added day 6 of aoc-2021
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 6 Dec 2021 13:43:13 +0000 (07:43 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 6 Dec 2021 13:43:13 +0000 (07:43 -0600)
tests/aoc-2021/day06 [new file with mode: 0644]
tests/aoc-2021/day06.onyx [new file with mode: 0644]
tests/aoc-2021/input/day06.txt [new file with mode: 0644]

diff --git a/tests/aoc-2021/day06 b/tests/aoc-2021/day06
new file mode 100644 (file)
index 0000000..d429bc7
--- /dev/null
@@ -0,0 +1 @@
+Part 2: 1767323539209
diff --git a/tests/aoc-2021/day06.onyx b/tests/aoc-2021/day06.onyx
new file mode 100644 (file)
index 0000000..8bdbb3c
--- /dev/null
@@ -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 (file)
index 0000000..89b026d
--- /dev/null
@@ -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