diff --git a/.gitignore b/.gitignore index b6e4761..6f0d2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,10 @@ dmypy.json # Pyre type checker .pyre/ + +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace diff --git a/advent.py b/advent.py index 7241ff7..fad2f75 100644 --- a/advent.py +++ b/advent.py @@ -6,6 +6,8 @@ def suite(): suite.addTest(days.Day1('test_day1a')) suite.addTest(days.Day1('test_day1b')) suite.addTest(days.Day2('test_day2a')) + suite.addTest(days.Day4('test_day4a')) + suite.addTest(days.Day4('test_day4b')) return suite if __name__ == "__main__": diff --git a/days/__init__.py b/days/__init__.py index 62b2105..9c8e6b1 100644 --- a/days/__init__.py +++ b/days/__init__.py @@ -1,2 +1,4 @@ from .day1 import Day1 -from .day2 import Day2 \ No newline at end of file +from .day2 import Day2 +from .day3 import Day3 +from .day4 import Day4 \ No newline at end of file diff --git a/days/day2.py b/days/day2.py index 4531fa6..9169b70 100644 --- a/days/day2.py +++ b/days/day2.py @@ -1,6 +1,9 @@ import unittest +import os class Day2(unittest.TestCase): + inputfile = os.path.join(os.path.dirname(__file__), "day2_input") + def test_day2a(self): self.assertTrue(1 == 1) diff --git a/days/day2_input b/days/day2_input new file mode 100644 index 0000000..7b5d936 --- /dev/null +++ b/days/day2_input @@ -0,0 +1 @@ +1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,10,19,2,6,19,23,1,23,5,27,1,27,13,31,2,6,31,35,1,5,35,39,1,39,10,43,2,6,43,47,1,47,5,51,1,51,9,55,2,55,6,59,1,59,10,63,2,63,9,67,1,67,5,71,1,71,5,75,2,75,6,79,1,5,79,83,1,10,83,87,2,13,87,91,1,10,91,95,2,13,95,99,1,99,9,103,1,5,103,107,1,107,10,111,1,111,5,115,1,115,6,119,1,119,10,123,1,123,10,127,2,127,13,131,1,13,131,135,1,135,10,139,2,139,6,143,1,143,9,147,2,147,6,151,1,5,151,155,1,9,155,159,2,159,6,163,1,163,2,167,1,10,167,0,99,2,14,0,0 \ No newline at end of file diff --git a/days/day3.py b/days/day3.py new file mode 100644 index 0000000..05ad0c1 --- /dev/null +++ b/days/day3.py @@ -0,0 +1,14 @@ +import unittest +import os + +class Day3(unittest.TestCase): + inputfile = os.path.join(os.path.dirname(__file__), "day3_input") + + def test_day3a(self): + with open(self.inputfile) as fp: + steps = fp.readline().split(',') + + pass + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/days/day3_input b/days/day3_input new file mode 100644 index 0000000..da43d67 --- /dev/null +++ b/days/day3_input @@ -0,0 +1,2 @@ +R999,U626,R854,D200,R696,D464,R54,D246,L359,U57,R994,D813,L889,U238,L165,U970,L773,D904,L693,U512,R126,D421,R732,D441,R453,D349,R874,D931,R103,D794,R934,U326,L433,D593,L984,U376,R947,U479,R533,U418,R117,D395,L553,D647,R931,D665,L176,U591,L346,D199,L855,D324,L474,U251,R492,D567,L97,D936,L683,U192,R198,U706,L339,U66,R726,D102,R274,U351,R653,D602,L695,U921,R890,D654,R981,U351,R15,U672,R856,D319,R102,D234,R248,U169,L863,U375,L412,U75,L511,U298,L303,U448,R445,U638,L351,D312,R768,D303,L999,D409,L746,U266,L16,U415,L951,D763,L976,U342,L505,U770,L228,D396,L992,U3,R243,D794,L496,U611,R587,U772,L306,D119,L470,D490,L336,U518,L734,D654,L150,U581,L874,U691,L243,U94,L9,D582,L402,U563,R468,U96,L311,D10,R232,U762,R630,D1,L674,U685,R240,D907,R394,U703,L64,U397,L810,D272,L996,D954,R797,U789,R790,D526,R103,D367,R143,D41,L539,D735,R51,D172,L33,U241,R814,D981,R748,D699,L716,U647,L381,D351,L381,D121,L52,U601,R515,U713,L404,U45,R362,U670,L235,U102,R373,U966,L362,U218,R280,U951,R371,U378,L10,U670,R958,D423,L740,U888,R235,U899,L387,U167,R392,D19,L330,D916,R766,D471,L708,D83,R749,D696,L50,D159,R828,U479,L980,D613,L182,D875,L307,U472,L317,U999,R435,D364,R737,U550,L233,U190,L501,U610,R433,U470,L801,U52,L393,D596,L378,U220,L967,D807,R357,D179,L731,D54,L804,D865,L994,D151,L181,U239,R794,D378,L487,U408,R817,U809,R678,D599,L564,U480,R525,D189,L641,D771,L514,U72,L248,D334,L859,D318,R590,D571,R453,U732,R911,U632,R992,D80,R490,D234,L710,U816,L585,U180,L399,D238,L103,U605,R993,D539,R330 +L996,U383,L962,U100,L836,D913,R621,U739,R976,D397,L262,D151,L12,U341,R970,U123,L713,U730,L52,D223,L190,D81,R484,D777,R374,U755,R640,D522,R603,D815,R647,U279,R810,U942,R314,D19,L938,U335,R890,U578,R273,U338,R186,D271,L230,U90,R512,U672,R666,D328,L970,U17,R368,D302,L678,D508,L481,U12,L783,D409,L315,D579,L517,D729,R961,D602,R253,D746,R418,D972,R195,D270,L46,D128,L124,U875,R632,D788,L576,U695,R159,U704,R599,D597,R28,D703,L18,D879,L417,U633,L56,U302,R289,U916,R820,D55,R213,U712,R250,D265,L935,D171,L680,U738,L361,D939,R547,D606,L255,U880,R968,U255,R902,D624,L251,U452,L412,D60,L996,D140,L971,U196,R796,D761,L54,U54,L98,D758,L521,U578,L861,U365,L901,D495,L234,D124,L121,D329,L38,U481,L491,D938,L840,D311,L993,D954,R654,U925,L528,D891,L994,D681,L879,D476,L933,U515,L292,U626,R348,D963,L145,U230,L114,D11,R651,D929,R318,D672,R125,D827,L590,U338,L755,D925,L577,D52,R131,D465,R657,D288,R22,D363,R162,D545,L904,D457,R987,D389,L566,D931,L773,D53,R162,U271,L475,U666,L594,U733,R279,D847,R359,U320,R450,D704,L698,D173,R35,D267,L165,D66,L301,U879,R862,U991,R613,D489,L326,D393,R915,U718,R667,U998,R554,U199,R300,U693,R753,U938,R444,U12,L844,D912,R297,D668,R366,U710,L821,U384,R609,D493,R233,U898,R407,U683,R122,U790,L1,U834,L76,U572,R220,U752,L728,D85,L306,D805,R282,U507,R414,D687,L577,U174,L211,U308,L15,U483,R741,D828,L588,D192,L409,D605,L931,U260,L239,D424,L846,U429,L632,U122,L266,D544,R248,U188,R465,U721,R621,U3,L884,U361,L322,U504,R999,U381,R327,U555,L467,D849,R748,U175,R356 \ No newline at end of file diff --git a/days/day4.py b/days/day4.py new file mode 100644 index 0000000..479b435 --- /dev/null +++ b/days/day4.py @@ -0,0 +1,66 @@ +import unittest +import os + +class Day4(unittest.TestCase): + def num_to_array(self, num): + arr = [] + while num != 0: + arr.append(num % 10) + num = num //10 + arr.reverse() + return arr + + def check_num(self, num): + numarr = self.num_to_array(num) + last = numarr[0] + adj = False + for p in range(1,6): + val = numarr[p] + if last > val: + return False + if last == val: + adj = True + last = val + return adj + + def check_num_grp(self, num): + numarr = self.num_to_array(num) + last = numarr[0] + adj = False + candidate = False + finished = False + for p in range(1,6): + val = numarr[p] + if last > val: + return False + if last == val: + if adj: + candidate = False + else: + candidate = True + adj = True + else: + adj = False + if candidate: + finished = True + last = val + return finished or candidate + + def test_day4a(self): + counter = 0 + for num in range(168630, 718099): + if self.check_num(num) == True: + counter += 1 + self.assertEqual(counter, 1686) + + def test_day4b(self): + self.assertTrue(self.check_num_grp(112233)) + self.assertFalse(self.check_num_grp(123444)) + counter = 0 + for num in range(168630,718099): + if self.check_num_grp(num) == True: + counter += 1 + self.assertEqual(counter, 1145) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file