From 37b740f07a5545292a81887d6450f113c4219ecc Mon Sep 17 00:00:00 2001 From: ktkk Date: Thu, 11 Dec 2025 12:15:11 +0000 Subject: [PATCH 01/10] Finish day11, part 1 --- src/days/day11.zig | 76 ++++- src/days/input/day11.txt | 609 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 683 insertions(+), 2 deletions(-) create mode 100755 src/days/input/day11.txt diff --git a/src/days/day11.zig b/src/days/day11.zig index d16d9d5..cfbf883 100644 --- a/src/days/day11.zig +++ b/src/days/day11.zig @@ -1,7 +1,79 @@ const std = @import("std"); -pub const title = "Day 11"; +pub const title = "Day 11: Reactor"; -pub fn run(_: std.mem.Allocator) !void { +pub fn run(allocator: std.mem.Allocator) !void { + const input = @embedFile("./input/day11.txt"); + //const input = + // \\aaa: you hhh + // \\you: bbb ccc + // \\bbb: ddd eee + // \\ccc: ddd eee fff + // \\ddd: ggg + // \\eee: out + // \\fff: out + // \\ggg: out + // \\hhh: ccc fff iii + // \\iii: out + // ; + + var lines = std.mem.tokenizeScalar(u8, input, '\n'); + + var devices: std.StringHashMap([][]const u8) = .init(allocator); + defer { + var outputs_iter = devices.valueIterator(); + while (outputs_iter.next()) |value| { + allocator.free(value.*); + } + devices.deinit(); + } + + while (lines.next()) |line| { + const device = line[0..3]; + std.debug.print("device = {s}\n", .{device}); + + var outputs: std.ArrayList([]const u8) = .empty; + defer outputs.deinit(allocator); + + var outputs_iter = std.mem.tokenizeScalar(u8, line[5..], ' '); + while (outputs_iter.next()) |output| { + try outputs.append(allocator, output); + } + + const outputs_slice = try outputs.toOwnedSlice(allocator); + errdefer allocator.free(outputs_slice); + + try devices.put(device, outputs_slice); + } + + var paths_to_out: usize = 0; + visitOutputs("you", devices, &paths_to_out); + + var buffer: [8]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&buffer); + const stdout = &stdout_writer.interface; + + try stdout.print("{d}\n", .{paths_to_out}); + + try stdout.flush(); +} + +fn visitOutputs( + start: []const u8, + devices: std.StringHashMap([][]const u8), + paths_to_out: *usize, +) void { + const device = devices.get(start); + if (device) |outputs| { + for (outputs) |output| { + if (std.mem.eql(u8, output, "out")) { + paths_to_out.* += 1; + } else { + visitOutputs(output, devices, paths_to_out); + } + } + } else { + std.debug.print("device {s} not found\n", .{start}); + } } diff --git a/src/days/input/day11.txt b/src/days/input/day11.txt new file mode 100755 index 0000000..1c6713e --- /dev/null +++ b/src/days/input/day11.txt @@ -0,0 +1,609 @@ +smx: otc +mmh: gvp +gbo: hyf alz +laa: vky qjq +vrn: tbs tsr jix +xyl: xel eur wdj +sxm: out +wsd: kua hpv jep +qsj: ulu xel eur wdj +xwa: mtd xxf hnw +kai: ehr kaj +uuj: you +owb: ixr bps pim eez ejn syt qrx hxw vsy ghl gfu cgh mpk kfj +vky: owb wlw qic +ysd: mkp jbf btz xgg gbk tvg iju amm dws ykz azc blh xld rpr uek rcl zzy jhu +rbc: ski xyl sdx wpw +zmc: pal lwb rns hex +cuu: vyo +bqf: kmy exx ish +jbv: ysa +aog: ayv kwq +fcq: qic xss owb +hyg: out +xoz: llx kra cqn bzn swe tdo vnz zos duw +gnq: eya +qmk: fcq lyd +ggp: brz eya +oit: yyy quh brz +hjl: dtj lnc jps fyr +sqg: xbz upq +nil: diq +xqa: jei ipw tkt +ond: fft jko dqj pxe +and: ahn izm esa +cqf: xss +rqa: ryb rwu ono fyb +jps: byj fmv shn +ccg: ond afk tbu +dta: ctq jbw whr smq +ztx: hlm ctr vgo maf fkj +sdx: xel eur +xwb: dds +clh: ktb +rtn: quh eya +dac: nxc vug eou +nvh: kmf yga wtv +xgw: kep unr lju mtm +mdx: qmk fwk fbd +tbu: fft dqj pxe +vil: lyz aek +ona: zjk ovx dmv laa +bld: zbs +rms: vjs znm +oku: brz yyy +bzn: dmc fwa ykh vrn axj +uzl: ayv fuz qhs kwq +bhz: ggv +kfj: xqa ucr akl +koi: szi +mvo: dqp kjr rbc +rof: vgo hlm +ixt: jws nxc vug +ycf: out +dmc: tsr +nam: mvo +rkj: quh yyy eya brz +qxk: uty +lwb: phc esx +fqf: isr dax +eou: lqz ysd +lbb: out +hyf: fgh wem yen taw +dfv: nzl +pnh: lai +jon: eya +guf: shn +lmw: hlu mhq +jff: ngn gye +xxj: guf dtj lnc +fbd: fcq lyd +idw: cmg phc +zbs: hjl +lqz: blh ttg ykz jhu zzy uek rcl bld xgg gbk mkp amm iju tvg +shn: goi +hdc: wap pvr +odf: yey ggp jtc +rkk: zyi ubs +fyr: fmv vtv +pxe: ztx mmi +ntf: dds cst aff +lyz: gwp +pyt: zpv ias oiz +cqx: rod jnp +dtj: shn vtv +gfu: kai ctq +ycw: ryl ixt uut dac +yvb: jbv rms fez +lvx: tvz vyo +pvr: yat +oiz: zjk ovx dmv +biy: tdg +xbz: cqf +obk: jje +jcc: ssq daa +elu: ihl kep lju unr +jgf: qfx bhz +wbp: xxj cap hjl +nne: out +llx: axj ykh +kso: kuk ams +eod: nzl aap +ryl: nxc +epd: eou jws ats nxc vug +wqg: uzn yyf +qhh: lqz +fhu: hex idw pal +ipt: ema +vpo: cap xxj +thl: azd otc +ttg: vpo +uty: owb qic +brz: mdl eiw gam aog nam wqg jcc kgs nac bsk zpk kul snr uzl +faw: out +lzw: wlw xss owb qic +wap: iel yat qhh paa +ffr: vnn fiv +nug: sqg eyp sws eai dsh icy zrp mas dmf ccg hoq qze qde cqt zvl jrq gep +ygk: jon oit +eya: ppx nac mdl dej +lnc: byj fmv shn +nhq: kjv +biq: lav xhe vcg +hfn: pvr ydj +leg: oii zad jje +fft: rof taz +maf: qic +aap: rkj hrs svl +axv: esa +zou: ulu eur xel +jtc: yyy +pxc: gvr dyo omt +byj: nqz goi faw +ykh: jix tbs tsr +fai: cst nug aff +oty: nhq +cek: vvv ubs zyi +ufu: zen +xtk: kpg tap qzv +kil: dds aff +ojk: lqz +aly: qak lqz +xxf: aff cst dds +yua: oit ktb rwv +vlf: ujz +lbw: zyi uuj +zpk: nhp urn ctg +kuk: you ysd qak +tmy: esa +sqi: quh lvi +jrq: obk leg +yat: lqz +atl: zpv ias oiz ona obm +xhe: asz jbv +gdx: oii jje +ssq: fqf tap kpg qzv +quh: snr kul zpk bsk nac ufu yor dej ppx aog nam wqg eiw mdl +bvn: luk +zny: jon ktb rwv +jzw: aap plm +jqp: dac +mpk: euv llh +fpr: gwp zmc ulq fhu +ahn: qtl rtn +zyi: lqz ysd +ypn: mtd xxf +fgh: rkk +vgo: xss owb wlw +axj: jix tsr +kgv: kpg +gfa: ona obm zpv ias +eur: eij vil oxs xip hsd hdc gbo laz rnq lnj nuk xck twd jqp ycw btu abg koi cey hfn +bsk: oqd hmt kew +wrx: tas +jix: aff nug cst dds qvv +blc: yan +rwv: yyy quh eya brz +exx: blc dks +ujz: mwp +yyf: xya xmb fee +icq: mtm +hxw: viq eod +xii: fyb +lyb: drx mlf pkl +puw: ona ias +ilj: qfx xph +wlw: gfu ghl vlf cgh mpk yfx pbj qrx hxw jsq eez syt dta ejn bps hnj pim +icy: xbz +wdr: gbm kil +svl: lvi +dax: wdj eur +fwa: jix tsr +fyb: you ysd qak +whr: ehr kaj ogx nvh +agb: mag yan +duw: luk yzp nil +plg: yen taw fks wem fgh +zrp: pyt puw qyk gfa atl +phc: you qak lqz +aff: qze hoq qde mdx zvl jrq sqg dsh eai zrp icy mas dmf +ulu: lnj xck twd jqp btu ycw abg koi gqf hfn eij vil oxs xip nhi hsd hdc kku laz rnq +ezt: nug cst qvv dds +ccu: yyy brz eya +nuk: zpf +ubs: ysd +qyk: ona oiz +kua: wlw xss qic +ssa: kua +uds: ier vnn fiv +cbw: gvr +pln: wdj ulu +zos: htz ilj +viq: aap nzl +azd: jff +esa: rtn oku +rzd: eya brz +syt: euv cbo +drx: tdg +qjq: xss owb +jru: aat eoy dqu +vms: bzf gkm ffr uds +zen: vms zuv vci +qfx: wdr +amm: wbp vpo evr jmb zbs +hnj: sxp viq jzw +vtv: goi +kep: xnp yoh evy +evr: cap +gvp: yyy brz lvi eya +kxs: rod jru uvb +daa: jlo +fks: lbw cek +omt: dds +gtx: out +jws: lqz qak +eoy: out +qvv: fes dmf icy zrp eai dsh iyb sqg eyp sws gep jrq mdx zvl qfd qde qze hoq ccg +smq: kaj +kmy: agb +qde: atl +fez: znm mvj vjs +cey: wrx ryw lbx +ema: brz eya lvi quh yyy +zfg: cst nug aff qvv +pim: yip pxl ujz +zge: lzw +ykz: yrg bss smx +yyy: snr zpk uzl ufu bsk dej yte kgs gam eiw wqg +yor: kew +cmg: lqz qak ysd +xya: zou pln uaz +zpv: laa +yen: cek rkk fce iwk +boc: eay hlu +ygu: xya ofj +xnp: oic zfg eft xwb +nlb: izm +fmv: nqz +mag: aem wtx qrc pyc ipu +tdo: jgf +znm: sxm lbb +mtm: xnp +khk: ipt qvi +vyo: eur wdj +kye: out +uvb: dqu aat yvz +xck: lyz fpr aek arq +acb: wtv gts +gep: qxk upq +ihl: xnp yoh +eyp: qyk +lai: qsj +ipu: out +isr: ulu +qrc: out +jhu: bqf +eij: uut dac ryl epd +tvg: yrg thl mvu bss +pbj: ucr +cst: ccg sws hoq qze dsh qde cqt +yzp: xwa diq cft ypn +uut: eou ats +fee: zou +dqj: mmi taz rof ztx +rnq: arq aek +yfk: yvb zzh +lvi: jcc dej mdl gam aog nam zpk kul uzl ufu bsk nac +tap: sxw +jsq: dfv sxp viq jzw +tdg: aff nug cst dds +cgh: tmy oze nlb and +qzv: dax +jtn: xhe +kjr: ski wpw sdx xyl +ski: wdj xel +oqd: zuv +ppx: zen hmt kew +vcg: jbv +jbw: nvh +ctg: dqp +dcv: owb wlw qic +kzs: rxd lai cuu lvx +dws: bss yrg thl mvu +ara: dds qvv cst nug aff +ctr: owb wlw +ctq: ehr kaj acb +zpf: fgh fks +pyc: out +ras: gvr omt +iby: xxb rqa vlx +gam: mah ygu uzn +ulq: idw lwb pal +gkm: ier +cqn: pdv elu +tvz: ulu +obm: laa +btu: alz +wtx: out +xel: oty oxs vil eij hsd nhi hdc gbo kku lnj ycw btu jqp xck gqf hfn cey koi abg +uxa: lwb hex rns +yga: gnq +ppv: lav xhe vcg +upq: hzh cqf lzw uty +mvu: otc exw +yrg: otc azd +kul: qsu xtk ssq daa kgv +pif: mbd bzn mzo xhj wee jdf +xhy: wus khk mwp +ehr: wtv gts yga +fes: zge +rwu: you qak ysd lqz +hnw: cst +goi: out +hsd: alz zpf amk +hzh: wlw xss qic +lbs: vlx rqa +dds: mdx zvl qde qfd qze jrq zrp icy iyb dsh eyp sqg fes dmf mas +tsh: hpv kua +svr: xoz lak pif ryf dyv +gua: hlu +jei: jtc ggp +wpw: xel eur wdj ulu +jbf: biq jtn hut ppv yfk +hoq: qmk fwk cxr fbd +blh: evr vpo zbs jmb +mas: gdx +afk: jko pxe +zzy: lmw boc +vsy: tmy oze axv and +htz: xph qfx bhz +yte: mah ygu uzn rcr +zuv: bzf gkm ffr uds +yvz: out +ejn: dok llh euv +jlo: dax isr +qvi: gvp ema rzd +mdl: mah +wdj: hfn gqf cey koi jqp twd lnj rnq gbo kku hdc hsd oty vil eij abg ycw btu xck nuk nhi oxs +ias: dmv zjk ovx +laz: nhq +ish: blc +pkl: ezt ara +xhj: elu +tlp: ais +mux: zrm uvb +vci: bzf gkm uds +nie: wtx aem qrc +ike: wdj xel ulu +abg: pvr wap +ono: lqz +yip: khk +oze: ahn izm +lak: bvn mbd llx xhj lyb pxo +dmf: obk leg +wus: ipt qvi +oic: nug cst qvv dds +rpr: ifc fjg mfu +vvv: qak +qtl: lvi brz quh yyy +rqt: pdv icq +yoh: eft ntf oic +aby: nug dds +yfx: axv tmy +xmb: uaz pln +hrs: brz quh yyy +eez: llh cbo +lyd: qic owb xss wlw +dyo: dds qvv aff cst nug +evy: xwb eft ntf +plv: esz ktb jon +luk: xwa ypn +nqz: out +ier: wdj eur ulu +yey: quh eya lvi brz +otc: svv tlp jff +qze: leg gdx obk +aek: gwp ulq +mah: xmb fee xya +pxl: khk xux wus +wem: iwk cek lbw rkk +nhi: uut ryl epd +cui: out +qak: ykz xmj jbf rpr xgg blh +qwm: eya lvi brz quh +dsh: zge qxk upq xbz +hmt: zuv +bss: azd otc +rxd: vyo qsj +eay: uhs mux kxs +vnn: ulu wdj eur xel +iju: ckk lmw gua +fiv: wdj eur xel ulu +izm: rtn oku +xld: fjg mfu ifc +xph: ggv nqb +ija: rxd cuu +tsr: nug cst aff dds qvv +uaz: ulu wdj eur +ats: lqz you qak ysd +cft: xxf aby +taw: iwk cek lbw rkk +rns: ojk phc +qic: vlf eez cgh yfx dta syt bps hnj jsq +gqf: zpf amk plg hyf +ryb: qak +tbs: nug aff qvv dds +gbk: yfk +eiw: mvo ctg urn abp +kpg: sxw isr +pal: phc ojk esx +ais: nne hyg kye ycf +fjg: kmy +uzn: fee xmb +hpv: owb xss wlw qic +hlu: mux cqx +azc: ckk lmw boc +dqp: xyl ike +aat: out +fuz: srk pnh ija +ypw: jgf +pdv: kep +dmv: qjq vky +fya: llv iby lbs +plm: rkj +xux: ipt qvi mmh +gye: kye gme +zzh: fez asz rms +snr: ayv fuz qhs +ydj: qhh akg paa +rcr: ofj fee xmb xya +kaj: wtv kmf yga +lju: yoh evy +ebo: sqi jtc yey +vlx: rwu ryb ono +tas: xxb xii +wee: pdv xgw +fkj: owb wlw +xro: ilj htz jgf +hum: lqz ysd +kku: bsy aek lyz +euv: clh plv yua ygk +akl: ebo jei tkt odf +lnj: fya lbx +lbx: iby lbs +mhq: cqx uhs +hut: vcg zzh +szi: mnj ams +ysa: sxm rni lbb +vug: you +llh: ygk yua zny plv clh +nzl: hrs +uek: mvu +mmi: maf vgo hlm +eft: dds cst +dok: zny yua clh plv +kmf: npf lef nsp +mnj: you qak ysd lqz +paa: qak you +ghl: xhy +ggv: kil gbm fai lvh +jje: ssa +jko: mmi +srk: rxd +yan: ipu +nxc: lqz you qak +gts: qwm npf lef gnq +qrx: kai smq whr +ovx: oiw +unr: evy xnp +kew: vms vci +sxp: aap +oii: tsh wsd +cbo: ygk clh +xip: wrx lbx +sws: ond tbu +abp: rbc +tkt: ccu ggp +diq: xxf mtd hnw +gvr: nug cst +ipw: jtc ccu +arq: uxa gwp ulq +iwk: vvv uuj aly zyi +mfu: exx kmy +dks: nie mag +twd: fpr lyz arq bsy +fwk: lyd +jnp: eoy aat +nsp: brz eya yyy +xss: vsy bps ixr hxw syt pbj kfj gfu +nac: kgv xtk qsu +oiw: qic xss owb wlw +svv: ais gye +mtd: cst dds qvv +ixr: and nlb axv +jdf: pxc cbw +dyv: dea wnr xro ypw xlu +qfd: afk ond +wtv: qwm nsp +xxb: rwu ryb fyb ono +wnr: xgw elu +uhs: uvb zrm jnp rod jru +asz: mvj vjs +eai: gfa puw +ofj: uaz +vnz: pkl +kgs: mvo urn abp ctg +fce: ubs uuj vvv +pxo: vrn fwa dmc ykh +cxr: lyd fcq dcv +xgg: ifc +mzo: biy pkl mlf +gwp: pal idw rns hex +you: dws amm iju tvg bld xgg jbf btz mkp jhu uek blh xld ykz ttg azc +jep: wlw xss +nqb: lvh +zrm: yvz eoy aat cui +zmm: odf ipw jei +kjv: qak ysd +akg: you ysd lqz +lvh: qvv dds aff cst +ogx: gts yga +urn: kjr rbc +bsy: uxa fhu zmc gwp ulq +lav: asz fez +exw: svv +esz: lvi +sxw: eur xel +ams: lqz +qsu: fqf kpg tap +bps: akl zmm xqa +ayv: srk pnh ija kzs +gme: out +oxs: szi nhq kso +hex: esx hum ojk cmg phc +xlu: luk +aem: out +mlf: ara +kwq: srk pnh kzs +jmb: xxj cap +dqu: out +iel: ysd +ucr: ipw +cqt: fbd qmk fwk +nhp: dqp kjr +ifc: ish +llv: rqa xii xxb +dea: luk yzp nil +ngn: nne gme ycf hyg +ryf: xlu rqt swe bvn lyb duw cqn bzn jdf wnr wee ypw pxo vnz xhj zos +lef: brz quh +mbd: pxc +cap: dtj guf +rcl: wbp evr vpo jmb +zvl: fbd cxr fwk +btz: lmw gua +ktb: brz yyy +taz: ctr hlm vgo fkj +mkp: jtn hut yfk ppv +iyb: afk tbu +gbm: nug dds +swe: ras +ckk: hlu eay +rni: out +bzf: fiv +qhs: ija +rod: yvz +amk: yen taw +vjs: rni sxm +hlm: owb xss +zjk: oiw +mvj: gtx rni +ryw: iby llv +npf: quh brz lvi +zad: ssa tsh +esx: lqz ysd +mwp: mmh +alz: wem yen +kra: luk nil +xmj: smx +dej: kew From f85eda4e870dba5bd8fe6b5b1f2ff05c9167856d Mon Sep 17 00:00:00 2001 From: ktkk Date: Thu, 11 Dec 2025 15:48:33 +0000 Subject: [PATCH 02/10] WIP: implement part 2 --- src/days/day11.zig | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/days/day11.zig b/src/days/day11.zig index cfbf883..2525215 100644 --- a/src/days/day11.zig +++ b/src/days/day11.zig @@ -5,16 +5,19 @@ pub const title = "Day 11: Reactor"; pub fn run(allocator: std.mem.Allocator) !void { const input = @embedFile("./input/day11.txt"); //const input = - // \\aaa: you hhh - // \\you: bbb ccc - // \\bbb: ddd eee - // \\ccc: ddd eee fff - // \\ddd: ggg - // \\eee: out - // \\fff: out + // \\svr: aaa bbb + // \\aaa: fft + // \\fft: ccc + // \\bbb: tty + // \\tty: ccc + // \\ccc: ddd eee + // \\ddd: hub + // \\hub: fff + // \\eee: dac + // \\dac: fff + // \\fff: ggg hhh // \\ggg: out - // \\hhh: ccc fff iii - // \\iii: out + // \\hhh: out // ; var lines = std.mem.tokenizeScalar(u8, input, '\n'); @@ -47,7 +50,7 @@ pub fn run(allocator: std.mem.Allocator) !void { } var paths_to_out: usize = 0; - visitOutputs("you", devices, &paths_to_out); + visitOutputs("svr", devices, &paths_to_out, false, false); var buffer: [8]u8 = undefined; var stdout_writer = std.fs.File.stdout().writer(&buffer); @@ -62,14 +65,26 @@ fn visitOutputs( start: []const u8, devices: std.StringHashMap([][]const u8), paths_to_out: *usize, + visited_fft: bool, + visited_dac: bool, ) void { const device = devices.get(start); if (device) |outputs| { for (outputs) |output| { if (std.mem.eql(u8, output, "out")) { - paths_to_out.* += 1; + std.debug.print("found out! (fft = {any}, dac = {any})\n", .{visited_fft, visited_dac}); + if (visited_fft and visited_dac) { + std.debug.print("visited fft and dac\n", .{}); + paths_to_out.* += 1; + } + } else if (std.mem.eql(u8, output, "fft")) { + std.debug.print("found fft!\n", .{}); + visitOutputs(output, devices, paths_to_out, true, visited_dac); + } else if (std.mem.eql(u8, output, "dac")) { + std.debug.print("found dac!\n", .{}); + visitOutputs(output, devices, paths_to_out, visited_fft, true); } else { - visitOutputs(output, devices, paths_to_out); + visitOutputs(output, devices, paths_to_out, visited_fft, visited_dac); } } } else { From 76b70d3c6b3251b5a6352c7242a955818bf152fe Mon Sep 17 00:00:00 2001 From: ktkk Date: Thu, 11 Dec 2025 16:30:51 +0000 Subject: [PATCH 03/10] WIP: implement part 2 --- src/days/day11.zig | 49 +++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/days/day11.zig b/src/days/day11.zig index 2525215..b8084d4 100644 --- a/src/days/day11.zig +++ b/src/days/day11.zig @@ -5,6 +5,18 @@ pub const title = "Day 11: Reactor"; pub fn run(allocator: std.mem.Allocator) !void { const input = @embedFile("./input/day11.txt"); //const input = + // \\aaa: you hhh + // \\you: bbb ccc + // \\bbb: ddd eee + // \\ccc: ddd eee fff + // \\ddd: ggg + // \\eee: out + // \\fff: out + // \\ggg: out + // \\hhh: ccc fff iii + // \\iii: out + // ; + //const input = // \\svr: aaa bbb // \\aaa: fft // \\fft: ccc @@ -49,8 +61,11 @@ pub fn run(allocator: std.mem.Allocator) !void { try devices.put(device, outputs_slice); } + var cache: std.StringHashMap(usize) = .init(allocator); + defer cache.deinit(); + var paths_to_out: usize = 0; - visitOutputs("svr", devices, &paths_to_out, false, false); + try visitOutputs("svr", "fft", devices, &cache, &paths_to_out); var buffer: [8]u8 = undefined; var stdout_writer = std.fs.File.stdout().writer(&buffer); @@ -63,30 +78,28 @@ pub fn run(allocator: std.mem.Allocator) !void { fn visitOutputs( start: []const u8, + end: []const u8, devices: std.StringHashMap([][]const u8), - paths_to_out: *usize, - visited_fft: bool, - visited_dac: bool, -) void { + cache: *std.StringHashMap(usize), + paths_to_end: *usize, +) !void { + if (cache.get(start)) |result| { + paths_to_end.* += result; + return; + } + + var paths: usize = 0; const device = devices.get(start); if (device) |outputs| { for (outputs) |output| { - if (std.mem.eql(u8, output, "out")) { - std.debug.print("found out! (fft = {any}, dac = {any})\n", .{visited_fft, visited_dac}); - if (visited_fft and visited_dac) { - std.debug.print("visited fft and dac\n", .{}); - paths_to_out.* += 1; - } - } else if (std.mem.eql(u8, output, "fft")) { - std.debug.print("found fft!\n", .{}); - visitOutputs(output, devices, paths_to_out, true, visited_dac); - } else if (std.mem.eql(u8, output, "dac")) { - std.debug.print("found dac!\n", .{}); - visitOutputs(output, devices, paths_to_out, visited_fft, true); + if (std.mem.eql(u8, output, end)) { + paths += 1; } else { - visitOutputs(output, devices, paths_to_out, visited_fft, visited_dac); + try visitOutputs(output, end, devices, cache, &paths); } } + try cache.put(start, paths); + paths_to_end.* += paths; } else { std.debug.print("device {s} not found\n", .{start}); } From 524b451399f6cd8bcf77db8034b70982c6d77108 Mon Sep 17 00:00:00 2001 From: ktkk Date: Thu, 11 Dec 2025 18:40:52 +0000 Subject: [PATCH 04/10] Finish day11, part 2 --- src/days/day11.zig | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/days/day11.zig b/src/days/day11.zig index b8084d4..5e7686a 100644 --- a/src/days/day11.zig +++ b/src/days/day11.zig @@ -63,15 +63,29 @@ pub fn run(allocator: std.mem.Allocator) !void { var cache: std.StringHashMap(usize) = .init(allocator); defer cache.deinit(); + try cache.ensureTotalCapacity(devices.count()); - var paths_to_out: usize = 0; - try visitOutputs("svr", "fft", devices, &cache, &paths_to_out); + const dac_to_fft = try visitOutputs("dac", "fft", devices, &cache); + const svr_to_fft = try visitOutputs("svr", "fft", devices, &cache); + cache.clearRetainingCapacity(); + + const to_fft = if (dac_to_fft == 0) svr_to_fft else dac_to_fft; + + const dac_start = if (dac_to_fft == 0) "fft" else "svr"; + const end_start = if (dac_to_fft == 0) "dac" else "fft"; + + const to_dac = try visitOutputs(dac_start, "dac", devices, &cache); + cache.clearRetainingCapacity(); + + const to_end = try visitOutputs(end_start, "out", devices, &cache); + + const result = to_fft * to_dac * to_end; var buffer: [8]u8 = undefined; var stdout_writer = std.fs.File.stdout().writer(&buffer); const stdout = &stdout_writer.interface; - try stdout.print("{d}\n", .{paths_to_out}); + try stdout.print("{d}\n", .{result}); try stdout.flush(); } @@ -81,11 +95,9 @@ fn visitOutputs( end: []const u8, devices: std.StringHashMap([][]const u8), cache: *std.StringHashMap(usize), - paths_to_end: *usize, -) !void { +) !usize { if (cache.get(start)) |result| { - paths_to_end.* += result; - return; + return result; } var paths: usize = 0; @@ -95,13 +107,14 @@ fn visitOutputs( if (std.mem.eql(u8, output, end)) { paths += 1; } else { - try visitOutputs(output, end, devices, cache, &paths); + paths += try visitOutputs(output, end, devices, cache); } } try cache.put(start, paths); - paths_to_end.* += paths; + return paths; } else { std.debug.print("device {s} not found\n", .{start}); + return 0; } } From b55a6d61da63d5eab872d4987d515edf808d7015 Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 11:02:47 +0000 Subject: [PATCH 05/10] WIP: implement part 1 --- src/days/day12.zig | 170 ++++++- src/days/input/day12.txt | 1030 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 1198 insertions(+), 2 deletions(-) create mode 100755 src/days/input/day12.txt diff --git a/src/days/day12.zig b/src/days/day12.zig index e5f9176..d940d18 100644 --- a/src/days/day12.zig +++ b/src/days/day12.zig @@ -1,7 +1,173 @@ const std = @import("std"); -pub const title = "Day 12"; +pub const title = "Day 12: Christmas Tree Farm"; -pub fn run(_: std.mem.Allocator) !void { +pub fn run(allocator: std.mem.Allocator) !void { + //const input = @embedFile("./input/day12.txt"); + const input = + \\0: + \\### + \\##. + \\##. + \\ + \\1: + \\### + \\##. + \\.## + \\ + \\2: + \\.## + \\### + \\##. + \\ + \\3: + \\##. + \\### + \\##. + \\ + \\4: + \\### + \\#.. + \\### + \\ + \\5: + \\### + \\.#. + \\### + \\ + \\4x4: 0 0 0 0 2 0 + \\12x5: 1 0 1 0 2 2 + \\12x5: 1 0 1 0 3 2 + ; + + var lines = std.mem.tokenizeScalar(u8, input, '\n'); + + var presents: std.ArrayList(Present) = .empty; + defer presents.deinit(allocator); + + var regions: std.ArrayList(Region) = .empty; + defer { + for (regions.items) |region| { + region.deinit(allocator); + } + regions.deinit(allocator); + } + + while (lines.next()) |line| { + var semicolon_pos: usize = 0; + var x_pos: ?usize = null; + for (line, 0..) |c, i| { + switch (c) { + 'x' => x_pos = i, + ':' => { + semicolon_pos = i; + break; + }, + else => {}, + } + } + if (semicolon_pos != 0) { + if (x_pos) |p| { + // region + const width = try std.fmt.parseUnsigned(u8, line[0..p], 10); + const height = try std.fmt.parseUnsigned(u8, line[p + 1..semicolon_pos], 10); + + var required_presents: std.ArrayList(u8) = .empty; + defer required_presents.deinit(allocator); + if (presents.items.len > 0) { + try required_presents.ensureTotalCapacity(allocator, presents.items.len); + } + + var presents_iter = std.mem.tokenizeScalar(u8, line[semicolon_pos + 2..], ' '); + while (presents_iter.next()) |present| { + const amount = try std.fmt.parseUnsigned(u8, present, 10); + try required_presents.append(allocator, amount); + } + + const required_presents_slice = try required_presents.toOwnedSlice(allocator); + errdefer allocator.free(required_presents_slice); + + const region: Region = .{ + .width = width, + .height = height, + .required_presents = required_presents_slice, + }; + try regions.append(allocator, region); + } else { + // present + var present: Present = .{ + .shape = .initEmpty(), + }; + for (0..Present.Width) |y| { + const l = lines.next() orelse unreachable; + for (0..Present.Width) |x| { + if (l[x] == '#') { + present.set(x, y); + } + } + } + try presents.append(allocator, present); + } + } + } + + for (presents.items, 0..) |present, i| { + std.debug.print("{d}:\n{f}\n\n", .{i, present}); + } + + for (regions.items) |region| { + std.debug.print("{f}\n", .{region}); + } } +const Present = struct { + shape: std.bit_set.IntegerBitSet(Width * Width), + + const Width = 3; + + const Self = @This(); + + pub fn format(self: Self, w: *std.Io.Writer) std.Io.Writer.Error!void { + for (0..Width) |y| { + for (0..Width) |x| { + try w.writeByte(if (self.isSet(x, y)) '#' else '.'); + } + if (y < Width - 1) { + try w.writeByte('\n'); + } + } + } + + pub fn set(self: *Self, x: usize, y: usize) void { + const index = (y * Width) + x; + self.shape.set(index); + } + + pub fn isSet(self: Self, x: usize, y: usize) bool { + const index = (y * Width) + x; + return self.shape.isSet(index); + } +}; + +const Region = struct { + width: u8, + height: u8, + required_presents: []u8, + + const Self = @This(); + + pub fn deinit(self: Self, allocator: std.mem.Allocator) void { + allocator.free(self.required_presents); + } + + pub fn format(self: Self, w: *std.Io.Writer) std.Io.Writer.Error!void { + try w.print("{d}x{d}: ", .{self.width, self.height}); + for (self.required_presents, 0..) |present, i| { + try w.print("{d}", .{present}); + if (i < self.required_presents.len - 1) { + try w.writeByte(' '); + } + } + } +}; + diff --git a/src/days/input/day12.txt b/src/days/input/day12.txt new file mode 100755 index 0000000..6b6eac1 --- /dev/null +++ b/src/days/input/day12.txt @@ -0,0 +1,1030 @@ +0: +..# +.## +### + +1: +### +.## +.## + +2: +..# +.## +##. + +3: +##. +.## +### + +4: +### +#.# +#.# + +5: +### +.#. +### + +46x37: 23 26 23 34 38 36 +46x38: 47 53 50 49 36 36 +38x41: 28 24 30 26 22 26 +49x43: 48 59 49 63 49 54 +49x41: 48 50 45 59 54 51 +49x50: 60 60 60 70 60 66 +50x41: 55 43 52 54 49 63 +35x45: 41 46 31 47 37 38 +45x46: 51 47 59 61 51 51 +36x48: 47 57 28 37 47 46 +38x47: 57 36 50 48 35 52 +44x39: 32 31 34 32 29 23 +38x45: 33 26 32 40 23 25 +37x45: 46 40 29 38 57 43 +46x41: 33 36 31 34 25 36 +37x44: 39 44 34 41 40 50 +46x50: 50 64 45 58 72 60 +40x40: 26 36 28 31 24 23 +48x49: 55 56 70 67 63 53 +37x38: 25 33 20 21 17 27 +42x35: 31 45 39 37 34 40 +45x47: 53 58 63 52 46 56 +49x49: 56 60 65 60 64 65 +43x43: 52 45 42 52 46 47 +43x41: 48 45 32 43 46 54 +38x48: 43 38 49 46 61 44 +35x46: 34 59 31 34 42 44 +37x45: 40 48 42 41 34 51 +38x36: 40 26 34 35 38 38 +47x49: 54 54 56 65 68 56 +49x45: 37 36 42 48 38 38 +43x39: 46 44 47 40 47 36 +43x37: 49 38 36 35 45 42 +35x45: 21 23 28 32 30 30 +38x43: 25 35 26 29 27 26 +44x45: 51 50 62 44 58 43 +50x43: 49 59 69 61 52 44 +40x49: 44 59 58 52 41 49 +42x50: 59 52 46 56 57 52 +38x43: 33 25 32 24 34 19 +36x44: 43 51 36 35 35 43 +50x47: 46 39 23 48 41 43 +39x46: 43 48 43 53 41 47 +41x45: 45 55 52 42 44 47 +35x36: 34 26 34 32 41 28 +40x48: 46 45 55 50 52 49 +39x45: 42 55 38 43 36 54 +41x45: 42 49 42 45 51 53 +48x49: 64 58 65 68 44 65 +38x41: 25 27 20 15 31 38 +46x41: 57 45 50 41 52 47 +44x46: 49 49 47 50 59 56 +47x45: 49 64 62 43 54 55 +37x41: 29 22 24 30 22 28 +50x36: 43 58 36 54 36 47 +37x41: 41 38 42 29 38 47 +43x47: 47 55 53 53 43 60 +38x50: 36 29 37 27 34 29 +48x47: 41 36 41 43 37 42 +38x45: 39 38 48 51 43 45 +43x49: 36 33 47 39 43 25 +48x50: 53 67 57 49 74 67 +37x48: 28 29 35 32 27 40 +48x47: 52 61 56 70 59 48 +41x43: 36 47 44 59 44 40 +35x40: 34 45 35 35 35 31 +48x46: 36 40 51 36 51 26 +49x47: 59 62 53 67 53 59 +38x40: 26 26 25 26 27 25 +42x50: 46 32 36 39 40 31 +47x50: 62 57 70 70 55 51 +45x41: 33 52 47 51 56 43 +49x35: 36 56 48 41 47 36 +45x44: 43 50 48 61 52 49 +48x47: 31 35 49 35 35 54 +44x35: 22 40 15 29 24 24 +35x36: 16 21 23 25 22 24 +36x45: 56 44 33 34 40 42 +44x44: 53 51 54 43 51 48 +48x36: 32 31 39 25 41 23 +44x42: 40 36 33 23 36 28 +41x43: 28 35 24 34 29 32 +41x37: 26 27 27 33 23 19 +41x47: 40 21 34 29 33 38 +49x35: 39 39 46 45 52 43 +44x39: 39 29 28 27 21 38 +35x37: 41 28 28 38 33 31 +44x49: 33 51 27 40 31 42 +50x45: 49 39 30 35 47 39 +46x49: 35 41 38 46 35 44 +40x50: 65 50 44 45 39 65 +38x44: 21 24 41 22 32 27 +45x45: 43 53 46 53 61 53 +43x46: 45 48 45 50 55 59 +47x41: 42 52 44 45 47 64 +46x39: 42 33 27 38 29 26 +46x43: 63 49 49 46 44 55 +40x35: 34 31 38 48 29 36 +41x40: 27 29 33 23 24 32 +47x36: 32 21 34 35 32 26 +49x49: 48 41 47 40 35 44 +36x38: 28 26 26 24 20 20 +39x35: 33 42 25 29 45 33 +48x47: 54 68 52 57 63 51 +36x42: 43 38 47 32 39 37 +47x41: 33 40 35 37 23 27 +47x37: 63 45 39 38 42 42 +42x42: 31 60 47 49 42 41 +36x44: 54 48 30 33 39 39 +46x42: 31 34 38 27 46 33 +47x43: 58 47 62 49 49 50 +38x47: 51 37 39 53 48 46 +41x46: 48 57 51 58 43 34 +36x42: 31 34 46 42 40 41 +38x49: 56 48 41 42 47 52 +43x35: 23 28 29 28 30 15 +47x38: 36 41 47 47 53 50 +44x48: 59 56 54 62 55 40 +40x47: 38 30 28 41 32 26 +44x41: 46 60 37 43 45 44 +42x45: 42 38 27 32 37 34 +37x40: 44 38 31 37 40 37 +39x50: 29 49 29 34 27 39 +41x35: 33 33 31 36 49 37 +43x38: 17 27 28 33 33 30 +47x38: 36 26 35 30 28 25 +43x50: 51 58 60 51 54 58 +42x41: 52 42 50 40 36 48 +41x41: 30 28 27 35 27 22 +45x36: 49 46 33 34 32 54 +38x37: 23 21 29 20 22 28 +42x42: 38 33 30 31 29 34 +50x45: 63 71 60 50 41 63 +42x37: 44 38 40 37 37 44 +40x41: 46 34 49 47 34 45 +38x38: 45 36 31 37 39 34 +40x38: 23 31 22 25 34 20 +49x44: 31 40 37 38 36 41 +38x50: 35 28 37 32 26 33 +38x38: 31 35 42 36 45 34 +42x48: 45 39 30 31 38 41 +36x46: 24 24 25 22 36 48 +45x48: 75 56 61 51 46 48 +42x37: 39 30 46 37 50 39 +44x42: 43 31 27 32 31 31 +40x39: 46 38 36 41 39 40 +39x47: 47 45 46 49 51 44 +45x47: 37 47 33 38 33 37 +37x42: 28 24 34 27 33 22 +39x40: 32 46 36 33 37 54 +41x50: 69 48 39 57 59 42 +46x48: 64 59 42 68 51 53 +47x44: 57 52 57 54 36 64 +47x47: 50 62 60 68 46 54 +38x44: 38 49 43 39 42 46 +49x42: 48 45 62 50 55 59 +37x38: 26 15 26 35 16 26 +35x42: 41 33 38 40 32 43 +47x48: 70 62 47 48 60 59 +39x39: 51 36 32 42 38 35 +46x35: 50 36 44 38 37 45 +43x37: 20 27 34 30 27 30 +39x47: 41 46 45 51 44 54 +36x49: 37 31 28 31 30 34 +48x36: 33 48 42 47 54 40 +43x38: 28 31 27 29 31 22 +38x38: 38 35 35 33 49 32 +40x43: 21 31 32 35 36 27 +41x36: 27 32 24 22 18 33 +48x49: 54 49 59 69 80 50 +44x41: 41 40 46 59 38 53 +49x49: 62 61 56 76 55 58 +37x48: 35 28 42 30 33 24 +48x39: 31 41 30 37 34 35 +41x44: 58 36 38 47 53 45 +44x50: 39 41 45 38 31 29 +50x38: 37 42 63 56 49 48 +44x40: 43 47 56 43 38 47 +39x50: 55 63 47 33 43 59 +45x36: 25 39 32 25 17 41 +42x48: 38 38 43 29 34 41 +46x35: 31 34 23 28 25 24 +43x35: 37 35 37 47 37 38 +45x45: 48 30 35 36 41 35 +42x38: 22 31 28 21 37 29 +48x47: 49 37 29 49 34 42 +42x41: 36 53 47 41 48 40 +35x38: 24 23 23 27 20 14 +41x37: 40 40 39 44 31 40 +42x37: 30 21 40 36 23 18 +41x42: 30 42 50 49 55 39 +36x41: 42 31 42 46 36 32 +43x38: 27 28 35 31 24 22 +37x41: 30 28 30 18 24 25 +45x38: 47 37 45 36 38 61 +48x42: 41 33 45 32 38 35 +37x39: 23 23 28 31 26 25 +49x36: 28 28 38 33 36 28 +37x48: 22 30 33 30 32 44 +50x47: 70 54 56 73 48 61 +46x42: 53 50 60 54 45 39 +48x49: 65 66 51 65 54 59 +36x40: 52 39 47 33 31 25 +45x43: 39 45 28 30 30 37 +35x42: 37 44 37 37 42 29 +40x43: 34 34 25 31 26 31 +45x43: 43 36 35 36 23 37 +47x37: 51 42 42 45 42 46 +42x44: 25 37 21 41 39 32 +43x49: 47 67 59 59 45 48 +39x50: 41 33 35 31 32 36 +39x39: 28 24 27 30 34 26 +36x42: 38 35 40 34 47 39 +43x37: 26 29 24 25 35 28 +43x46: 49 53 56 45 55 48 +39x39: 16 30 29 29 37 28 +40x39: 24 31 27 24 20 42 +38x44: 39 33 54 45 39 50 +46x48: 48 53 71 57 55 59 +46x47: 66 70 57 38 55 49 +49x42: 52 48 57 49 60 52 +45x44: 54 44 49 56 57 45 +41x35: 47 33 35 39 36 32 +47x44: 45 53 55 60 58 47 +47x35: 18 26 27 38 33 23 +45x37: 34 50 53 35 44 42 +37x40: 42 44 29 43 30 38 +36x35: 38 37 33 29 33 25 +38x44: 36 53 41 46 33 47 +40x40: 42 43 43 32 44 43 +41x43: 28 32 29 23 33 36 +45x50: 53 58 59 63 66 47 +44x46: 46 49 53 49 55 59 +41x35: 41 28 45 38 38 34 +43x47: 37 41 36 31 33 31 +46x44: 44 63 40 54 56 50 +46x41: 57 53 43 33 52 52 +38x47: 46 36 42 54 52 44 +42x47: 31 37 41 29 32 40 +36x35: 21 30 22 17 21 20 +47x49: 67 54 67 61 58 51 +39x44: 48 50 44 48 36 39 +49x38: 30 34 38 28 30 32 +49x38: 52 54 47 50 46 38 +44x48: 49 66 63 52 52 45 +45x39: 46 43 40 52 40 48 +40x48: 27 41 33 37 33 36 +37x44: 30 29 27 31 23 28 +44x40: 36 48 35 46 53 49 +41x36: 31 39 43 42 41 32 +42x46: 47 43 46 52 61 47 +42x36: 38 49 32 39 39 34 +42x38: 46 25 36 43 52 43 +42x46: 48 54 35 37 66 53 +39x42: 32 35 33 27 31 23 +43x50: 54 52 52 72 46 54 +47x36: 23 37 31 29 30 29 +36x45: 32 43 52 28 57 39 +50x40: 40 57 54 50 64 42 +43x46: 33 37 36 30 35 39 +49x43: 47 28 38 44 25 41 +38x38: 30 33 21 47 37 49 +43x36: 45 40 42 40 39 34 +44x41: 29 35 38 17 36 26 +50x40: 33 32 24 42 31 45 +43x40: 28 26 34 35 30 29 +45x40: 47 49 48 43 37 54 +45x47: 65 58 53 49 43 59 +41x46: 62 54 47 43 53 33 +47x41: 63 47 68 45 39 42 +38x46: 49 40 42 54 37 47 +47x39: 33 32 33 35 30 32 +45x38: 29 31 32 33 31 23 +40x42: 40 36 49 34 41 60 +50x35: 39 41 49 42 41 58 +44x38: 48 45 49 48 38 32 +44x40: 47 43 47 44 53 38 +46x46: 57 53 54 50 60 52 +50x45: 39 37 37 39 53 35 +48x45: 59 44 59 69 45 58 +47x46: 57 63 55 57 49 52 +48x38: 52 48 52 53 30 48 +43x37: 46 43 34 31 48 42 +40x49: 49 49 45 48 47 62 +46x48: 65 69 60 54 60 34 +43x38: 26 27 26 21 28 39 +36x44: 35 36 44 43 38 48 +41x42: 32 47 63 40 31 56 +36x45: 36 47 39 48 41 37 +48x39: 43 38 38 25 30 33 +48x36: 47 44 43 47 41 44 +37x46: 51 36 39 35 52 49 +35x43: 16 23 36 28 23 27 +36x46: 39 47 58 30 45 40 +44x35: 34 38 34 44 35 50 +44x37: 28 43 43 37 52 46 +38x40: 19 22 28 27 27 32 +36x44: 29 25 35 30 31 18 +40x47: 57 56 52 35 54 38 +35x49: 36 28 25 24 33 29 +35x42: 38 37 33 41 41 35 +48x49: 56 60 62 48 68 68 +42x50: 31 36 51 41 32 32 +47x36: 25 32 36 29 29 28 +50x36: 34 23 42 30 30 32 +45x37: 35 18 29 32 36 30 +43x43: 37 29 24 32 38 36 +42x42: 26 24 28 40 41 36 +47x37: 57 42 43 44 43 40 +41x40: 53 42 38 50 32 38 +37x37: 35 32 43 29 39 35 +48x45: 32 36 51 41 34 46 +47x38: 52 45 46 41 52 40 +40x38: 16 29 19 29 34 28 +42x40: 37 24 28 25 38 30 +47x46: 59 46 50 54 62 61 +38x35: 27 31 45 35 30 39 +47x39: 47 41 36 58 47 50 +50x40: 53 49 57 44 53 54 +37x47: 25 23 31 38 36 26 +37x42: 35 46 44 40 37 38 +49x46: 68 49 74 53 48 61 +38x48: 30 39 34 21 31 37 +47x48: 40 44 38 38 43 37 +49x48: 33 41 54 47 42 38 +42x49: 32 31 38 42 41 39 +35x47: 49 56 38 31 33 46 +39x47: 42 49 59 47 40 48 +35x41: 37 31 44 28 43 40 +47x39: 44 44 62 30 53 53 +47x41: 43 44 50 67 46 46 +43x44: 28 30 29 39 32 37 +43x48: 55 62 66 52 41 46 +49x41: 26 36 40 45 33 27 +43x50: 45 66 70 59 52 42 +40x39: 47 42 32 41 44 33 +44x37: 40 25 23 26 25 29 +43x46: 36 55 56 72 37 48 +48x47: 47 57 59 59 63 61 +42x49: 52 58 50 59 46 51 +42x37: 37 37 47 38 44 38 +35x39: 41 35 28 38 29 38 +43x43: 35 27 34 38 33 29 +48x48: 51 60 61 62 57 63 +43x38: 32 29 28 29 25 25 +47x44: 39 25 43 35 31 36 +44x50: 28 26 43 41 42 43 +42x43: 28 32 32 37 38 29 +48x44: 69 57 49 48 58 45 +36x39: 37 29 41 38 25 48 +40x37: 30 30 25 29 22 19 +39x39: 34 25 32 27 25 25 +43x36: 25 23 32 26 32 30 +50x36: 52 53 50 43 44 37 +48x44: 41 32 45 47 37 21 +40x47: 32 34 37 28 30 33 +41x36: 42 38 48 49 38 16 +45x39: 32 43 31 25 32 31 +41x49: 42 36 32 36 29 33 +36x41: 36 43 37 35 35 41 +46x42: 44 48 64 50 54 41 +37x44: 31 32 26 26 34 18 +48x40: 58 50 39 46 45 56 +50x48: 69 69 60 53 57 62 +39x46: 34 38 30 32 31 29 +43x50: 46 63 59 57 50 56 +50x41: 44 29 40 27 33 34 +36x35: 17 26 20 18 28 22 +44x40: 54 34 40 51 45 47 +46x45: 30 42 46 32 39 35 +43x39: 30 27 26 26 29 43 +47x43: 41 58 50 52 60 48 +38x39: 31 23 24 23 30 25 +35x38: 26 39 38 37 29 36 +36x42: 33 37 38 40 39 45 +40x44: 28 53 39 42 54 51 +40x44: 35 31 24 31 28 33 +37x46: 34 31 27 23 27 38 +50x41: 45 43 47 47 57 74 +37x44: 46 48 34 36 42 43 +38x39: 25 50 33 41 32 44 +47x42: 31 48 35 30 29 37 +42x35: 29 19 29 35 22 20 +44x44: 33 33 33 31 36 29 +39x35: 28 21 24 25 22 23 +38x45: 28 29 33 25 32 32 +46x49: 57 48 62 60 64 57 +40x46: 21 41 34 25 36 38 +50x46: 48 32 44 34 38 44 +46x42: 47 59 45 47 52 46 +46x43: 36 37 40 37 29 31 +41x40: 25 35 30 26 24 29 +49x43: 48 64 38 60 48 61 +39x45: 42 49 56 44 40 42 +50x48: 70 68 59 57 60 56 +41x47: 41 50 51 55 46 53 +45x43: 48 57 50 49 48 46 +35x36: 31 30 46 31 31 29 +40x40: 31 38 44 41 52 40 +44x45: 41 58 46 60 46 51 +44x37: 36 35 49 48 40 44 +46x41: 46 43 44 51 52 53 +43x49: 40 42 35 37 41 28 +49x35: 36 35 28 32 21 23 +38x37: 47 33 28 44 28 36 +49x42: 61 56 49 54 41 56 +38x43: 43 45 46 37 42 40 +44x44: 50 50 42 62 54 38 +41x39: 27 31 32 21 29 29 +39x39: 21 33 36 33 22 24 +42x38: 37 31 50 50 33 47 +41x37: 41 37 42 43 35 37 +35x47: 38 48 46 36 46 40 +43x48: 44 33 30 32 37 47 +50x49: 71 59 58 63 64 62 +41x39: 44 38 39 42 32 51 +40x44: 37 39 26 27 27 26 +46x48: 33 43 40 42 46 36 +42x50: 39 27 41 34 50 33 +47x48: 66 57 52 58 57 57 +44x35: 31 14 22 33 31 22 +44x35: 38 40 43 33 43 41 +48x48: 39 42 55 30 53 37 +38x40: 27 29 24 27 22 27 +38x45: 48 43 37 45 46 43 +35x47: 47 47 60 41 33 31 +36x50: 44 41 50 52 41 50 +48x41: 51 52 53 41 54 53 +44x47: 38 53 55 59 59 53 +48x38: 38 27 22 44 40 21 +41x40: 41 41 34 49 39 46 +44x37: 29 34 21 25 26 32 +43x44: 28 33 39 30 34 31 +50x37: 44 59 49 49 33 51 +47x49: 41 69 62 55 70 56 +49x46: 37 38 45 40 45 34 +37x35: 29 26 19 23 13 21 +37x50: 31 35 27 43 36 20 +49x44: 41 57 59 52 65 57 +45x49: 54 62 63 48 55 59 +41x40: 36 46 43 51 39 37 +48x50: 41 35 46 45 32 57 +38x45: 33 25 23 32 33 33 +43x45: 44 66 49 51 46 41 +50x37: 38 25 32 38 26 32 +39x45: 50 38 28 53 44 53 +43x38: 36 25 29 24 27 27 +50x40: 43 49 63 53 47 55 +42x40: 26 29 29 31 37 29 +35x46: 37 27 15 29 31 26 +47x50: 57 65 59 53 62 65 +47x37: 30 28 22 27 42 31 +45x44: 45 39 51 69 54 46 +39x49: 33 42 34 28 38 32 +44x48: 30 42 32 41 37 41 +45x46: 42 48 49 64 52 61 +47x37: 31 29 28 24 33 35 +49x43: 41 42 34 39 30 38 +37x39: 27 18 30 33 24 24 +45x41: 45 45 45 46 46 56 +45x50: 40 45 46 35 31 43 +38x48: 48 40 33 41 60 55 +45x49: 43 41 35 34 38 48 +50x42: 39 53 63 51 60 58 +40x47: 59 52 41 49 40 48 +38x40: 25 29 25 27 26 23 +47x48: 47 47 41 35 37 32 +37x36: 16 30 20 25 32 20 +46x46: 59 53 67 41 64 46 +36x48: 44 40 44 43 62 33 +50x40: 45 43 55 44 61 60 +49x46: 54 63 67 56 52 57 +35x48: 31 48 39 50 44 44 +39x38: 44 33 41 39 36 37 +49x44: 54 59 46 60 50 60 +44x39: 27 33 37 33 29 23 +40x44: 23 34 27 36 34 27 +36x41: 24 27 29 22 31 23 +47x40: 52 44 52 58 48 37 +38x45: 33 34 34 23 35 20 +39x36: 34 23 29 24 24 21 +35x49: 39 30 25 22 28 32 +43x50: 50 65 61 46 53 57 +49x43: 35 39 38 37 40 35 +37x44: 27 30 30 27 21 33 +41x41: 20 24 35 32 23 35 +45x45: 30 36 41 40 42 35 +40x49: 35 34 24 35 50 29 +48x43: 38 41 38 40 30 37 +46x43: 53 47 40 69 48 45 +42x44: 53 48 49 39 58 39 +37x44: 28 29 39 23 27 22 +39x47: 57 51 62 46 34 38 +40x36: 36 42 34 29 41 39 +42x38: 35 26 29 21 30 26 +42x47: 31 39 41 35 27 36 +40x35: 32 35 29 46 35 36 +50x40: 42 25 37 35 35 34 +48x43: 40 31 45 28 37 42 +50x49: 44 39 45 41 47 39 +40x45: 33 23 31 32 42 34 +44x41: 31 28 25 28 35 35 +48x50: 66 56 61 60 61 66 +48x42: 44 49 43 51 57 63 +42x50: 69 63 59 45 49 42 +49x40: 47 52 52 42 57 52 +42x41: 19 27 34 35 36 31 +38x39: 31 37 40 46 36 38 +44x36: 41 31 51 41 42 41 +40x44: 37 28 23 27 29 37 +50x49: 38 42 41 48 40 47 +48x38: 31 46 45 24 22 24 +44x46: 44 34 35 35 28 34 +49x38: 34 57 45 56 50 42 +47x46: 65 57 51 54 59 47 +41x49: 42 38 30 36 26 35 +40x45: 49 60 47 40 35 47 +45x43: 33 31 36 35 43 32 +50x43: 60 53 52 56 55 55 +38x41: 26 19 28 34 22 27 +35x42: 21 14 20 33 39 27 +48x43: 54 53 46 58 56 49 +39x40: 42 38 41 43 35 42 +36x35: 31 34 26 38 35 28 +36x36: 28 27 48 41 28 31 +37x40: 35 42 33 40 32 44 +35x36: 24 18 28 24 21 17 +43x41: 47 42 36 46 43 55 +46x39: 50 34 43 54 39 56 +40x35: 32 28 21 28 17 17 +46x36: 54 36 44 37 44 42 +37x47: 35 49 47 49 33 54 +45x35: 39 37 56 42 39 34 +35x41: 20 29 24 25 19 25 +36x48: 56 37 52 46 34 45 +44x47: 50 50 56 55 53 55 +41x42: 45 48 50 30 46 48 +35x46: 32 42 53 30 43 50 +38x36: 35 43 29 36 27 39 +38x41: 20 27 22 33 23 30 +41x49: 53 48 56 41 59 54 +37x40: 30 37 39 36 37 48 +38x42: 53 49 29 33 43 37 +43x40: 52 40 37 49 45 41 +38x37: 31 39 36 32 37 41 +37x37: 21 27 21 24 27 24 +50x41: 33 20 38 35 34 47 +42x49: 47 61 63 47 51 50 +39x41: 43 43 36 39 39 45 +42x38: 48 27 41 39 39 53 +46x36: 32 29 40 25 31 22 +35x46: 35 21 29 24 33 23 +35x41: 29 33 40 33 43 43 +37x36: 20 20 32 29 17 25 +44x39: 42 53 48 57 28 37 +44x46: 40 35 46 25 36 28 +45x35: 37 43 40 50 34 38 +47x49: 43 48 35 33 35 45 +50x42: 52 61 60 51 45 56 +43x36: 38 38 46 33 37 48 +48x38: 46 44 44 53 45 48 +44x35: 27 26 24 27 24 26 +36x49: 33 37 36 25 24 37 +48x47: 28 35 38 50 37 52 +40x49: 33 36 33 40 36 29 +40x50: 42 34 30 33 32 37 +40x36: 24 21 29 31 21 30 +43x44: 38 34 29 34 26 34 +40x45: 49 45 47 43 40 54 +46x44: 48 60 41 54 41 64 +41x44: 28 34 30 31 29 29 +48x48: 62 62 66 55 62 50 +37x50: 37 31 37 29 21 36 +35x38: 36 32 33 30 36 38 +41x38: 46 47 40 40 34 34 +46x50: 51 54 62 53 64 70 +38x48: 34 27 33 34 32 31 +42x36: 42 26 55 36 35 44 +35x48: 31 32 26 26 33 27 +35x38: 22 23 24 15 26 22 +41x39: 40 31 41 46 43 45 +48x44: 53 53 54 49 61 55 +44x36: 46 36 35 41 39 46 +46x40: 23 28 41 31 39 33 +39x45: 26 42 31 22 34 39 +42x42: 33 66 53 40 38 42 +37x50: 55 43 44 48 37 58 +47x42: 36 25 42 34 37 36 +43x47: 51 55 55 45 55 51 +47x46: 33 39 29 31 39 53 +49x36: 53 54 49 49 35 34 +45x43: 33 33 32 33 39 40 +40x36: 27 26 19 30 21 32 +43x39: 27 25 31 31 30 37 +35x42: 28 19 34 26 21 25 +44x45: 48 52 63 44 45 56 +42x35: 32 42 29 35 49 36 +40x40: 24 27 28 28 31 31 +43x42: 31 38 24 39 31 33 +35x41: 43 34 33 30 40 41 +45x41: 41 42 60 52 53 39 +44x49: 35 35 28 32 49 44 +38x42: 35 25 32 32 23 21 +47x40: 44 49 42 52 53 47 +40x38: 30 24 20 31 33 18 +46x43: 52 54 52 41 59 47 +35x39: 35 33 34 42 35 31 +39x46: 49 42 50 51 40 46 +41x46: 49 36 57 54 40 57 +35x47: 52 38 47 44 39 36 +37x45: 31 22 30 32 39 26 +48x39: 34 68 50 43 49 43 +49x38: 43 61 47 39 55 41 +47x42: 50 54 41 51 60 45 +36x45: 28 31 26 32 26 37 +42x46: 53 52 43 51 53 44 +36x38: 26 27 22 24 18 27 +50x37: 31 35 20 37 37 31 +44x44: 47 48 44 44 58 55 +36x50: 40 29 28 28 37 30 +48x39: 52 51 42 50 35 57 +48x48: 64 59 51 52 67 60 +39x47: 49 49 45 45 38 56 +46x46: 36 51 31 37 32 37 +47x43: 23 38 38 27 42 42 +38x35: 35 36 30 42 34 27 +39x50: 22 38 35 33 36 44 +41x49: 49 28 36 29 32 34 +40x40: 31 31 28 27 28 23 +44x48: 56 55 63 48 46 60 +35x39: 26 25 27 26 18 20 +42x48: 35 35 40 37 38 38 +45x40: 37 45 50 45 33 67 +43x37: 42 47 37 37 45 36 +45x41: 50 39 49 51 43 53 +47x50: 59 64 47 56 71 61 +42x38: 49 44 44 46 33 32 +41x41: 27 52 30 47 49 48 +41x36: 39 27 33 36 41 50 +46x36: 36 30 33 31 17 32 +43x35: 39 29 35 35 48 45 +38x36: 25 25 30 17 23 24 +39x43: 39 31 18 33 31 29 +38x44: 48 37 42 47 47 37 +37x38: 29 35 10 20 28 21 +35x41: 35 43 34 38 33 37 +39x36: 28 46 29 35 36 39 +46x44: 49 57 65 45 42 57 +43x35: 32 43 42 37 41 37 +35x39: 34 27 31 41 40 36 +37x37: 26 23 28 25 21 21 +35x47: 36 43 34 42 46 49 +43x36: 36 41 44 44 39 35 +46x38: 26 36 31 28 31 28 +42x44: 49 52 62 39 47 40 +50x37: 24 44 21 26 40 36 +45x42: 53 51 36 49 47 52 +44x36: 23 29 35 29 26 25 +36x50: 43 50 40 46 50 46 +37x47: 31 30 25 29 28 36 +49x46: 54 35 43 42 35 31 +40x36: 23 27 25 26 23 32 +49x48: 42 61 69 70 64 56 +38x49: 61 47 45 47 47 41 +47x40: 27 25 29 34 40 39 +35x38: 24 30 17 21 22 18 +42x39: 48 38 38 50 49 29 +48x37: 39 40 31 26 34 21 +47x50: 52 33 32 42 32 49 +50x42: 53 59 49 48 50 63 +45x44: 22 45 37 27 42 36 +39x39: 35 40 37 44 33 44 +44x49: 63 50 48 59 52 59 +35x48: 33 24 26 29 33 31 +42x41: 27 32 27 33 33 29 +48x41: 33 26 40 33 44 32 +39x45: 37 46 38 46 56 44 +41x42: 68 36 35 46 49 32 +50x40: 40 37 28 42 27 34 +43x46: 36 53 56 43 63 53 +44x41: 28 36 28 22 41 27 +50x35: 25 21 42 32 27 29 +41x48: 56 50 55 55 41 48 +39x48: 57 39 49 45 48 52 +36x36: 18 25 19 28 32 21 +40x40: 49 36 46 38 36 44 +43x37: 33 43 44 46 40 39 +38x38: 41 37 48 28 36 36 +42x40: 50 33 34 43 58 39 +45x41: 20 30 41 39 33 31 +39x40: 37 51 40 32 44 36 +37x39: 37 32 32 43 38 39 +36x46: 33 23 34 20 31 38 +47x48: 42 46 33 40 45 33 +41x44: 31 30 27 26 34 33 +47x43: 60 49 54 43 59 48 +39x36: 43 35 49 28 36 30 +50x43: 39 27 39 41 43 35 +50x43: 58 50 46 62 61 52 +45x38: 50 34 53 45 48 37 +44x40: 39 28 31 24 24 35 +46x44: 53 57 59 46 56 43 +44x35: 35 46 41 38 44 33 +42x44: 47 49 56 45 41 49 +35x39: 26 27 49 45 29 37 +36x45: 36 47 43 46 45 32 +46x35: 33 24 22 36 32 18 +39x45: 35 45 49 50 43 48 +36x48: 48 46 46 39 44 44 +43x45: 54 43 40 59 48 52 +47x35: 34 42 41 51 42 42 +45x41: 34 61 47 64 44 32 +39x42: 21 41 35 26 23 35 +38x50: 42 56 60 48 38 51 +38x45: 44 49 42 40 50 38 +45x43: 32 49 48 48 70 48 +46x44: 24 25 42 47 35 37 +43x36: 33 32 45 50 40 39 +47x45: 41 36 31 39 34 43 +49x43: 40 36 40 39 35 33 +38x35: 42 37 34 21 34 38 +39x50: 31 35 35 35 35 36 +48x48: 54 53 66 56 63 64 +43x37: 37 43 36 42 46 39 +37x46: 31 28 26 34 31 29 +43x35: 29 26 24 28 25 22 +45x41: 36 39 28 27 31 33 +48x46: 38 32 52 30 41 46 +42x47: 45 60 47 51 52 47 +49x36: 46 45 57 41 37 49 +41x38: 27 30 25 23 25 26 +46x46: 63 51 36 63 58 51 +41x39: 27 23 22 29 29 39 +47x38: 46 48 52 39 47 45 +43x38: 36 48 43 44 43 37 +37x39: 30 26 21 31 29 18 +47x42: 53 64 42 59 35 49 +50x36: 37 28 26 36 36 29 +44x43: 37 37 19 42 26 34 +38x49: 57 45 47 46 43 50 +38x39: 36 36 41 35 37 44 +38x38: 37 35 42 37 32 41 +36x37: 45 37 32 36 28 28 +37x39: 34 35 37 38 48 30 +37x47: 35 29 24 33 27 31 +47x35: 25 23 26 34 31 26 +35x44: 22 21 22 26 40 23 +38x43: 40 31 51 43 39 50 +46x45: 32 33 33 38 45 43 +38x49: 48 38 52 47 47 56 +45x36: 44 44 35 26 47 52 +42x37: 33 25 21 27 33 28 +45x37: 45 42 44 39 52 35 +46x38: 36 53 52 41 36 52 +45x45: 58 38 49 63 52 52 +47x37: 28 38 30 25 25 34 +39x40: 57 36 37 39 43 30 +45x46: 61 54 47 50 43 63 +41x42: 25 36 29 26 29 36 +49x50: 54 39 46 42 37 38 +46x38: 57 38 66 47 32 37 +43x35: 28 22 21 22 29 31 +45x47: 40 35 31 38 33 47 +49x47: 56 57 58 68 57 58 +42x48: 34 29 35 43 40 42 +50x39: 55 52 47 53 47 46 +50x50: 45 47 37 46 38 42 +36x40: 25 24 28 25 27 27 +48x40: 56 44 40 43 61 50 +48x39: 26 36 38 27 42 38 +48x45: 33 29 30 52 48 48 +48x41: 34 26 39 32 38 38 +40x44: 48 46 50 40 41 48 +43x47: 26 35 39 38 37 34 +43x38: 44 21 34 21 21 26 +35x38: 22 21 16 29 22 21 +45x39: 31 28 34 28 48 26 +43x39: 35 33 21 32 31 29 +40x44: 35 35 38 19 24 31 +37x50: 50 46 43 55 39 51 +41x44: 33 36 34 26 27 25 +42x48: 49 44 62 56 46 56 +40x45: 40 44 52 45 51 46 +47x49: 43 33 39 45 39 40 +48x39: 47 43 61 42 49 50 +47x39: 36 25 29 38 30 36 +48x40: 59 63 42 40 38 53 +46x44: 49 50 51 59 54 48 +46x44: 45 56 53 51 51 55 +46x39: 33 24 34 43 24 37 +36x50: 40 50 52 53 42 41 +47x48: 71 49 71 52 51 59 +48x42: 38 44 44 22 34 41 +39x46: 30 33 28 46 26 32 +37x40: 40 39 37 37 33 42 +44x44: 43 29 44 37 23 20 +41x49: 56 52 48 51 59 43 +43x43: 32 35 35 27 26 41 +36x37: 26 32 45 37 39 28 +44x50: 44 30 38 36 43 33 +47x48: 49 68 50 57 53 67 +38x47: 50 41 50 45 41 50 +48x36: 41 49 52 47 31 48 +42x48: 37 42 25 42 36 41 +35x50: 53 57 39 42 34 44 +50x35: 58 36 51 32 55 41 +42x35: 38 37 43 38 44 28 +44x39: 39 50 38 58 39 38 +38x43: 30 44 46 44 38 49 +36x40: 34 34 43 39 39 34 +36x38: 25 37 38 34 40 36 +47x35: 28 29 26 27 28 27 +43x37: 47 43 31 44 33 45 +39x45: 33 32 25 35 35 34 +46x49: 25 50 53 41 34 36 +41x38: 38 46 34 48 35 37 +39x43: 30 31 28 32 29 32 +40x35: 48 24 34 33 40 38 +45x48: 63 60 57 53 43 58 +47x46: 59 55 43 63 53 57 +41x39: 32 43 44 38 45 44 +41x48: 45 42 56 51 54 56 +43x47: 67 47 47 42 53 56 +35x40: 36 28 37 48 32 35 +48x37: 41 21 42 28 30 30 +40x35: 32 31 36 35 35 46 +42x35: 44 40 33 33 40 36 +38x48: 19 36 31 38 29 39 +48x35: 39 39 39 50 43 47 +47x39: 52 47 44 44 55 40 +48x45: 38 34 36 40 52 40 +43x40: 34 34 32 18 26 37 +40x43: 46 49 43 51 36 40 +35x48: 32 28 27 30 32 26 +48x48: 42 42 46 44 48 33 +47x46: 51 47 62 62 67 45 +36x40: 20 27 27 27 25 30 +40x48: 34 46 47 23 26 31 +41x41: 48 40 48 43 42 40 +48x47: 35 31 53 46 32 43 +42x38: 26 30 27 27 21 36 +38x46: 42 28 27 25 27 30 +36x38: 21 23 26 28 28 17 +47x37: 49 49 40 49 44 36 +48x44: 52 63 58 44 51 58 +37x45: 27 27 25 29 40 32 +46x37: 21 37 35 36 22 28 +38x43: 37 26 27 22 34 22 +41x39: 28 29 30 24 33 25 +49x37: 34 28 29 30 35 35 +39x40: 45 40 44 33 40 40 +45x38: 33 25 37 22 33 30 +44x37: 29 31 26 28 26 28 +44x47: 30 41 34 44 42 18 +39x36: 28 30 23 24 28 23 +37x46: 27 32 37 31 24 29 +43x45: 51 47 46 58 47 48 +48x41: 48 56 45 50 52 50 +36x41: 29 26 20 27 26 27 +44x35: 42 33 31 45 39 45 +44x42: 45 47 46 56 41 49 +48x46: 33 28 37 58 38 45 +48x41: 53 48 49 49 47 57 +40x47: 53 47 51 46 38 56 +48x49: 68 58 74 48 62 57 +47x47: 62 63 53 64 50 48 +47x37: 25 33 19 44 28 31 +50x37: 30 35 31 34 34 28 +47x37: 44 48 32 52 43 45 +49x40: 37 29 31 42 31 38 +39x42: 33 37 38 43 45 54 +39x38: 50 30 48 21 39 45 +46x50: 66 50 65 52 66 58 +43x37: 45 45 35 42 40 37 +44x37: 40 36 47 39 46 44 +48x49: 50 59 83 53 58 64 +44x45: 37 33 38 30 38 34 +45x39: 32 31 35 22 40 34 +36x48: 30 25 36 33 30 38 +48x38: 40 52 57 56 38 40 +46x36: 55 33 40 40 50 38 +50x36: 41 42 59 46 46 46 +41x50: 57 46 52 63 41 57 +35x48: 33 37 30 25 24 26 +42x36: 37 38 29 36 43 47 +42x44: 46 45 42 49 51 50 +38x38: 37 37 42 50 27 31 +44x37: 49 50 36 34 39 42 +35x38: 22 19 15 23 25 27 +40x38: 40 42 41 42 23 47 +43x37: 31 31 24 26 27 29 +45x43: 40 32 34 30 38 36 +49x36: 46 36 49 45 49 48 +43x35: 26 36 21 23 28 20 +38x37: 21 30 20 23 23 26 +46x35: 45 41 43 43 38 39 +45x43: 40 40 28 40 34 28 +42x49: 54 47 49 49 54 63 +35x47: 25 23 35 23 41 18 +38x44: 31 26 27 26 27 30 +41x43: 37 48 54 39 36 59 +46x42: 49 51 58 42 60 40 +39x39: 37 38 29 52 30 45 +43x49: 45 50 64 52 62 53 +38x37: 37 40 34 29 42 34 +50x39: 36 35 31 40 32 34 +42x36: 28 24 29 33 24 30 +39x47: 29 21 28 44 35 37 +50x49: 68 58 73 64 56 62 +42x39: 26 23 34 32 37 30 +47x37: 37 26 28 25 31 32 +44x45: 34 38 35 34 34 34 +40x40: 22 35 36 22 23 30 +42x36: 35 20 38 28 26 20 +46x38: 36 26 31 25 24 38 +39x37: 26 27 22 19 35 26 +47x38: 38 46 49 40 47 55 +39x41: 36 20 29 25 24 35 +43x39: 40 48 44 38 45 43 +50x49: 49 41 50 48 31 36 +44x41: 36 44 52 46 55 45 +35x45: 29 36 40 39 49 48 +38x35: 32 44 39 35 27 29 +50x42: 50 46 51 68 49 58 +48x44: 50 58 59 54 46 59 +44x36: 37 44 39 36 48 39 +48x46: 50 50 56 75 55 53 +38x35: 24 17 23 25 17 25 +36x49: 49 40 52 49 49 35 +48x36: 35 35 26 38 33 24 +44x46: 30 34 37 38 36 34 +46x41: 59 49 48 38 53 45 +42x45: 35 34 38 36 30 36 +42x47: 54 49 52 48 51 51 +40x40: 18 26 28 40 25 31 +39x43: 47 48 43 33 40 48 +48x35: 49 39 41 53 39 38 +47x45: 28 30 39 44 29 55 +41x35: 28 16 29 24 23 22 +46x45: 65 66 45 52 51 39 +37x39: 47 33 27 37 31 46 +43x44: 59 41 52 52 40 50 +49x47: 58 65 58 66 50 57 +41x48: 33 32 43 40 30 30 +50x38: 56 46 54 44 57 38 +45x39: 30 39 32 31 31 32 +44x41: 29 34 31 30 25 32 +44x49: 39 39 38 36 37 34 +42x44: 27 38 35 33 33 30 +46x47: 54 47 71 55 54 56 +49x40: 55 53 48 55 45 46 +39x39: 19 25 31 28 37 29 +40x38: 21 23 30 19 39 24 +45x45: 39 31 33 43 38 40 +49x46: 49 61 52 52 67 63 +45x45: 45 49 60 43 46 70 +43x38: 37 44 66 23 43 45 +49x48: 43 39 37 47 46 43 +46x49: 56 70 52 50 65 52 +45x37: 40 36 53 54 34 42 +43x50: 53 41 56 62 63 56 +50x45: 35 37 39 42 45 41 +49x37: 46 54 49 46 46 39 +41x46: 49 45 50 43 51 53 +45x35: 22 32 21 23 31 35 +47x44: 57 62 53 51 49 47 +39x45: 45 50 47 42 48 39 +42x36: 20 34 26 35 24 29 +49x41: 31 39 30 32 40 36 +41x41: 46 42 49 46 38 40 +42x45: 52 40 54 57 39 51 +37x39: 29 29 40 37 35 52 +40x35: 32 40 35 37 40 31 +42x48: 49 46 51 50 55 59 +40x48: 50 51 47 41 46 60 +45x46: 49 30 34 41 36 34 +38x39: 34 42 32 40 40 38 +46x35: 30 37 40 41 43 55 +45x42: 58 50 47 49 43 45 +48x35: 47 47 46 39 44 37 +49x42: 50 61 58 50 59 40 +49x37: 40 41 52 49 49 49 +48x47: 65 59 46 57 59 59 +35x35: 26 17 15 28 13 22 +42x49: 34 37 41 32 36 43 +44x43: 32 39 30 32 30 33 +43x47: 50 57 49 56 50 48 +43x46: 52 49 59 50 54 43 +44x41: 30 20 30 31 36 35 +49x50: 56 69 58 64 72 56 +43x44: 27 34 32 29 43 31 +43x50: 49 51 54 56 62 58 +49x37: 48 45 45 50 44 47 +46x36: 50 48 45 39 36 39 +46x50: 36 30 46 42 44 41 +42x46: 33 40 42 29 31 35 +50x36: 45 52 56 47 37 43 +43x36: 28 30 26 29 27 27 +36x47: 44 34 48 49 44 43 +42x47: 38 22 37 32 35 46 From 393f80f314c5b99afc3c567314b8df96d3d963bd Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 14:48:57 +0000 Subject: [PATCH 06/10] WIP: implement part 1 --- src/days/day12.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/days/day12.zig b/src/days/day12.zig index d940d18..17f6c7e 100644 --- a/src/days/day12.zig +++ b/src/days/day12.zig @@ -169,5 +169,50 @@ const Region = struct { } } } + + pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion { + return try .init(allocator, self.width, self.height); + } +}; + +const EmptyRegion = struct { + grid: [][]bool, + filled_spaces: usize, + + allocator: std.mem.Allocator, + + const Self = @This(); + + pub fn init(allocator: std.mem.Allocator, width: u8, height: u8) !Self { + const h = try allocator.alloc([]bool, height); + for (0..height) |i| { + const w = try allocator.alloc(u8, width); + @memset(w, false); + h[i] = w; + } + return .{ + .grid = h, + .filled_spaces = 0, + .allocator = allocator, + }; + } + + pub fn deinit(self: Self) void { + for (self.grid) |row| { + self.allocator.free(row); + } + self.allocator.free(self.grid); + } + + pub fn fits(self: Self, present: Present) bool { + std.debug.assert(self.grid.len > 0); + const size = self.grid.len * self.grid[0].len; + if ((size - self.filled_spaces) < present.shape.count()) { + return false; + } + + // TODO: Implementation + return false; + } }; From bc89b177a26f4f99825629c83fb20b8b80a947a7 Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 14:55:11 +0000 Subject: [PATCH 07/10] Add README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4e39aa0 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Advent of Code 2025 + +| Day | Part 1 | Part 2 | +| --- | ------ | ------ | +| 1 | [x] | [x] | +| 2 | [x] | [x] | +| 3 | [x] | [x] | +| 4 | [x] | [x] | +| 5 | [x] | [x] | +| 6 | [x] | [x] | +| 7 | [x] | [x] | +| 8 | [ ] | [ ] | +| 9 | [x] | [x] | +| 10 | [x] | [ ] | +| 11 | [x] | [x] | +| 12 | [ ] | [ ] | From f088a5a21a5da063947e66089213ba0aa220d8ff Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 16:35:12 +0000 Subject: [PATCH 08/10] WIP: implement part 1 --- src/days/day12.zig | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/days/day12.zig b/src/days/day12.zig index 17f6c7e..26d586b 100644 --- a/src/days/day12.zig +++ b/src/days/day12.zig @@ -111,13 +111,26 @@ pub fn run(allocator: std.mem.Allocator) !void { } } - for (presents.items, 0..) |present, i| { - std.debug.print("{d}:\n{f}\n\n", .{i, present}); - } + var accumulator: usize = 0; for (regions.items) |region| { - std.debug.print("{f}\n", .{region}); + var area_needed: usize = 0; + for (region.required_presents, 0..) |amount, i| { + area_needed += amount * presents.items[i].area(); + } + if (area_needed < region.area()) { + std.debug.print("{f}\nfits\n", .{region}); + accumulator += 1; + } } + + var buffer: [8]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&buffer); + const stdout = &stdout_writer.interface; + + try stdout.print("{d}\n", .{accumulator}); + + try stdout.flush(); } const Present = struct { @@ -147,6 +160,10 @@ const Present = struct { const index = (y * Width) + x; return self.shape.isSet(index); } + + pub fn area(self: Self) usize { + return self.shape.count(); + } }; const Region = struct { @@ -173,6 +190,10 @@ const Region = struct { pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion { return try .init(allocator, self.width, self.height); } + + pub fn area(self: Self) usize { + return self.width * self.height; + } }; const EmptyRegion = struct { From 0633ee80a9450b8a6c6cd2c93b122cef7b2a5f86 Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 22:07:05 +0000 Subject: [PATCH 09/10] Finish day12, part 1 This feels like cheating --- src/days/day12.zig | 81 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/days/day12.zig b/src/days/day12.zig index 26d586b..354fe56 100644 --- a/src/days/day12.zig +++ b/src/days/day12.zig @@ -3,42 +3,42 @@ const std = @import("std"); pub const title = "Day 12: Christmas Tree Farm"; pub fn run(allocator: std.mem.Allocator) !void { - //const input = @embedFile("./input/day12.txt"); - const input = - \\0: - \\### - \\##. - \\##. - \\ - \\1: - \\### - \\##. - \\.## - \\ - \\2: - \\.## - \\### - \\##. - \\ - \\3: - \\##. - \\### - \\##. - \\ - \\4: - \\### - \\#.. - \\### - \\ - \\5: - \\### - \\.#. - \\### - \\ - \\4x4: 0 0 0 0 2 0 - \\12x5: 1 0 1 0 2 2 - \\12x5: 1 0 1 0 3 2 - ; + const input = @embedFile("./input/day12.txt"); + //const input = + // \\0: + // \\### + // \\##. + // \\##. + // \\ + // \\1: + // \\### + // \\##. + // \\.## + // \\ + // \\2: + // \\.## + // \\### + // \\##. + // \\ + // \\3: + // \\##. + // \\### + // \\##. + // \\ + // \\4: + // \\### + // \\#.. + // \\### + // \\ + // \\5: + // \\### + // \\.#. + // \\### + // \\ + // \\4x4: 0 0 0 0 2 0 + // \\12x5: 1 0 1 0 2 2 + // \\12x5: 1 0 1 0 3 2 + // ; var lines = std.mem.tokenizeScalar(u8, input, '\n'); @@ -69,8 +69,8 @@ pub fn run(allocator: std.mem.Allocator) !void { if (semicolon_pos != 0) { if (x_pos) |p| { // region - const width = try std.fmt.parseUnsigned(u8, line[0..p], 10); - const height = try std.fmt.parseUnsigned(u8, line[p + 1..semicolon_pos], 10); + const width = try std.fmt.parseUnsigned(usize, line[0..p], 10); + const height = try std.fmt.parseUnsigned(usize, line[p + 1..semicolon_pos], 10); var required_presents: std.ArrayList(u8) = .empty; defer required_presents.deinit(allocator); @@ -114,6 +114,7 @@ pub fn run(allocator: std.mem.Allocator) !void { var accumulator: usize = 0; for (regions.items) |region| { + std.debug.print("{f}\n", .{region}); var area_needed: usize = 0; for (region.required_presents, 0..) |amount, i| { area_needed += amount * presents.items[i].area(); @@ -167,8 +168,8 @@ const Present = struct { }; const Region = struct { - width: u8, - height: u8, + width: usize, + height: usize, required_presents: []u8, const Self = @This(); From b3f8ab19ffc911be4be485de0af2ace55a7ab7bc Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 22:08:19 +0000 Subject: [PATCH 10/10] Add hyperfine to nix env --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index e668d05..6649f39 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,7 @@ nativeBuildInputs = with pkgs; [ zig zls + hyperfine ]; buildInputs = with pkgs; [];