From: Brendan Hansen Date: Mon, 6 Dec 2021 13:43:13 +0000 (-0600) Subject: added day 6 of aoc-2021 X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=604e01bef5926c26ad6b0834b22e8cf336db461a;p=onyx.git added day 6 of aoc-2021 --- diff --git a/tests/aoc-2021/day06 b/tests/aoc-2021/day06 new file mode 100644 index 00000000..d429bc78 --- /dev/null +++ b/tests/aoc-2021/day06 @@ -0,0 +1 @@ +Part 2: 1767323539209 diff --git a/tests/aoc-2021/day06.onyx b/tests/aoc-2021/day06.onyx new file mode 100644 index 00000000..8bdbb3c5 --- /dev/null +++ b/tests/aoc-2021/day06.onyx @@ -0,0 +1,28 @@ +#load "core/std" + +use package core + +main :: (args) => { + for file: os.with_file("./tests/aoc-2021/input/day06.txt") { + reader := io.reader_make(file); + start_str := io.read_all(^reader); + + start_list := string.split(start_str, #char ","); + + fish: [9] i64; + for start_list { + value := cast(i32) conv.str_to_i64(it); + fish[value] += 1; + } + + for day: 256 { + new_fish := fish[0]; + for 8 do fish[it] = fish[it + 1]; + fish[6] += new_fish; + fish[8] = new_fish; + } + + total := array.sum(fish); + printf("Part 2: {}\n", total); + } +} \ No newline at end of file diff --git a/tests/aoc-2021/input/day06.txt b/tests/aoc-2021/input/day06.txt new file mode 100644 index 00000000..89b026d3 --- /dev/null +++ b/tests/aoc-2021/input/day06.txt @@ -0,0 +1 @@ +1,1,1,2,1,1,2,1,1,1,5,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,4,1,1,1,1,3,1,1,3,1,1,1,4,1,5,1,3,1,1,1,1,1,5,1,1,1,1,1,5,5,2,5,1,1,2,1,1,1,1,3,4,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,5,4,1,1,1,1,1,5,1,2,4,1,1,1,1,1,3,3,2,1,1,4,1,1,5,5,1,1,1,1,1,2,5,1,4,1,1,1,1,1,1,2,1,1,5,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,3,1,1,3,1,3,1,4,1,5,4,1,1,2,1,1,5,1,1,1,1,1,5,1,1,1,1,1,1,1,1,1,4,1,1,4,1,1,1,1,1,1,1,5,4,1,2,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,4,1,1,1,2,1,4,1,1,1,1,1,1,1,1,1,4,2,1,2,1,1,4,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,3,2,1,4,1,5,1,1,1,4,5,1,1,1,1,1,1,5,1,1,5,1,2,1,1,2,4,1,1,2,1,5,5,3 \ No newline at end of file