From: Brendan Hansen Date: Sun, 6 Dec 2020 22:35:38 +0000 (-0600) Subject: updated to Onyx package changes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=26c3e48b3e4a131cc727ed9deb46d8316c536326;p=onyx-aoc-2020.git updated to Onyx package changes --- diff --git a/day1.onyx b/day1.onyx index e02d40c..8c7f56f 100644 --- a/day1.onyx +++ b/day1.onyx @@ -3,24 +3,28 @@ package main #include_file "core/std/wasi" use package core -use package core_file main :: proc (args: [] cstring) { - contents := file_get_contents("input/day1.txt"); + contents := file.get_contents("input/day1.txt"); contents_orig := contents; defer cfree(contents_orig.data); nums: [..] u32; - array_init(^nums, 128); - defer array_free(^nums); + array.init(^nums, 128); + defer array.free(^nums); while num := 1; num > 0 { // This sets num to be 0 if there is no number - string_read_u32(^contents, ^num); - if num != 0 do array_push(^nums, num); + str.read_u32(^contents, ^num); + if num != 0 do array.push(^nums, num); } for i: nums do for j: nums do for k: nums { - if j + i + k == 2020 do printf("Answer: %i\n", i * j * k); + if j + i + k == 2020 { + printf("Answer: %i\n", i * j * k); + + // Break out of all of the loops + break break break; + } } } diff --git a/day2.onyx b/day2.onyx index 75e24ca..daa3e80 100644 --- a/day2.onyx +++ b/day2.onyx @@ -3,10 +3,9 @@ package main #include_file "core/std/wasi" use package core -use package core_file main :: proc (args: [] cstring) { - contents := file_get_contents("input/day2.txt"); + contents := file.get_contents("input/day2.txt"); contents_orig := contents; defer cfree(contents_orig.data); @@ -17,14 +16,14 @@ main :: proc (args: [] cstring) { pw : string = ""; while true { - string_read_u32(^contents, ^lo); + str.read_u32(^contents, ^lo); if lo == 0 do break; - string_discard_chars(^contents); - string_read_u32(^contents, ^hi); - string_discard_chars(^contents); - string_read_char(^contents, ^ch); - string_discard_chars(^contents, 2); - string_read_line(^contents, ^pw); + str.discard_chars(^contents); + str.read_u32(^contents, ^hi); + str.discard_chars(^contents); + str.read_char(^contents, ^ch); + str.discard_chars(^contents, 2); + str.read_line(^contents, ^pw); // Part 1 // count := 0; diff --git a/day3.onyx b/day3.onyx index db07849..68418c8 100644 --- a/day3.onyx +++ b/day3.onyx @@ -1,7 +1,6 @@ #include_file "core/std/wasi" use package core -use package core_file Point :: struct { x : i32; @@ -20,25 +19,25 @@ line_interp_at :: proc (use li: LineInterp, t: i32) -> Point { } main :: proc (args: [] cstring) { - contents := file_get_contents("input/day3.txt"); + contents := file.get_contents("input/day3.txt"); contents_orig := contents; defer cfree(contents_orig.data); forest: [..] u8; - array_init(^forest, 1024); - defer array_free(^forest); + array.init(^forest, 1024); + defer array.free(^forest); width := 0; height := 0; while true { line: string = ""; - string_read_line(^contents, ^line); + str.read_line(^contents, ^line); if line.count == 0 do break; width = line.count; height = height + 1; - for ch: line do array_push(^forest, ch); + for ch: line do array.push(^forest, ch); } lis : [5] LineInterp; diff --git a/day4.onyx b/day4.onyx index 415f321..ba958eb 100644 --- a/day4.onyx +++ b/day4.onyx @@ -1,7 +1,6 @@ #include_file "core/std/wasi" use package core -use package core_file // Returns the number of fields process_passport :: proc (contents: ^string) -> u32 { @@ -9,18 +8,17 @@ process_passport :: proc (contents: ^string) -> u32 { while true { line: string; - string_read_line(contents, ^line); + str.read_line(contents, ^line); if line.count == 0 do break; - fields := string_split(line, #char " "); + fields := str.split(line, #char " "); defer cfree(fields.data); for field: fields { - data := string_split(field, #char ":"); + data := str.split(field, #char ":"); defer cfree(data.data); - printf("Field: %s\n", data[0]); - if !string_equal(data[0], "cid") { + if !str.equal(data[0], "cid") { field_count += 1; } } @@ -32,7 +30,7 @@ process_passport :: proc (contents: ^string) -> u32 { // This does not include part 2 because it is gross and // not worth the effort to implement it. main :: proc (args: [] cstring) { - contents := file_get_contents("input/day4.txt"); + contents := file.get_contents("input/day4.txt"); contents_data := contents.data; defer cfree(contents_data); diff --git a/day5.onyx b/day5.onyx index 8d962ca..21a913b 100644 --- a/day5.onyx +++ b/day5.onyx @@ -1,22 +1,21 @@ #include_file "core/std/wasi" use package core -use package core_file main :: proc (args: [] cstring) { - contents := file_get_contents("input/day5.txt"); + contents := file.get_contents("input/day5.txt"); contents_data := contents.data; defer cfree(contents_data); vals: [..] u32; - array_init(^vals); - defer array_free(^vals); + array.init(^vals); + defer array.free(^vals); max_val := 0; while true { line: string; - string_read_line(^contents, ^line); + str.read_line(^contents, ^line); if line.count == 0 do break; val := 0; @@ -25,12 +24,12 @@ main :: proc (args: [] cstring) { if ch == #char "B" || ch == #char "R" do val += 1; } - max_val = max_poly(max_val, val); - array_push(^vals, val); + max_val = math.max(max_val, val); + array.push(^vals, val); } missing := 0; - array_sort(^vals, cmp_asc); + array.sort(^vals, cmp_asc); for i: 0 .. vals.count - 1 { if vals[i + 1] - vals[i] != 1 do missing = vals[i] + 1; } diff --git a/day6.onyx b/day6.onyx index 3d374bf..cf50b1f 100644 --- a/day6.onyx +++ b/day6.onyx @@ -1,7 +1,6 @@ #include_file "core/std/wasi" use package core -use package core_file part_1 :: proc (contents: ^string) -> u32 { chars : [26] u8; @@ -9,7 +8,7 @@ part_1 :: proc (contents: ^string) -> u32 { while true { line: string; - string_read_line(contents, ^line); + str.read_line(contents, ^line); if line.count == 0 do break; for ch: line do chars[~~ch - cast(u32) #char "a"] = ~~1; @@ -28,7 +27,7 @@ part_2 :: proc (contents: ^string) -> u32 { person_count := 0; while true { line: string; - string_read_line(contents, ^line); + str.read_line(contents, ^line); if line.count == 0 do break; person_count += 1; @@ -42,7 +41,7 @@ part_2 :: proc (contents: ^string) -> u32 { } main :: proc (args: [] cstring) { - contents := file_get_contents("input/day6.txt"); + contents := file.get_contents("input/day6.txt"); contents_data := contents.data; defer cfree(contents_data); @@ -50,7 +49,7 @@ main :: proc (args: [] cstring) { while true { if contents.count == 0 do break; - unique := part_2(^contents); + unique := part_1(^contents); unique_sum += unique; } diff --git a/out.wasm b/out.wasm index 0532d5d..8e10301 100644 Binary files a/out.wasm and b/out.wasm differ