summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inputs/06.txt1
-rw-r--r--inputs/07.txt1
-rw-r--r--src/06.lisp37
-rw-r--r--test/06.lisp23
-rw-r--r--top.lisp3
5 files changed, 65 insertions, 0 deletions
diff --git a/inputs/06.txt b/inputs/06.txt
new file mode 100644
index 0000000..777f8fb
--- /dev/null
+++ b/inputs/06.txt
@@ -0,0 +1 @@
+1,1,5,2,1,1,5,5,3,1,1,1,1,1,1,3,4,5,2,1,2,1,1,1,1,1,1,1,1,3,1,1,5,4,5,1,5,3,1,3,2,1,1,1,1,2,4,1,5,1,1,1,4,4,1,1,1,1,1,1,3,4,5,1,1,2,1,1,5,1,1,4,1,4,4,2,4,4,2,2,1,2,3,1,1,2,5,3,1,1,1,4,1,2,2,1,4,1,1,2,5,1,3,2,5,2,5,1,1,1,5,3,1,3,1,5,3,3,4,1,1,4,4,1,3,3,2,5,5,1,1,1,1,3,1,5,2,1,3,5,1,4,3,1,3,1,1,3,1,1,1,1,1,1,5,1,1,5,5,2,1,5,1,4,1,1,5,1,1,1,5,5,5,1,4,5,1,3,1,2,5,1,1,1,5,1,1,4,1,1,2,3,1,3,4,1,2,1,4,3,1,2,4,1,5,1,1,1,1,1,3,4,1,1,5,1,1,3,1,1,2,1,3,1,2,1,1,3,3,4,5,3,5,1,1,1,1,1,1,1,1,1,5,4,1,5,1,3,1,1,2,5,1,1,4,1,1,4,4,3,1,2,1,2,4,4,4,1,2,1,3,2,4,4,1,1,1,1,4,1,1,1,1,1,4,1,5,4,1,5,4,1,1,2,5,5,1,1,1,5
diff --git a/inputs/07.txt b/inputs/07.txt
new file mode 100644
index 0000000..152bc07
--- /dev/null
+++ b/inputs/07.txt
@@ -0,0 +1 @@
+1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,20,1091,861,228,628,186,980,996,710,541,354,1611,69,1331,91,1220,447,523,38,1286,244,643,1069,566,70,155,1710,1266,120,302,72,232,387,1086,278,1122,605,1559,98,111,1816,795,543,1217,304,356,129,839,704,49,523,370,74,13,232,179,101,664,892,266,622,197,404,147,882,435,504,48,766,684,1362,136,830,1393,1259,925,68,879,251,43,1339,61,98,403,51,1008,197,659,195,1823,233,121,731,82,141,580,18,427,774,13,685,496,752,63,132,39,237,18,167,51,299,22,19,1442,305,1283,253,159,731,302,76,115,185,136,447,821,307,207,30,1427,251,589,0,1096,1240,261,442,757,5,172,847,858,382,425,79,402,166,1058,186,35,21,324,183,1293,95,410,321,12,155,88,409,40,428,1180,199,1444,487,148,57,1187,15,100,983,77,0,1667,359,513,659,339,142,968,994,787,0,443,183,133,538,4,332,1459,204,1156,710,1654,20,36,407,890,1265,1090,743,36,78,1033,781,608,476,103,1401,24,4,875,414,799,305,1047,842,72,497,362,270,73,12,9,0,21,11,51,1357,455,505,483,552,199,1108,214,238,686,1496,116,154,1403,35,272,738,1024,50,50,934,564,19,395,324,447,794,1326,14,407,1694,452,439,455,442,86,1515,588,809,224,112,156,21,1405,610,187,23,370,112,397,995,777,75,1281,32,60,284,388,916,555,200,675,20,320,32,398,104,113,447,113,351,396,322,36,1674,1708,232,1004,514,95,859,382,116,277,239,343,3,433,11,55,699,513,1465,319,44,306,224,615,482,695,421,300,321,283,579,323,102,275,17,723,632,713,277,801,222,130,189,1549,49,784,690,136,444,1315,259,1334,472,711,1109,276,70,315,838,35,328,766,1100,460,4,178,630,571,5,106,429,368,547,1210,840,162,166,10,403,880,287,44,1001,316,402,1054,174,7,1194,105,58,268,667,86,588,166,547,238,1586,77,112,244,107,63,873,1152,16,407,198,26,587,20,1449,775,653,1369,732,262,566,222,10,102,22,573,233,297,1238,789,291,93,206,1274,177,58,841,672,37,16,262,201,241,938,133,774,978,631,511,0,263,498,799,51,330,11,206,325,173,676,15,457,364,46,373,34,1475,530,672,295,55,4,297,274,1519,15,688,555,96,160,185,583,646,41,378,1572,67,219,572,143,16,286,65,788,886,243,883,1012,109,90,742,464,1099,388,1855,731,62,6,415,66,232,542,98,1123,11,414,1262,4,440,8,691,130,164,773,992,423,115,1807,1618,153,168,1213,719,291,316,311,110,24,608,0,127,131,142,196,232,75,248,412,275,1295,239,86,967,133,422,415,894,280,807,345,446,250,979,231,713,201,1009,208,444,43,1400,434,8,221,141,235,909,1018,340,0,178,1144,353,662,491,294,6,440,446,824,1392,379,269,1427,911,671,231,424,102,718,86,54,130,206,514,137,1075,1573,248,472,602,249,974,8,372,59,2,940,165,1132,327,1424,63,6,97,140,1302,439,1237,59,324,733,397,477,426,278,274,1636,745,41,269,257,51,173,503,88,1223,754,228,584,72,632,645,323,156,7,337,192,375,583,613,370,172,528,1282,360,208,17,208,802,22,67,290,242,458,809,6,1388,49,14,327,911,121,475,101,617,284,91,1,35,421,293,1419,602,143,142,168,657,472,219,345,411,115,387,5,494,383,348,85,1070,154,42,63,586,953,563,12,1263,788,762,222,351,730,42,643,877,522,775,698,564,604,155,191,430,5,386,787,120,470,433,564,955,411,1090,210,1096,933,109,70,279,287,736,390,1075,30,194,30,1318,473,727,100,584,1227,89,432,120,393,1080,185,500,847,117,319,54,160,32,114,700,12,36,681,53,1063,113,82,1625,1426,53,658,80,253,36,16,810,560,602,177,275,147,335,1237,1447,176,55,366,721,471,501,217,67,899,914,168,981,1177,898,1,9,704,602,787,1280,305,57,786,1696,211,63,55,351,14,151,932,757,810,1748,169,1018,125,849,234,102,823,300,127,6,849,1163,229,726,397,656,135,466,137,1247,811,807,366,209,1703,24,1219,45,161,353,274,572,397,899,646,32,137,439,1048,2,391,8,214,736,518,409,414,567,1262,155,102,178,1247,526,10,94,759,781,18,14,1518,68,295,905,478,1581,89,429,937,438,915,1110,659,615,1128,8,125,89,289,1084,905,254,1227,184,883,983,110,1,24,748,1408,828,1187,63,264,481,214
diff --git a/src/06.lisp b/src/06.lisp
new file mode 100644
index 0000000..8a7d2ec
--- /dev/null
+++ b/src/06.lisp
@@ -0,0 +1,37 @@
+(use-package 'cl-ppcre)
+(use-package 'trivia)
+
+(defun 06/parse-input-direct (input)
+ (mapcar #'parse-integer (split "," (car input))))
+
+(defun 06/parse-input (input-file)
+ (06/parse-input-direct (get-file-lines input-file)))
+
+(defun 06/one-iter (parsed-input)
+ (let* ((new 0)
+ (new-map (mapcar (lambda (x) (if (> x 0) (- x 1) (progn (incf new) 6))) parsed-input)))
+ (append new-map (make-list new :initial-element 8))))
+
+(defun 06/part-a (parsed-input)
+ (loop for i from 1 upto 80
+ do (setf parsed-input (06/one-iter parsed-input)))
+ (list-length parsed-input))
+
+(defun 06/another-iter (arr new)
+ (loop for i from 8 downto 0
+ for n = (aref arr i)
+ do (if (zerop i)
+ (progn
+ (setf (aref new 8) n)
+ (incf (aref new 6) n))
+ (setf (aref new (1- i)) n))))
+
+(defun 06/part-b (parsed-input)
+ (let ((initial (make-array 9 :initial-element 0))
+ (new (make-array 9)))
+ (dolist (i parsed-input) (incf (aref initial i)))
+ (loop for x below 256
+ do (progn (06/another-iter initial new)
+ (rotatef initial new)))
+ (apply #'+ (loop for x below 9
+ collect (aref initial x)))))
diff --git a/test/06.lisp b/test/06.lisp
new file mode 100644
index 0000000..2b00ab8
--- /dev/null
+++ b/test/06.lisp
@@ -0,0 +1,23 @@
+(use-package :clunit)
+
+(defsuite 06/aoc (aoc))
+
+(defvar 06/default-input '("3,4,3,1,2"))
+
+(deftest 06/test-ex-a (06/aoc)
+ (let ((result (06/part-a (06/parse-input-direct 06/default-input))))
+ (assert-equalp 5934 result)))
+
+(deftest 06/test-ex-b (06/aoc)
+ (let ((result (06/part-b (06/parse-input-direct 06/default-input))))
+ (assert-equalp 26984457539 result)))
+
+(deftest 06/test-a (06/aoc)
+ (let ((result (06/part-a (06/parse-input "inputs/06.txt"))))
+ (assert-equalp 372300 result)))
+
+(deftest 06/test-b (06/aoc)
+ (let ((result (06/part-b (06/parse-input "inputs/06.txt"))))
+ (assert-equalp 1675781200288 result)))
+
+(defun 06/run-tests () (run-suite '06/aoc))
diff --git a/top.lisp b/top.lisp
index 73b1825..3851e46 100644
--- a/top.lisp
+++ b/top.lisp
@@ -30,4 +30,7 @@
(load "src/05.lisp")
(load "test/05.lisp")
+(load "src/06.lisp")
+(load "test/06.lisp")
+
(defun run-all () (clunit:run-suite 'aoc))