diff --git a/aoc.mk b/aoc.mk
index a01fe20..3b50207 100644
--- a/aoc.mk
+++ b/aoc.mk
@@ -16,19 +16,7 @@ DREAMCAST_OBJ = \
$(LIB)/font/dejavusansmono/dejavusansmono.data.o \
$(LIB)/sh7091/serial.o
-DAY1_OBJ = \
- day1/sample1.txt.o \
- day1/input.txt.o \
- day1/solution.o
-
-DAY2_OBJ = \
- day2/sample1.txt.o \
- day2/input.txt.o \
- day2/solution.o
-
-DAY_OBJ = \
- $(DAY1_OBJ) \
- $(DAY2_OBJ)
+include solutions.mk
aoc.elf: LDSCRIPT = $(LIB)/main.lds
aoc.elf: $(START_OBJ) $(OBJ) $(DREAMCAST_OBJ) $(DAY_OBJ)
diff --git a/day1/sample2.txt b/day1/sample2.txt
deleted file mode 120000
index 0705e8e..0000000
--- a/day1/sample2.txt
+++ /dev/null
@@ -1 +0,0 @@
-sample1.txt
\ No newline at end of file
diff --git a/day3/input.txt b/day3/input.txt
new file mode 100644
index 0000000..ef794f2
--- /dev/null
+++ b/day3/input.txt
@@ -0,0 +1,6 @@
+@~don't()mul(683,461) >,~select()what()};what()*,why()mul(456,228)%/'where()~{mul(508,422)mul(78,184)&why()/(mul(373,546)why()*why():-~{@mul(615,760)}?/*>$mul(422,670)},?#''how()@#mul(597,259)??mul(281,991)when()why()]/;}:who()why()/mul(864,121)how()#{[from()&mul(336,536) what()/what()#:>mul(908,667)[%^>&]select()*(mul(716,31)what()[+~what())]where():mul(131,416)what()from()]^when()$mul(808,465)from(747,493)*@;mul(728,405)@mul(528,186)where(830,813) mul(138,404)&&$,,mul(220,842)(from()*~from()how()where()mul(44,647)~where()}%$+mul(523,78)}mul(506,925)where()) ?mul(650,260)what()))when()mul(992,831)*]?-(mul(382,514)@<>,{*^/why()[don't()#>how(558,115)mul(303,593)${~from()%*$%do()-+[$mul(406,365)how()mul(561,819)how():select()[:when()mul(283,930)where()$>why():#mul(154,725)from(496,796))@[how()from()- mul(942,491)-don't()~who()^)#select()where()mul(880,650)>(when(),)who()]where()mul(735,764)<-select()where()~#mul(685,917)from()!how()&who(),~why()[/mul(838,662) }what()from()from()[mul(217,645)who(){who()mul(712,250)*}~who(133,126)where()}what()-where()mul(879,905)mul(95,8)~{?%:/mul(885,299)mul(509,215)~mul(97,351)mul(11,228)mul(976,139)where()mul(532,340)mul(535,236)@)+mul(91,686)^+)(/}where()why()()'mul(544,423)@@ mul(543,903)why()mul(610,22)where()when()^)mul(529,383) ;,/'when(179,924)mul(31,223)when());*from()mul(810,928) ^'{'?~mul(840,456)?where()}~:who()'do()@where(){(@$select(471,179)mul(490,95)where()?>)^$mul(192,331)?when()where()!}who()*%[%mul(778,800)+}when()who()how()mul(836,264)from()+)@where()mul(261,535)&)@why()-#/(mul(187,2)(?what()mul(467,281)when()where()#, [+what()select()(mul(232,619)don't()^mul(406,760)mul(400,865)%%who()where()}${?[!don't()#%@^/)when()]@%mul(268,776){-:how()}:'~+mul(817,838)}when()when()#/where()?how()+mul(712,30)select()(%* !mul(11,366)
+ select(463,746)]mul(475,757)where()$ }~)}'mul(201,678)what()when()]',who()how()mul(228,56)^'what()from()@$,+{[mul(725,736)mul(96,310)*:<>how()from()&{>mul(533,345)>where()>%when()mul(816,202)#what()]+/}%when()<]don't():*%;mul(368,570)~from(251,737):^ ;select(589,302);~mul(780/what()/{&when()mul(780,721))';+>mul(191,651)#}why()!when())mul(321,579)%~ what();/!who()mul(707,979)!select()when():+<& do();>what()}what(318,824)mul(755,111)%/(?*}#how(431,277)mul(85,134)mul(280~<$:who()when()where(174,374)mul(113,173)>don't()^(who()(mul(765,356)!/$? select()-%+?mul(991,23)?why(270,631)when()!:)/&mul(782,296)(~['+*?don't()@)+?mul(553,968)how()what()%where()]where()&&mul(621,835)when()/:what()@,@where()>mul(317,451)~why()+where(),))mul(364,198)+what()}*[mul(883,802)]/'where()mul(387,43 where()~?;)@@what()how()mul(322,326)who()+mul(326,133)/(]%,? mul(907,688))-(select()#mul(666,327),!who()mul(895,291);&)^)[mul(658,676)@who()/+>&mul(44,325):^>why()who()$*select()mul(641,527)mul(524,670)~mul(25,367)mul(499,446) ,why()who()%mul(100,283)#when()who() how() @&mul(351,89)why(36,81)'!,select()>who()!who()/mul(52,820)/^mul(630,788)from()%<(^:}mul(420,483)mul(473,512);*}-mul(761,735)'mul(419,165)&mul(523,446))mul(834,76)!#mul(562,151):-'who(285,490)[mul(984,224)'!;mul(469,881)>**-'mul(385,297)@mul(994,97)+*%mul(281,326)@//$mul(664,734)how()select()[:@?#,do() !)%what(202,601)+how()from()mul(391,934)!%?)how()mul(825,779)how()([how()do()who()+who()#%when();mul(642,60)from()&mul(425,517):what()mul(675,402))?@/how(668,137)from()-mul(400,170)mul(808,291){how()mul(142,403)
+mul(868,598)@from()%>&?;@mul(20,94)&?why())?mul(758,315)~&;where()'what()mul(152,875)mul(308,470)][select()$&-:>?mul(256,361)<')>&from();{why()mul(620,603):{~where();' -mul(693,340)$mul(646,441)-what()do()%!when()->mul(617,502),#,]mul(212,569)$when()])mul(635,595)~}:@*mul(292,790)}mul(933,20)@^{(mul(22,237)&'mul(103,788){}{why()who()%what()don't()(,#'(;mul]when()mul(268,616)how()mul(675,612)>**@$mul(111,445)$:!how()mul(56,5) mul(419,542)why()&@mul(214,101)]how()from()why()why();^where()mul(841,681))$',#%}&mul(777,293){mul(778,822)>*{{)'from(644,961)why()mul(559,996)*how()<(mul(41*!:select()%#''+what()mul(193,482)$;%([]-*mul(271,561)mul(632,842:^+/%)mul(605,351)<$}mul(80,304),!(]$/when()-when())mul(942,823)~^,,}#'mulhow()mul(558,938))+how(),mul(345,610)]%<(mul(550,971):,#)mul(468,45);$:how() *(>mul(354,420)/:+how()#::mul(71,315)&mul(378,96); +*what()[when()]):mul(486,242)+(@from()'-^(}mul(727how()? }^/^mul(470,146)from()'why()how()<~,+-mul(522,547)#**?+:what()who()from()>mul(793,81)$)'~what();do()]how()select(432,392)+;-[mul(997,671) where()?mul(129,744)select()why()<+mul(567,796)from(817,482)@(mul(462,463)/)!why());mul(893,320)@;&)why()?why()when()who();mul(731,381)when()/:how()%mul(999,422)where()from()]select(739,491)#*;mul(435,663):mul(872,159&/&where(70,34)};where()from()mul(518,656)>[*who()<{when():don't()(mul(616,333){@/why()?what()*>mul(823,123)how()mul(113,251)from()~('mul(894,176*when()#/*]>mul(542,271)when(159,532)]:~from()mul(629,280)from(676,859)[&&!]mul(980,396)where()}*' ^!how(298,757)mul(593,718#)~do()>!{what()';what()-mul(417,931)mul(379,961)#>!}-- mul(770,269)-]~&'*mul(179,685)how()why(){;^mul(515,206)+^$#]- ;@mul(854,862)-%,mul(217,603){why()^select():where()*mul(458,549)where()!% mul(336,105)from()!};$why()%[~why()mul(701,97)mul(566,796)'/}!mul(987,970)why()/ where()?*why()mul(938,415)(#^>(mul(358,974why()>mul(127,685)]what():mul(23,486)!+[}!mul(703,30)when()'%,#mul(182,500):mul(13,248)^-[,]what())'who()mul(150,306)>/mul(353,581);%:where():mul(296,383);%why()select())][ /mul(185,486)~#mul(383,477)mul(484,779)/select()what()#%+from()]'why()mul(410,683,mul(892,307)<-~,~mul(463,990)?#>-+mul(500,467)~~mul(41,729)-^don't() mul(478,617);,{$mul(722,601) when()who()>>&mul(107,557)}why()-why(){select()mul(963,953)+mul(56,679)/#!/usr/bin/perl(+where()?~%when(),mul(415,271)mul(681,988)~~/where(),&:,mul(130who()'mul(551,234)'what():'!@why()+!mul(710,188)^select()mul(59,292)&;^why(359,678)?>??mul(244,420)&mul(348,572)when(746,716)/]^why()what()mul(476,900)];what()mul(203,688)why()*#who()when()+(why()where()from()mul(362,853){#'!%%mul(606,167)select()mul(928,445)!+'select()mul(41,136)mul(245,634^who(419,312)#/'<)'%mul(804,572)'%+' who()+@mul(913,22?;+-from(278,530)#how()mul(141,596)@>select(540,148)!]{mul%!-@#&}mul(889,958)mul(485,341)~%+how()?select()#mul(777,805)'how()!mul(266,524)<+)when()${mul(880,580)select()&who()~#)mul(486,513)why()when()%;how()#mul(937,105)*mul(186,474)mul(420,471) what()[>,%)]mul(862,899)(&}]{+$mul(871,579)$why()#}#mul(125,369)when(271,818)<''}-select(){ don't();#who(){-#mul(268,334)^:%do()mul(75,572){what()mul(283,605)mul(919,23){;)what()~who(445,781)from()&>mul(294,330):*from()who()#from(868,274)-[mul(47,694)mul]$when()$+mul(747,604))!~;mul(588,239)what()(^(>}mul(376,745)why()]where()why()/who()mul(265,949)mul(889,524),,{what()+{/*mul(946,665);?*?;~,mul(738,941)&]why()]~^~where()*mul(865,982):',mul(146,728)~mul(399,437)(do()mul[why()from()who(),:mul(277,862)from():'mul(367,848)where();why(),(select()-when()who(){mul(833,730),+select()mul(196,278) ?}}[!^^mul(825,271):select()&@~^+why()%mul(858,60)};how()}^mul(285,548)mul(989,956)$mul(849,412)}>/:>/@mul(803,749)select()>,#mul(270,484),mul(49,218)%{;/>select()'+mul(645,947)select()*?do()' >@'~;mul(222,599)#@from()where(),what()mul(989,460)?{)<$mul(444,901)<@'mul(402,13)/!*mul(657,625){#when()what()mul(762,228)#mul(704,630)@&{??!//?/mul(104,95) mul(337,388)#^ )who())where()mul(623,138)$mul(403,157);%mul(101,259)>what()don't()>mul(998,640)mul(448,211)?*!select()who(),? )mul(271,985)$}--~&mul(234,431)from()+where(891,795){$+:~)mul(11,379)
+why(872,627)when() @who()&why()mul(585,812)-+#%(%)mul(774,83)where()-(/~mul(249,409)&>don't()('^mul(504,414)!%>%[#{*<%mul(188,200)mul(167,558)>?>select():@mul(56,920)-how()}[{?^*,mul(280,213how(298,460)/]<*mul(827,209)$^{where();mul(55,859)?mul(820,629)^],*@+!]&mul(51,796)*@[:mul(391,202)(*&($?%;{mul(715,516)where()when()when(878,620)>^%><()mul(200,147)##}^$ ]'select()+mul(830,239)((~select()'mul(107,50),:<{when()(select(441,699)when()mul(190,106)]what()+where()@{where()#who()mul(280,967)who();from()( do()+'] /;where()&select()/mul(196,704))<&mul(268,129)#)!'?+**mul(2,819)---{what()mul(340,265)]-;@}-{>mul(957,38)>@~>&@<who()(how()'~mul(576,420)!]:(who()mul(696,352)what()*,{]how()<#mul(722,996*^>[mul(707,555)mul(690,368)+*#{why()/why()?;mul(191,355)-}mul(634select()from(662,490)^select(130,551)>$when()mul(785,141)how()from()@//^do()from()when()%mul(280,35)(select()who()<:who()#<-mul(656,404)&+&mul(876,651),<'>mul(932,833)where()(,when()when()!/mul(756,656)&where();-^why()]mul(247,388)where()}{why()}?do()$}why()select()mul(783,462) &],(who()?:;mul(981,136)<{];>mul(848,166),]-why()do()from(102,362):-~how() why()how()who()mul(163,237)%;]mul(762,71)~,:-;mul(996,713)#!-~do()/ ^^mul(190,532)&'why()@~mul(580,20)mul(512,144),how(712,274)# ([mul(74,589)>-what()what()~mul(144,880){mul(566,592), {@*why()mul(523,558)@)!mul(826,790)!select()why()from()(mul(110,522)!select()('mul(704,195>+from()?%>mul(274,353)))}who()[when(660,595)~how()]mul(552,121)from()select()why()mul(240,146)why()> mul(679,332)why()(%(from()^:why(492,169)}~mul(799,127)%~}mul(755,381)[;%what()how())*when()what(323,755)?mul(454,719[-%/;why()how(316,859)^!when()mul(151,252)where()&/ &mul(802,262)**why()mul(860,835)<&]from()where(617,545);;mul(547,933)'mul(809,108)! ~%]})where()mul}'what():mul(270,513)who() (]@,~][mul(900,601)~:?!'mul(772,689)*(%'**~^from(){mul(664,414)&&-who();who()from()who()$,mul(658!*+mul(68,562)[*mul(227,260)^:#(;mul(171,823);>select()where()'+$$mul(520,111)>+*select()why()mul(713,530)}-<$;(;mul(94,879)?who()why()@/^/@mul(58,649)?why();(what(994,808)-:,mul(439,811)' mul(885,101)[what()mul(713,539)?/~where()!#/:#mul(119,763)where()select()[%;:from():+mul(78,791)select()}'mul(253,65)^ %mul(175,244)]#+why()where()@;mul(610,884)*;what()mul(70,112)( mul(375,253)mul(321,80);+mul(498,751)>[~?mul(848,622?$mul(43,693)how(){(^mul(91[)why()^:^from()]*mul(773,980);how()@who()(mul(817,36)
+!']*;&mul(832,66)[when()'^mul(839,760){ what()mul(374,389)-^*when()what()mul(743,565)+%where(24,265)--@mul(37,414)mul(200,132)&<&@when()who()]~what()mul(816,483))from()%{:mul(237,407)]what()select()where()mul(937,582)why())!)mul(196,261)>*<%;who()<:!mul(42,391)) where(711,384)mul(286from()'[%mul(112,582)from();:mul(755,219)!**where()<#?)mul(893,667)who()> #mul[:where()select()>(/from()>:-mul(587,565)mul(979,685)mul(686,145)who()?;]:{$mul(815,666'?&mul(981,191)mul(710,249)~@what():*&+from()&mul(420,352)&(-mul(308,752)@'mul(408,712)why()<]mul(610,709)~{mul(495,81)~),select()^mul(257,534)where()}mul(154,658)^}mul(313,894)(why()mul(950,201)>why()%what(276,768)%-+??(mul(578,595)mul(860,931)&{>:)^mul(566,551)>what()+how()[*from()[)mul(879,564)from()~:^'}[select()#who()do()%what();who()#mul(614,173))>'mul(274,742)why()+!&*/mul(962,316)?do()<@mul(599,386))mul(355,316)+-;&where()-;don't()?#[]#where()[::mul(532,56)>~@mul(264,327)~?%]&@! when()+mul(739,388)<$*)what()mul(732,804)from()who()'who()#,~mul(642,712)?}?mul(362,448)&,}+}: -mul(980,701)']when()-;]^^mul(761,19)+,mul(69,535)$>@do()%/:mul(244,738) mul(836,850):;when()from()'?do()]who(931,224)+}*@when(690,226)how()!mul(651,163)?how()-(&$-@mul(159,702)@mul(165,723)}(mul(401,331)'what() what(75,87)){,mul(665,944)/<:@'why(290,555)&%';mul(906,18)select()mul(394,692)*where()'mul(127,395){^what()~-^mul(892,931)%@who()mul(770,492)when()mul(615,744)<;+]+how()}&(mul(849,515)who(651,542)/@$mul(551,298)mul(752,737)>?what();^{,mul(518,320)~select()(+-,>;)~mul(37,708)why()'mul(213,584) how()mul(552,286)mul(41,894) <(mul(410,393)(why(),^<(#{~+don't()what()/when()what(35,148)$how() $'mul(352,31)'!?[mul(922,598)# mul(274,543)/{/'!-()mul(899,396))&-,#select()how()select(963,44)mul(719,545)(')mul(909,800)-[-mul(718,282);< )where();*#+mul(509,20)>?@^select() $do()]:what()>}!!^({mul(492,556);<{$how()mul(98,348){]'don't(){{',mul(564,736)>{how()'mul(154,829)'~from()]do(){mul(452,695)+where()who(),-mul(906,99){} >why()why()mul(12,879)~when(646,247) ;mul(878,782)+ '{+&>who() mul(726,701)%<##!mul(457,189)$>')+~!%do()where() @when()mul(159,260)<%[~when() why()mul(663,679)}/
diff --git a/day3/input.txt.h b/day3/input.txt.h
new file mode 100644
index 0000000..7af9dea
--- /dev/null
+++ b/day3/input.txt.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t _binary_day3_input_txt_start __asm("_binary_day3_input_txt_start");
+extern uint32_t _binary_day3_input_txt_end __asm("_binary_day3_input_txt_end");
+extern uint32_t _binary_day3_input_txt_size __asm("_binary_day3_input_txt_size");
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/day3/sample1.txt b/day3/sample1.txt
new file mode 100644
index 0000000..f274bda
--- /dev/null
+++ b/day3/sample1.txt
@@ -0,0 +1 @@
+xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
diff --git a/day3/sample1.txt.h b/day3/sample1.txt.h
new file mode 100644
index 0000000..65d1abf
--- /dev/null
+++ b/day3/sample1.txt.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t _binary_day3_sample1_txt_start __asm("_binary_day3_sample1_txt_start");
+extern uint32_t _binary_day3_sample1_txt_end __asm("_binary_day3_sample1_txt_end");
+extern uint32_t _binary_day3_sample1_txt_size __asm("_binary_day3_sample1_txt_size");
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/day3/sample2.txt b/day3/sample2.txt
new file mode 100644
index 0000000..30032cb
--- /dev/null
+++ b/day3/sample2.txt
@@ -0,0 +1 @@
+xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
diff --git a/day3/sample2.txt.h b/day3/sample2.txt.h
new file mode 100644
index 0000000..5931e62
--- /dev/null
+++ b/day3/sample2.txt.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t _binary_day3_sample2_txt_start __asm("_binary_day3_sample2_txt_start");
+extern uint32_t _binary_day3_sample2_txt_end __asm("_binary_day3_sample2_txt_end");
+extern uint32_t _binary_day3_sample2_txt_size __asm("_binary_day3_sample2_txt_size");
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/day3/solution.c b/day3/solution.c
new file mode 100644
index 0000000..43ae869
--- /dev/null
+++ b/day3/solution.c
@@ -0,0 +1,130 @@
+#include
+#include
+
+#include "parse.h"
+#include "printf.h"
+
+struct mul
+{
+ int x;
+ int y;
+};
+
+enum instruction_type {
+ INSTRUCTION_MUL,
+ INSTRUCTION_DO,
+ INSTRUCTION_DONT,
+};
+
+struct instruction {
+ enum instruction_type type;
+ struct mul mul;
+};
+
+const char * parse_instruction(const char * input, const char * end, struct instruction * ins)
+{
+ while (input < end) {
+ const char * mdo = parse_match(input, "do()");
+ if (mdo != NULL) {
+ ins->type = INSTRUCTION_DO;
+ return mdo;
+ }
+ const char * mdont = parse_match(input, "don't()");
+ if (mdont != NULL) {
+ ins->type = INSTRUCTION_DONT;
+ return mdont;
+ }
+
+ const char * m = parse_match(input, "mul(");
+ if (m == NULL) {
+ input++;
+ continue;
+ }
+ input = m;
+
+ const char * x = parse_base10(input, &ins->mul.x);
+ if (x == input) continue;
+ input = x;
+ if (ins->mul.x < 0 || ins->mul.x > 999) continue;
+
+ const char * c = parse_match(input, ",");
+ if (c == NULL) continue;
+ input = c;
+
+ const char * y = parse_base10(input, &ins->mul.y);
+ if (y == input) continue;
+ input = y;
+ if (ins->mul.y < 0 || ins->mul.y > 999) continue;
+
+ const char * p = parse_match(input, ")");
+ if (p == NULL) continue;
+ input = p;
+
+ ins->type = INSTRUCTION_MUL;
+
+ return input;
+ }
+
+ return NULL;
+}
+
+int parse_input(const char * input, int length, struct instruction * ins)
+{
+ const char * end = input + length;
+
+ int i = 0;
+ while (true) {
+ if (i >= 1000) {
+ printf("error: ins limit exceeded\n");
+ return 0;
+ }
+
+ input = parse_instruction(input, end, &ins[i]);
+ if (input == NULL)
+ break;
+ i += 1;
+ }
+
+ return i;
+}
+
+int day3_part1(char * input, int length)
+{
+ struct instruction ins[1000];
+
+ int mul_length = parse_input(input, length, ins);
+
+ int sum = 0;
+ for (int i = 0; i < mul_length; i++) {
+ if (ins[i].type == INSTRUCTION_MUL)
+ sum += ins[i].mul.x * ins[i].mul.y;
+ }
+
+ return sum;
+}
+
+int day3_part2(char * input, int length)
+{
+ struct instruction ins[1000];
+
+ int mul_length = parse_input(input, length, ins);
+
+ int mul_enabled = true;
+ int sum = 0;
+ for (int i = 0; i < mul_length; i++) {
+ switch (ins[i].type) {
+ case INSTRUCTION_MUL:
+ if (mul_enabled)
+ sum += ins[i].mul.x * ins[i].mul.y;
+ break;
+ case INSTRUCTION_DO:
+ mul_enabled = true;
+ break;
+ case INSTRUCTION_DONT:
+ mul_enabled = false;
+ break;
+ }
+ }
+
+ return sum;
+}
diff --git a/gen.sh b/gen.sh
new file mode 100755
index 0000000..2ea6aed
--- /dev/null
+++ b/gen.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+set -ex
+
+day="$1"
+
+if [ ! -z "$day" ]; then
+ re='^[0-9]+$'
+ if ! [[ $day =~ $re ]] ; then
+ echo "error: $day: not a number" >&2
+ exit 1
+ fi
+
+ mkdir -p day${day}
+ cat < day${day}/solution.c
+int day${day}_part1(char * input, int length)
+{
+ return -1;
+}
+
+int day${day}_part2(char * input, int length)
+{
+ return -1;
+}
+EOF
+
+ if [ ! -f day${day}/sample1.txt ]; then
+ touch day${day}/sample1.txt
+ fi
+
+ if [ ! -f day${day}/input.txt ]; then
+ touch day${day}/input.txt
+ fi
+fi
+
+function gen_start_size ()
+{
+ echo "$1 { ( char *)&_binary_${2}_${3}_txt_start," >> input_dreamcast.inc
+ echo "$1 (uint32_t)&_binary_${2}_${3}_txt_size }," >> input_dreamcast.inc
+}
+
+
+for i in day* ; do
+ make ${i}/sample1.txt.h ${i}/input.txt.h
+ if [ -f ${i}/sample2.txt ]; then
+ make ${i}/sample2.txt.h
+ fi
+done
+
+
+truncate -s0 input_dreamcast.inc
+
+for i in day* ; do
+ echo "#include \"${i}/sample1.txt.h\"" >> input_dreamcast.inc
+ if [ -f ${i}/sample2.txt ]; then
+ echo "#include \"${i}/sample2.txt.h\"" >> input_dreamcast.inc
+ fi
+ echo "#include \"${i}/input.txt.h\"" >> input_dreamcast.inc
+done
+echo >> input_dreamcast.inc
+echo "static struct start_size sample[][2] = {" >> input_dreamcast.inc
+for i in day* ; do
+ echo " {" >> input_dreamcast.inc
+ gen_start_size " " "${i}" "sample1"
+ if [ ! -f ${i}/sample2.txt ]; then
+ gen_start_size " " "${i}" "sample1"
+ else
+ gen_start_size " " "${i}" "sample2"
+ fi
+ echo " }," >> input_dreamcast.inc
+done
+echo "};" >> input_dreamcast.inc
+echo >> input_dreamcast.inc
+echo "static struct start_size input[] = {" >> input_dreamcast.inc
+for i in day* ; do
+ gen_start_size "" "${i}" "input"
+done
+echo "};" >> input_dreamcast.inc
+
+
+truncate -s0 solutions.mk
+echo -n "DAY_OBJ =" >> solutions.mk
+for i in day* ; do
+ echo " \\" >> solutions.mk
+ echo " ${i}/sample1.txt.o \\" >> solutions.mk
+ if [ -f ${i}/sample2.txt ]; then
+ echo " ${i}/sample2.txt.o \\" >> solutions.mk
+ fi
+ echo " ${i}/input.txt.o \\" >> solutions.mk
+ echo -n " ${i}/solution.o" >> solutions.mk
+done
+echo >> solutions.mk
+
+truncate -s0 runner.inc
+for i in day* ; do
+ echo "int ${i}_part1(char * input, int length);" >> runner.inc
+ echo "int ${i}_part2(char * input, int length);" >> runner.inc
+done
+echo >> runner.inc
+echo "part_func solution[][2] = {" >> runner.inc
+for i in day* ; do
+ echo " {${i}_part1, ${i}_part2}," >> runner.inc
+done
+echo "};" >> runner.inc
diff --git a/input_dreamcast.c b/input_dreamcast.c
index 233c9f2..0e7a81c 100644
--- a/input_dreamcast.c
+++ b/input_dreamcast.c
@@ -3,39 +3,12 @@
#include "input.h"
-#include "day1/sample1.txt.h"
-#include "day1/input.txt.h"
-
-#include "day2/sample1.txt.h"
-#include "day2/input.txt.h"
-
struct start_size {
char * start;
uint32_t size;
};
-static struct start_size input[] = {
- { ( char *)&_binary_day1_input_txt_start,
- (uint32_t)&_binary_day1_input_txt_size },
-
- { ( char *)&_binary_day2_input_txt_start,
- (uint32_t)&_binary_day2_input_txt_size },
-};
-
-static struct start_size sample[][2] = {
- {
- { ( char *)&_binary_day1_sample1_txt_start,
- (uint32_t)&_binary_day1_sample1_txt_size },
- { ( char *)&_binary_day1_sample1_txt_start,
- (uint32_t)&_binary_day1_sample1_txt_size },
- },
- {
- { ( char *)&_binary_day2_sample1_txt_start,
- (uint32_t)&_binary_day2_sample1_txt_size },
- { ( char *)&_binary_day2_sample1_txt_start,
- (uint32_t)&_binary_day2_sample1_txt_size },
- },
-};
+#include "input_dreamcast.inc"
const int input_size = (sizeof (input)) / (sizeof (input[0]));
diff --git a/input_dreamcast.inc b/input_dreamcast.inc
new file mode 100644
index 0000000..b5ba364
--- /dev/null
+++ b/input_dreamcast.inc
@@ -0,0 +1,37 @@
+#include "day1/sample1.txt.h"
+#include "day1/input.txt.h"
+#include "day2/sample1.txt.h"
+#include "day2/input.txt.h"
+#include "day3/sample1.txt.h"
+#include "day3/sample2.txt.h"
+#include "day3/input.txt.h"
+
+static struct start_size sample[][2] = {
+ {
+ { ( char *)&_binary_day1_sample1_txt_start,
+ (uint32_t)&_binary_day1_sample1_txt_size },
+ { ( char *)&_binary_day1_sample1_txt_start,
+ (uint32_t)&_binary_day1_sample1_txt_size },
+ },
+ {
+ { ( char *)&_binary_day2_sample1_txt_start,
+ (uint32_t)&_binary_day2_sample1_txt_size },
+ { ( char *)&_binary_day2_sample1_txt_start,
+ (uint32_t)&_binary_day2_sample1_txt_size },
+ },
+ {
+ { ( char *)&_binary_day3_sample1_txt_start,
+ (uint32_t)&_binary_day3_sample1_txt_size },
+ { ( char *)&_binary_day3_sample2_txt_start,
+ (uint32_t)&_binary_day3_sample2_txt_size },
+ },
+};
+
+static struct start_size input[] = {
+ { ( char *)&_binary_day1_input_txt_start,
+ (uint32_t)&_binary_day1_input_txt_size },
+ { ( char *)&_binary_day2_input_txt_start,
+ (uint32_t)&_binary_day2_input_txt_size },
+ { ( char *)&_binary_day3_input_txt_start,
+ (uint32_t)&_binary_day3_input_txt_size },
+};
diff --git a/parse.c b/parse.c
index 9b333da..9ee5c23 100644
--- a/parse.c
+++ b/parse.c
@@ -1,4 +1,5 @@
#include
+#include
#include "parse.h"
@@ -43,3 +44,13 @@ const char * parse_base10(const char * s, int * n)
return s;
}
+
+const char * parse_match(const char * s, const char * m)
+{
+ while (*m != 0) {
+ if (*s++ != *m++) {
+ return NULL;
+ }
+ }
+ return s;
+}
diff --git a/parse.h b/parse.h
index a468f4f..2ba5884 100644
--- a/parse.h
+++ b/parse.h
@@ -6,6 +6,7 @@ extern "C" {
const char * parse_skip(const char * s, char c);
const char * parse_base10(const char * s, int * n);
+const char * parse_match(const char * s, const char * m);
#ifdef __cplusplus
}
diff --git a/runner.c b/runner.c
index debc78c..842ca40 100644
--- a/runner.c
+++ b/runner.c
@@ -4,17 +4,9 @@
#include "input.h"
#include "runner.h"
-int day1_part1(char * input, int length);
-int day1_part2(char * input, int length);
-int day2_part1(char * input, int length);
-int day2_part2(char * input, int length);
-
typedef int (* part_func)(char * input, int length);
-part_func solution[][2] = {
- {day1_part1, day1_part2},
- {day2_part1, day2_part2},
-};
+#include "runner.inc"
const int solution_days = (sizeof (solution)) / (sizeof (solution[0]));
bool runner_tick(struct runner_state * runner_state)
diff --git a/runner.inc b/runner.inc
new file mode 100644
index 0000000..b7c647d
--- /dev/null
+++ b/runner.inc
@@ -0,0 +1,12 @@
+int day1_part1(char * input, int length);
+int day1_part2(char * input, int length);
+int day2_part1(char * input, int length);
+int day2_part2(char * input, int length);
+int day3_part1(char * input, int length);
+int day3_part2(char * input, int length);
+
+part_func solution[][2] = {
+ {day1_part1, day1_part2},
+ {day2_part1, day2_part2},
+ {day3_part1, day3_part2},
+};
diff --git a/runner_dreamcast.cpp b/runner_dreamcast.cpp
index 47a99b7..2c1b2ab 100644
--- a/runner_dreamcast.cpp
+++ b/runner_dreamcast.cpp
@@ -278,5 +278,6 @@ int main()
transfer_scene(font, glyphs);
}
+ while (1);
serial::string("return\n");
}
diff --git a/solutions.mk b/solutions.mk
new file mode 100644
index 0000000..2e0ce19
--- /dev/null
+++ b/solutions.mk
@@ -0,0 +1,11 @@
+DAY_OBJ = \
+ day1/sample1.txt.o \
+ day1/input.txt.o \
+ day1/solution.o \
+ day2/sample1.txt.o \
+ day2/input.txt.o \
+ day2/solution.o \
+ day3/sample1.txt.o \
+ day3/sample2.txt.o \
+ day3/input.txt.o \
+ day3/solution.o