├── 2015 ├── day1.go ├── day1.hs ├── day10.go ├── day10.hs ├── day10 │ ├── day10.go │ └── day10_amd64.s ├── day11.go ├── day11.hs ├── day12.go ├── day13.go ├── day14.go ├── day15.go ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.hs ├── day25.go ├── day25.hs ├── day3.go ├── day4.go ├── day5.go ├── day6.go ├── day7-gen.go ├── day7.go ├── day7 │ ├── a │ │ └── a.go │ ├── aa │ │ └── aa.go │ ├── ab │ │ └── ab.go │ ├── ac │ │ └── ac.go │ ├── ad │ │ └── ad.go │ ├── ae │ │ └── ae.go │ ├── af │ │ └── af.go │ ├── ag │ │ └── ag.go │ ├── ah │ │ └── ah.go │ ├── ai │ │ └── ai.go │ ├── aj │ │ └── aj.go │ ├── ak │ │ └── ak.go │ ├── al │ │ └── al.go │ ├── am │ │ └── am.go │ ├── an │ │ └── an.go │ ├── ao │ │ └── ao.go │ ├── ap │ │ └── ap.go │ ├── aq │ │ └── aq.go │ ├── ar │ │ └── ar.go │ ├── as │ │ └── as.go │ ├── at │ │ └── at.go │ ├── au │ │ └── au.go │ ├── av │ │ └── av.go │ ├── aw │ │ └── aw.go │ ├── ax │ │ └── ax.go │ ├── ay │ │ └── ay.go │ ├── az │ │ └── az.go │ ├── b │ │ └── b.go │ ├── ba │ │ └── ba.go │ ├── bb │ │ └── bb.go │ ├── bc │ │ └── bc.go │ ├── bd │ │ └── bd.go │ ├── be │ │ └── be.go │ ├── bf │ │ └── bf.go │ ├── bg │ │ └── bg.go │ ├── bh │ │ └── bh.go │ ├── bi │ │ └── bi.go │ ├── bj │ │ └── bj.go │ ├── bk │ │ └── bk.go │ ├── bl │ │ └── bl.go │ ├── bm │ │ └── bm.go │ ├── bn │ │ └── bn.go │ ├── bo │ │ └── bo.go │ ├── bp │ │ └── bp.go │ ├── bq │ │ └── bq.go │ ├── br │ │ └── br.go │ ├── bs │ │ └── bs.go │ ├── bt │ │ └── bt.go │ ├── bu │ │ └── bu.go │ ├── bv │ │ └── bv.go │ ├── bw │ │ └── bw.go │ ├── bx │ │ └── bx.go │ ├── by │ │ └── by.go │ ├── bz │ │ └── bz.go │ ├── c │ │ └── c.go │ ├── ca │ │ └── ca.go │ ├── cb │ │ └── cb.go │ ├── cc │ │ └── cc.go │ ├── cd │ │ └── cd.go │ ├── ce │ │ └── ce.go │ ├── cf │ │ └── cf.go │ ├── cg │ │ └── cg.go │ ├── ch │ │ └── ch.go │ ├── ci │ │ └── ci.go │ ├── cj │ │ └── cj.go │ ├── ck │ │ └── ck.go │ ├── cl │ │ └── cl.go │ ├── cm │ │ └── cm.go │ ├── cn │ │ └── cn.go │ ├── co │ │ └── co.go │ ├── cp │ │ └── cp.go │ ├── cq │ │ └── cq.go │ ├── cr │ │ └── cr.go │ ├── cs │ │ └── cs.go │ ├── ct │ │ └── ct.go │ ├── cu │ │ └── cu.go │ ├── cv │ │ └── cv.go │ ├── cw │ │ └── cw.go │ ├── cx │ │ └── cx.go │ ├── cy │ │ └── cy.go │ ├── cz │ │ └── cz.go │ ├── d │ │ └── d.go │ ├── da │ │ └── da.go │ ├── db │ │ └── db.go │ ├── dc │ │ └── dc.go │ ├── dd │ │ └── dd.go │ ├── de │ │ └── de.go │ ├── df │ │ └── df.go │ ├── dg │ │ └── dg.go │ ├── dh │ │ └── dh.go │ ├── di │ │ └── di.go │ ├── dj │ │ └── dj.go │ ├── dk │ │ └── dk.go │ ├── dl │ │ └── dl.go │ ├── dm │ │ └── dm.go │ ├── dn │ │ └── dn.go │ ├── do │ │ └── do.go │ ├── dp │ │ └── dp.go │ ├── dq │ │ └── dq.go │ ├── dr │ │ └── dr.go │ ├── ds │ │ └── ds.go │ ├── dt │ │ └── dt.go │ ├── du │ │ └── du.go │ ├── dv │ │ └── dv.go │ ├── dw │ │ └── dw.go │ ├── dx │ │ └── dx.go │ ├── dy │ │ └── dy.go │ ├── dz │ │ └── dz.go │ ├── e │ │ └── e.go │ ├── ea │ │ └── ea.go │ ├── eb │ │ └── eb.go │ ├── ec │ │ └── ec.go │ ├── ed │ │ └── ed.go │ ├── ee │ │ └── ee.go │ ├── ef │ │ └── ef.go │ ├── eg │ │ └── eg.go │ ├── eh │ │ └── eh.go │ ├── ei │ │ └── ei.go │ ├── ej │ │ └── ej.go │ ├── ek │ │ └── ek.go │ ├── el │ │ └── el.go │ ├── em │ │ └── em.go │ ├── en │ │ └── en.go │ ├── eo │ │ └── eo.go │ ├── ep │ │ └── ep.go │ ├── eq │ │ └── eq.go │ ├── er │ │ └── er.go │ ├── es │ │ └── es.go │ ├── et │ │ └── et.go │ ├── eu │ │ └── eu.go │ ├── ev │ │ └── ev.go │ ├── ew │ │ └── ew.go │ ├── ex │ │ └── ex.go │ ├── ey │ │ └── ey.go │ ├── ez │ │ └── ez.go │ ├── f │ │ └── f.go │ ├── fa │ │ └── fa.go │ ├── fb │ │ └── fb.go │ ├── fc │ │ └── fc.go │ ├── fd │ │ └── fd.go │ ├── fe │ │ └── fe.go │ ├── ff │ │ └── ff.go │ ├── fg │ │ └── fg.go │ ├── fh │ │ └── fh.go │ ├── fi │ │ └── fi.go │ ├── fj │ │ └── fj.go │ ├── fk │ │ └── fk.go │ ├── fl │ │ └── fl.go │ ├── fm │ │ └── fm.go │ ├── fn │ │ └── fn.go │ ├── fo │ │ └── fo.go │ ├── fp │ │ └── fp.go │ ├── fq │ │ └── fq.go │ ├── fr │ │ └── fr.go │ ├── fs │ │ └── fs.go │ ├── ft │ │ └── ft.go │ ├── fu │ │ └── fu.go │ ├── fv │ │ └── fv.go │ ├── fw │ │ └── fw.go │ ├── fx │ │ └── fx.go │ ├── fy │ │ └── fy.go │ ├── fz │ │ └── fz.go │ ├── g │ │ └── g.go │ ├── ga │ │ └── ga.go │ ├── gb │ │ └── gb.go │ ├── gc │ │ └── gc.go │ ├── gd │ │ └── gd.go │ ├── ge │ │ └── ge.go │ ├── gf │ │ └── gf.go │ ├── gg │ │ └── gg.go │ ├── gh │ │ └── gh.go │ ├── gi │ │ └── gi.go │ ├── gj │ │ └── gj.go │ ├── gk │ │ └── gk.go │ ├── gl │ │ └── gl.go │ ├── gm │ │ └── gm.go │ ├── gn │ │ └── gn.go │ ├── goo │ │ └── goo.go │ ├── gp │ │ └── gp.go │ ├── gq │ │ └── gq.go │ ├── gr │ │ └── gr.go │ ├── gs │ │ └── gs.go │ ├── gt │ │ └── gt.go │ ├── gu │ │ └── gu.go │ ├── gv │ │ └── gv.go │ ├── gw │ │ └── gw.go │ ├── gx │ │ └── gx.go │ ├── gy │ │ └── gy.go │ ├── gz │ │ └── gz.go │ ├── h │ │ └── h.go │ ├── ha │ │ └── ha.go │ ├── hb │ │ └── hb.go │ ├── hc │ │ └── hc.go │ ├── hd │ │ └── hd.go │ ├── he │ │ └── he.go │ ├── hf │ │ └── hf.go │ ├── hg │ │ └── hg.go │ ├── hh │ │ └── hh.go │ ├── hi │ │ └── hi.go │ ├── hj │ │ └── hj.go │ ├── hk │ │ └── hk.go │ ├── hl │ │ └── hl.go │ ├── hm │ │ └── hm.go │ ├── hn │ │ └── hn.go │ ├── ho │ │ └── ho.go │ ├── hp │ │ └── hp.go │ ├── hq │ │ └── hq.go │ ├── hr │ │ └── hr.go │ ├── hs │ │ └── hs.go │ ├── ht │ │ └── ht.go │ ├── hu │ │ └── hu.go │ ├── hv │ │ └── hv.go │ ├── hw │ │ └── hw.go │ ├── hx │ │ └── hx.go │ ├── hy │ │ └── hy.go │ ├── hz │ │ └── hz.go │ ├── i │ │ └── i.go │ ├── ia │ │ └── ia.go │ ├── ib │ │ └── ib.go │ ├── ic │ │ └── ic.go │ ├── id │ │ └── id.go │ ├── ie │ │ └── ie.go │ ├── iff │ │ └── iff.go │ ├── ig │ │ └── ig.go │ ├── ih │ │ └── ih.go │ ├── ii │ │ └── ii.go │ ├── ij │ │ └── ij.go │ ├── ik │ │ └── ik.go │ ├── il │ │ └── il.go │ ├── im │ │ └── im.go │ ├── in │ │ └── in.go │ ├── io │ │ └── io.go │ ├── ip │ │ └── ip.go │ ├── iq │ │ └── iq.go │ ├── ir │ │ └── ir.go │ ├── is │ │ └── is.go │ ├── it │ │ └── it.go │ ├── iu │ │ └── iu.go │ ├── iv │ │ └── iv.go │ ├── iw │ │ └── iw.go │ ├── ix │ │ └── ix.go │ ├── iy │ │ └── iy.go │ ├── iz │ │ └── iz.go │ ├── j │ │ └── j.go │ ├── ja │ │ └── ja.go │ ├── jb │ │ └── jb.go │ ├── jc │ │ └── jc.go │ ├── jd │ │ └── jd.go │ ├── je │ │ └── je.go │ ├── jf │ │ └── jf.go │ ├── jg │ │ └── jg.go │ ├── jh │ │ └── jh.go │ ├── ji │ │ └── ji.go │ ├── jj │ │ └── jj.go │ ├── jk │ │ └── jk.go │ ├── jl │ │ └── jl.go │ ├── jm │ │ └── jm.go │ ├── jn │ │ └── jn.go │ ├── jo │ │ └── jo.go │ ├── jp │ │ └── jp.go │ ├── jq │ │ └── jq.go │ ├── jr │ │ └── jr.go │ ├── js │ │ └── js.go │ ├── jt │ │ └── jt.go │ ├── ju │ │ └── ju.go │ ├── jv │ │ └── jv.go │ ├── jw │ │ └── jw.go │ ├── jx │ │ └── jx.go │ ├── jy │ │ └── jy.go │ ├── jz │ │ └── jz.go │ ├── k │ │ └── k.go │ ├── ka │ │ └── ka.go │ ├── kb │ │ └── kb.go │ ├── kc │ │ └── kc.go │ ├── kd │ │ └── kd.go │ ├── ke │ │ └── ke.go │ ├── kf │ │ └── kf.go │ ├── kg │ │ └── kg.go │ ├── kh │ │ └── kh.go │ ├── ki │ │ └── ki.go │ ├── kj │ │ └── kj.go │ ├── kk │ │ └── kk.go │ ├── kl │ │ └── kl.go │ ├── km │ │ └── km.go │ ├── kn │ │ └── kn.go │ ├── ko │ │ └── ko.go │ ├── kp │ │ └── kp.go │ ├── kq │ │ └── kq.go │ ├── kr │ │ └── kr.go │ ├── ks │ │ └── ks.go │ ├── kt │ │ └── kt.go │ ├── ku │ │ └── ku.go │ ├── kv │ │ └── kv.go │ ├── kw │ │ └── kw.go │ ├── kx │ │ └── kx.go │ ├── ky │ │ └── ky.go │ ├── kz │ │ └── kz.go │ ├── l │ │ └── l.go │ ├── la │ │ └── la.go │ ├── lb │ │ └── lb.go │ ├── lc │ │ └── lc.go │ ├── ld │ │ └── ld.go │ ├── le │ │ └── le.go │ ├── lf │ │ └── lf.go │ ├── lg │ │ └── lg.go │ ├── lh │ │ └── lh.go │ ├── li │ │ └── li.go │ ├── lj │ │ └── lj.go │ ├── lk │ │ └── lk.go │ ├── ll │ │ └── ll.go │ ├── lm │ │ └── lm.go │ ├── ln │ │ └── ln.go │ ├── lo │ │ └── lo.go │ ├── lp │ │ └── lp.go │ ├── lq │ │ └── lq.go │ ├── lr │ │ └── lr.go │ ├── ls │ │ └── ls.go │ ├── lt │ │ └── lt.go │ ├── lu │ │ └── lu.go │ ├── lv │ │ └── lv.go │ ├── lw │ │ └── lw.go │ ├── lx │ │ └── lx.go │ ├── ly │ │ └── ly.go │ ├── lz │ │ └── lz.go │ ├── m │ │ └── m.go │ ├── ma │ │ └── ma.go │ ├── main.go │ ├── n │ │ └── n.go │ ├── o │ │ └── o.go │ ├── p │ │ └── p.go │ ├── q │ │ └── q.go │ ├── r │ │ └── r.go │ ├── s │ │ └── s.go │ ├── t │ │ └── t.go │ ├── u │ │ └── u.go │ ├── v │ │ └── v.go │ ├── w │ │ └── w.go │ ├── x │ │ └── x.go │ ├── y │ │ └── y.go │ └── z │ │ └── z.go ├── day8.go └── day9.go ├── 2016 ├── day1.go ├── day10.go ├── day11.go ├── day12.go ├── day13.go ├── day14.go ├── day15.go ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day3.go ├── day4.go ├── day5.go ├── day6.go ├── day7.go ├── day8.go └── day9.go ├── 2017 ├── day1.go ├── day10.go ├── day11.go ├── day12.go ├── day13.go ├── day14.go ├── day15.go ├── day15.hs ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day3.go ├── day4.go ├── day5.go ├── day6.go ├── day7.go ├── day8.go └── day9.go ├── 2018 ├── go │ ├── day1.go │ ├── day10.go │ ├── day11.go │ ├── day12.go │ ├── day13.go │ ├── day14.go │ ├── day15.go │ ├── day16.go │ ├── day17.go │ ├── day18.go │ ├── day19.go │ ├── day2.go │ ├── day20.go │ ├── day21.go │ ├── day22.go │ ├── day23.go │ ├── day24.go │ ├── day25.go │ ├── day3.go │ ├── day4.go │ ├── day5.go │ ├── day6.go │ ├── day8.go │ └── day9.go └── rust │ ├── Cargo.toml │ ├── input │ ├── 2018 │ │ ├── day1.txt │ │ ├── day2.txt │ │ ├── day3.txt │ │ ├── day5.txt │ │ └── day6.txt │ ├── day1 │ └── day2 │ └── src │ ├── day1.rs │ ├── day2.rs │ ├── day3.rs │ ├── day5.rs │ ├── day6.rs │ ├── lib.rs │ └── main.rs ├── 2019 ├── day1.go ├── day1.hoon ├── day1.zig ├── day10.go ├── day10.zig ├── day11.go ├── day11.zig ├── day12.go ├── day12.zig ├── day13.go ├── day13.zig ├── day14.go ├── day14.zig ├── day15.go ├── day16.go ├── day16.zig ├── day17.go ├── day17.zig ├── day18.go ├── day19.go ├── day19.zig ├── day2.go ├── day2.zig ├── day20.go ├── day21.go ├── day21.zig ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day25.zig ├── day3.go ├── day3.zig ├── day4.go ├── day4.zig ├── day5.go ├── day5.zig ├── day6.go ├── day6.zig ├── day7.go ├── day7.zig ├── day8.go ├── day8.zig ├── day9.go ├── day9.zig ├── intcode │ └── machine.go └── utils.zig ├── 2020 ├── day1.go ├── day10.go ├── day11.go ├── day12.go ├── day13.go ├── day14.go ├── day15.go ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day3.go ├── day4.go ├── day5.go ├── day6.go ├── day7.go ├── day8.go └── day9.go ├── 2021 ├── day1.go ├── day1.slouch ├── day10.go ├── day10.slouch ├── day11.go ├── day11.slouch ├── day12.go ├── day12.slouch ├── day13.go ├── day13.slouch ├── day14.go ├── day14.slouch ├── day15.go ├── day15.slouch ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day2.slouch ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day3.go ├── day3.slouch ├── day4.go ├── day4.slouch ├── day5.go ├── day5.slouch ├── day6.go ├── day6.slouch ├── day7.go ├── day7.slouch ├── day8.go ├── day8.slouch ├── day9.go └── day9.slouch ├── 2022 ├── day1.go ├── day1.slouch ├── day10.go ├── day10.slouch ├── day11.go ├── day12.go ├── day13.go ├── day14.go ├── day15.go ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day2.slouch ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day25.slouch ├── day3.go ├── day3.slouch ├── day4.go ├── day4.slouch ├── day5.go ├── day5.slouch ├── day6.go ├── day6.slouch ├── day7.go ├── day7.slouch ├── day8.go ├── day8.slouch ├── day9.go └── day9.slouch ├── 2023 ├── day1.go ├── day1.slouch ├── day10.go ├── day11.go ├── day11.slouch ├── day12.go ├── day12.slouch ├── day13.go ├── day13.slouch ├── day14.go ├── day15.go ├── day16.go ├── day17.go ├── day18.go ├── day18.slouch ├── day19.go ├── day2.go ├── day2.slouch ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day3.go ├── day3.slouch ├── day4.go ├── day4.slouch ├── day5.go ├── day5.slouch ├── day6.go ├── day6.slouch ├── day7.go ├── day7.slouch ├── day8.go ├── day8.slouch └── day9.slouch ├── 2024 ├── day1.go ├── day1.slouch ├── day10.go ├── day11.go ├── day12.go ├── day13.go ├── day13.slouch ├── day14.go ├── day15.go ├── day16.go ├── day17.go ├── day18.go ├── day19.go ├── day2.go ├── day2.slouch ├── day20.go ├── day21.go ├── day22.go ├── day23.go ├── day24.go ├── day25.go ├── day25.slouch ├── day3.go ├── day3.slouch ├── day4.go ├── day4.slouch ├── day5.go ├── day5.slouch ├── day6.go ├── day7.go ├── day8.go ├── day9.go └── rust │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ ├── day01.rs │ ├── day02.rs │ ├── day03.rs │ ├── day04.rs │ ├── day05.rs │ ├── day06.rs │ ├── day07.rs │ ├── day08.rs │ ├── day09.rs │ ├── day10.rs │ ├── day11.rs │ ├── day12.rs │ ├── day13.rs │ ├── day14.rs │ ├── day17.rs │ ├── day18.rs │ ├── day19.rs │ ├── day20.rs │ ├── day22.rs │ ├── day25.rs │ ├── main.rs │ └── utils │ └── mod.rs ├── go.mod └── utils └── utils.go /2015/day10.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | const input = `1113222113` 8 | 9 | func split(str string) []string { 10 | var groups []string 11 | for len(str) != 0 { 12 | var i int 13 | for i = 0; i < len(str) && str[i] == str[0]; i++ { 14 | } 15 | groups = append(groups, str[:i]) 16 | str = str[i:] 17 | } 18 | return groups 19 | } 20 | 21 | func lookandsay(str string) string { 22 | var end string 23 | for _, nums := range split(str) { 24 | end += utils.Itoa(len(nums)) + nums[:1] 25 | } 26 | return end 27 | } 28 | 29 | func main() { 30 | // part 1 31 | var final string = input 32 | for i := 0; i < 40; i++ { 33 | final = lookandsay(final) 34 | } 35 | println(len(final)) 36 | 37 | // part 2 38 | final = input 39 | for i := 0; i < 50; i++ { 40 | final = lookandsay(final) 41 | } 42 | println(len(final)) 43 | } 44 | -------------------------------------------------------------------------------- /2015/day10.hs: -------------------------------------------------------------------------------- 1 | import Data.List (group) 2 | 3 | input :: String 4 | input = "1113222113" 5 | 6 | lookAndSay :: String -> [String] 7 | lookAndSay = iterate next where 8 | next = concatMap say . group 9 | say str = (show (length str)) ++ [head str] 10 | 11 | part1 :: String -> Int 12 | part1 = length . (!! 40) . lookAndSay 13 | 14 | part2 :: String -> Int 15 | part2 = length . (!! 50) . lookAndSay 16 | 17 | main :: IO () 18 | main = do 19 | print $ part1 input 20 | print $ part2 input 21 | -------------------------------------------------------------------------------- /2015/day10/day10.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const input = `1113222113` 4 | 5 | func run(b []byte, c byte) int // day10_amd64.s 6 | 7 | func lookandsay(buf []byte) []byte { 8 | var i int 9 | end := make([]byte, 0, len(buf)*2) 10 | for len(buf) != 0 { 11 | i = run(buf, buf[0]) 12 | end = append(end, byte(i), buf[0]) 13 | buf = buf[i:] 14 | } 15 | return end 16 | } 17 | 18 | func main() { 19 | // part 1 20 | final := make([]byte, len(input)) 21 | for i := range final { 22 | final[i] = input[i] - '0' 23 | } 24 | for i := 0; i < 40; i++ { 25 | final = lookandsay(final) 26 | } 27 | println(len(final)) 28 | 29 | // part 2 30 | for i := 0; i < 10; i++ { 31 | final = lookandsay(final) 32 | } 33 | println(len(final)) 34 | } 35 | -------------------------------------------------------------------------------- /2015/day10/day10_amd64.s: -------------------------------------------------------------------------------- 1 | // no bounds checking or calls to morestack 2 | // some help optimizing this would be nice... 3 | 4 | // func run(b []byte, c byte) int 5 | TEXT ·run(SB), $0-40 6 | start: 7 | MOVQ (TLS), CX 8 | MOVQ b+0(FP), DI 9 | MOVBQZX c+24(FP), SI 10 | MOVQ b_len+8(FP), DX 11 | MOVQ $0, AX 12 | CMPQ AX, DX 13 | JGE $0, done 14 | loop: 15 | LEAQ (DI)(AX*1), BX 16 | MOVBQZX (BX), BX 17 | CMPB BL, SIB 18 | JNE $0, done 19 | INCQ AX 20 | CMPQ AX, DX 21 | JLT $0, loop 22 | done: 23 | MOVQ AX, ret+32(FP) 24 | RET 25 | -------------------------------------------------------------------------------- /2015/day11.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/lukechampine/advent/utils" 7 | ) 8 | 9 | const input = `hxbxwxba` 10 | 11 | func increment(str string) string { 12 | init, last := str[:len(str)-1], str[len(str)-1] 13 | if last == 'z' { 14 | return increment(init) + "a" 15 | } else { 16 | return init + string(last+1) 17 | } 18 | } 19 | 20 | func rule1(str string) bool { 21 | for i := 0; i < len(str)-2; i++ { 22 | if str[i+1] == str[i]+1 && str[i+2] == str[i]+2 { 23 | return true 24 | } 25 | } 26 | return false 27 | } 28 | 29 | func rule2(str string) bool { 30 | return !strings.ContainsAny(str, "iol") 31 | } 32 | 33 | func rule3(str string) bool { 34 | alphabet := "abcdefghijklmnopqrstuvwxyz" 35 | n := 0 36 | for _, l := range alphabet { 37 | if strings.Contains(str, string(l)+string(l)) { 38 | n++ 39 | } 40 | } 41 | return n >= 2 42 | } 43 | 44 | func valid(pw string) bool { 45 | return utils.And(rule1(pw), rule2(pw), rule3(pw)) 46 | } 47 | 48 | func nextPassword(pw string) string { 49 | for !valid(pw) { 50 | pw = increment(pw) 51 | } 52 | return pw 53 | } 54 | 55 | func main() { 56 | // part 1 57 | println(nextPassword(input)) 58 | 59 | // part 2 60 | println(nextPassword(increment(nextPassword(input)))) 61 | } 62 | -------------------------------------------------------------------------------- /2015/day11.hs: -------------------------------------------------------------------------------- 1 | import Data.List (group) 2 | 3 | input :: String 4 | input = "hxbxwxba" 5 | 6 | increment :: String -> String 7 | increment = reverse . inc . reverse where 8 | inc ('z':str) = 'a' : inc str 9 | inc (c:str) = succ c : str 10 | 11 | nextPassword :: String -> String 12 | nextPassword = until valid increment where 13 | valid s = and [rule1 s, rule2 s, rule3 s] 14 | rule1 (x:y:z:s) = y == succ x && z == succ y || rule1 (y:z:s) 15 | rule1 _ = False 16 | rule2 s = not . or $ map (`elem` s) ['i','o','l'] 17 | rule3 = (>= 2) . length . filter ((>= 2) . length) . group 18 | 19 | part1 :: String -> String 20 | part1 = nextPassword 21 | 22 | part2 :: String -> String 23 | part2 = nextPassword . increment . nextPassword 24 | 25 | main :: IO () 26 | main = do 27 | print $ part1 input 28 | print $ part2 input 29 | -------------------------------------------------------------------------------- /2015/day17.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | const input = `43 8 | 3 9 | 4 10 | 10 11 | 21 12 | 44 13 | 4 14 | 6 15 | 47 16 | 41 17 | 34 18 | 17 19 | 17 20 | 44 21 | 36 22 | 31 23 | 46 24 | 9 25 | 27 26 | 38` 27 | 28 | func combinations(liters int, cs []int) [][]int { 29 | var combos [][]int 30 | for i, c := range cs { 31 | switch { 32 | case c > liters: 33 | // can't use this container 34 | case c == liters: 35 | combos = append(combos, []int{c}) 36 | case c < liters: 37 | // we want combinations, not permutations, so don't reuse cs[:i] 38 | for _, combo := range combinations(liters-c, cs[i+1:]) { 39 | combos = append(combos, append(combo, c)) 40 | } 41 | } 42 | } 43 | return combos 44 | } 45 | 46 | func main() { 47 | // part 1 48 | var containers []int 49 | for _, str := range utils.Lines(input) { 50 | containers = append(containers, utils.Atoi(str)) 51 | } 52 | combos := combinations(150, containers) 53 | println(len(combos)) 54 | 55 | // part 2 56 | minLen := utils.Minimum(len(combos), func(i int) int { 57 | return len(combos[i]) 58 | }) 59 | count := 0 60 | for _, c := range combos { 61 | if len(c) == minLen { 62 | count++ 63 | } 64 | } 65 | println(count) 66 | } 67 | -------------------------------------------------------------------------------- /2015/day20.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const input = 29000000 4 | 5 | func main() { 6 | // part 1 7 | houses := make([]int, input/10) // answer won't be higher than input/10 8 | for elf := 1; elf < len(houses); elf++ { 9 | for h := elf; h < len(houses); h += elf { 10 | houses[h] += elf * 10 11 | } 12 | } 13 | for h, presents := range houses { 14 | if presents > input { 15 | println(h) 16 | break 17 | } 18 | } 19 | 20 | // // part 2 21 | houses = make([]int, input/10) 22 | for elf := 1; elf < len(houses); elf++ { 23 | count := 0 24 | for h := elf; h < len(houses) && count < 50; h += elf { 25 | houses[h] += elf * 11 26 | count++ 27 | } 28 | } 29 | for h, presents := range houses { 30 | if presents > input { 31 | println(h) 32 | break 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /2015/day24.hs: -------------------------------------------------------------------------------- 1 | presents :: [Int] 2 | presents = [1, 3, 5, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113] 3 | 4 | groups :: Int -> Int -> [Int] -> [[Int]] 5 | groups 0 _ _ = [] 6 | groups m 0 [] = [[]] 7 | groups m _ [] = [] 8 | groups m w (x:xs) = map (x:) (groups (m-1) (w-x) xs) ++ groups m w xs 9 | 10 | bestGroup :: Int -> Int -> [Int] -> Int 11 | bestGroup maxlen n xs = minimum . map product $ groups maxlen weight xs where 12 | weight = sum xs `div` n 13 | 14 | main :: IO () 15 | main = do 16 | print $ bestGroup 7 3 presents 17 | print $ bestGroup 6 4 presents -------------------------------------------------------------------------------- /2015/day25.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const inputRow = 2981 4 | const inputCol = 3075 5 | 6 | func makeCodes() [][]int { 7 | codes := make([][]int, 8000) 8 | for i := range codes { 9 | codes[i] = make([]int, 8000) 10 | } 11 | lastcode := 20151125 12 | for i := 0; i < 8000; i++ { 13 | for j := 0; j <= i; j++ { 14 | codes[i-j][j] = lastcode 15 | lastcode = (lastcode * 252533) % 33554393 16 | } 17 | } 18 | return codes 19 | } 20 | 21 | func main() { 22 | codes := makeCodes() 23 | println(codes[inputRow-1][inputCol-1]) // 1-indexed 24 | } 25 | -------------------------------------------------------------------------------- /2015/day25.hs: -------------------------------------------------------------------------------- 1 | codenum :: Int -> Int -> Int 2 | codenum row col = col + sum (enumFromTo 2 (row+col-2)) 3 | 4 | nextcode :: Int -> Int 5 | nextcode x = x * 252533 `mod` 33554393 6 | 7 | code :: Int -> Int 8 | code n = iterate' nextcode 20151125 !! n where 9 | iterate' f x = x `seq` x : iterate' f (f x) 10 | 11 | main :: IO () 12 | main = print $ code (codenum 2981 3075) 13 | -------------------------------------------------------------------------------- /2015/day4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/md5" 5 | "fmt" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | const input = "bgvyzdsv" 11 | 12 | func main() { 13 | // part 1 14 | for i := 0; ; i++ { 15 | data := input + strconv.Itoa(i) 16 | sum := fmt.Sprintf("%x", md5.Sum([]byte(data))) 17 | if strings.HasPrefix(sum, "00000") { 18 | println(i) 19 | break 20 | } 21 | } 22 | 23 | // part 2 24 | for i := 0; ; i++ { 25 | data := input + strconv.Itoa(i) 26 | sum := fmt.Sprintf("%x", md5.Sum([]byte(data))) 27 | if strings.HasPrefix(sum, "000000") { 28 | println(i) 29 | break 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /2015/day7/a/a.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lx" 5 | ) 6 | 7 | var Value uint16 = lx.Value 8 | -------------------------------------------------------------------------------- /2015/day7/aa/aa.go: -------------------------------------------------------------------------------- 1 | package aa 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/x" 5 | 6 | ) 7 | 8 | var Value uint16 = x.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/ab/ab.go: -------------------------------------------------------------------------------- 1 | package ab 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/z" 5 | "github.com/lukechampine/advent/day7/aa" 6 | ) 7 | 8 | var Value uint16 = z.Value | aa.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ac/ac.go: -------------------------------------------------------------------------------- 1 | package ac 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/z" 5 | "github.com/lukechampine/advent/day7/aa" 6 | ) 7 | 8 | var Value uint16 = z.Value & aa.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ad/ad.go: -------------------------------------------------------------------------------- 1 | package ad 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ac" 5 | ) 6 | 7 | var Value uint16 = ^ac.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ae/ae.go: -------------------------------------------------------------------------------- 1 | package ae 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ab" 5 | "github.com/lukechampine/advent/day7/ad" 6 | ) 7 | 8 | var Value uint16 = ab.Value & ad.Value 9 | -------------------------------------------------------------------------------- /2015/day7/af/af.go: -------------------------------------------------------------------------------- 1 | package af 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/y" 5 | "github.com/lukechampine/advent/day7/ae" 6 | ) 7 | 8 | var Value uint16 = y.Value | ae.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ag/ag.go: -------------------------------------------------------------------------------- 1 | package ag 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/y" 5 | "github.com/lukechampine/advent/day7/ae" 6 | ) 7 | 8 | var Value uint16 = y.Value & ae.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ah/ah.go: -------------------------------------------------------------------------------- 1 | package ah 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ag" 5 | ) 6 | 7 | var Value uint16 = ^ag.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ai/ai.go: -------------------------------------------------------------------------------- 1 | package ai 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/af" 5 | "github.com/lukechampine/advent/day7/ah" 6 | ) 7 | 8 | var Value uint16 = af.Value & ah.Value 9 | -------------------------------------------------------------------------------- /2015/day7/aj/aj.go: -------------------------------------------------------------------------------- 1 | package aj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/x" 5 | "github.com/lukechampine/advent/day7/ai" 6 | ) 7 | 8 | var Value uint16 = x.Value | ai.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ak/ak.go: -------------------------------------------------------------------------------- 1 | package ak 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/x" 5 | "github.com/lukechampine/advent/day7/ai" 6 | ) 7 | 8 | var Value uint16 = x.Value & ai.Value 9 | -------------------------------------------------------------------------------- /2015/day7/al/al.go: -------------------------------------------------------------------------------- 1 | package al 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ak" 5 | ) 6 | 7 | var Value uint16 = ^ak.Value 8 | -------------------------------------------------------------------------------- /2015/day7/am/am.go: -------------------------------------------------------------------------------- 1 | package am 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/aj" 5 | "github.com/lukechampine/advent/day7/al" 6 | ) 7 | 8 | var Value uint16 = aj.Value & al.Value 9 | -------------------------------------------------------------------------------- /2015/day7/an/an.go: -------------------------------------------------------------------------------- 1 | package an 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/am" 6 | ) 7 | 8 | var Value uint16 = 1 & am.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ao/ao.go: -------------------------------------------------------------------------------- 1 | package ao 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/u" 5 | 6 | ) 7 | 8 | var Value uint16 = u.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/ap/ap.go: -------------------------------------------------------------------------------- 1 | package ap 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ao" 5 | "github.com/lukechampine/advent/day7/an" 6 | ) 7 | 8 | var Value uint16 = ao.Value | an.Value 9 | -------------------------------------------------------------------------------- /2015/day7/aq/aq.go: -------------------------------------------------------------------------------- 1 | package aq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/x" 5 | 6 | ) 7 | 8 | var Value uint16 = x.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/ar/ar.go: -------------------------------------------------------------------------------- 1 | package ar 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/an" 5 | 6 | ) 7 | 8 | var Value uint16 = an.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/as/as.go: -------------------------------------------------------------------------------- 1 | package as 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/aq" 5 | "github.com/lukechampine/advent/day7/ar" 6 | ) 7 | 8 | var Value uint16 = aq.Value | ar.Value 9 | -------------------------------------------------------------------------------- /2015/day7/at/at.go: -------------------------------------------------------------------------------- 1 | package at 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/as" 5 | 6 | ) 7 | 8 | var Value uint16 = as.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/au/au.go: -------------------------------------------------------------------------------- 1 | package au 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/as" 5 | 6 | ) 7 | 8 | var Value uint16 = as.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/av/av.go: -------------------------------------------------------------------------------- 1 | package av 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/as" 5 | 6 | ) 7 | 8 | var Value uint16 = as.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/aw/aw.go: -------------------------------------------------------------------------------- 1 | package aw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/au" 5 | "github.com/lukechampine/advent/day7/av" 6 | ) 7 | 8 | var Value uint16 = au.Value | av.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ax/ax.go: -------------------------------------------------------------------------------- 1 | package ax 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/au" 5 | "github.com/lukechampine/advent/day7/av" 6 | ) 7 | 8 | var Value uint16 = au.Value & av.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ay/ay.go: -------------------------------------------------------------------------------- 1 | package ay 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ax" 5 | ) 6 | 7 | var Value uint16 = ^ax.Value 8 | -------------------------------------------------------------------------------- /2015/day7/az/az.go: -------------------------------------------------------------------------------- 1 | package az 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/aw" 5 | "github.com/lukechampine/advent/day7/ay" 6 | ) 7 | 8 | var Value uint16 = aw.Value & ay.Value 9 | -------------------------------------------------------------------------------- /2015/day7/b/b.go: -------------------------------------------------------------------------------- 1 | package b 2 | 3 | import ( 4 | 5 | ) 6 | 7 | var Value uint16 = 14146 8 | -------------------------------------------------------------------------------- /2015/day7/ba/ba.go: -------------------------------------------------------------------------------- 1 | package ba 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/at" 5 | "github.com/lukechampine/advent/day7/az" 6 | ) 7 | 8 | var Value uint16 = at.Value | az.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bb/bb.go: -------------------------------------------------------------------------------- 1 | package bb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/at" 5 | "github.com/lukechampine/advent/day7/az" 6 | ) 7 | 8 | var Value uint16 = at.Value & az.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bc/bc.go: -------------------------------------------------------------------------------- 1 | package bc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bb" 5 | ) 6 | 7 | var Value uint16 = ^bb.Value 8 | -------------------------------------------------------------------------------- /2015/day7/bd/bd.go: -------------------------------------------------------------------------------- 1 | package bd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ba" 5 | "github.com/lukechampine/advent/day7/bc" 6 | ) 7 | 8 | var Value uint16 = ba.Value & bc.Value 9 | -------------------------------------------------------------------------------- /2015/day7/be/be.go: -------------------------------------------------------------------------------- 1 | package be 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/as" 5 | "github.com/lukechampine/advent/day7/bd" 6 | ) 7 | 8 | var Value uint16 = as.Value | bd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bf/bf.go: -------------------------------------------------------------------------------- 1 | package bf 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/as" 5 | "github.com/lukechampine/advent/day7/bd" 6 | ) 7 | 8 | var Value uint16 = as.Value & bd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bg/bg.go: -------------------------------------------------------------------------------- 1 | package bg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bf" 5 | ) 6 | 7 | var Value uint16 = ^bf.Value 8 | -------------------------------------------------------------------------------- /2015/day7/bh/bh.go: -------------------------------------------------------------------------------- 1 | package bh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/be" 5 | "github.com/lukechampine/advent/day7/bg" 6 | ) 7 | 8 | var Value uint16 = be.Value & bg.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bi/bi.go: -------------------------------------------------------------------------------- 1 | package bi 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/bh" 6 | ) 7 | 8 | var Value uint16 = 1 & bh.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bj/bj.go: -------------------------------------------------------------------------------- 1 | package bj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ap" 5 | 6 | ) 7 | 8 | var Value uint16 = ap.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/bk/bk.go: -------------------------------------------------------------------------------- 1 | package bk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bj" 5 | "github.com/lukechampine/advent/day7/bi" 6 | ) 7 | 8 | var Value uint16 = bj.Value | bi.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bl/bl.go: -------------------------------------------------------------------------------- 1 | package bl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/as" 5 | 6 | ) 7 | 8 | var Value uint16 = as.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/bm/bm.go: -------------------------------------------------------------------------------- 1 | package bm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bi" 5 | 6 | ) 7 | 8 | var Value uint16 = bi.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/bn/bn.go: -------------------------------------------------------------------------------- 1 | package bn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bl" 5 | "github.com/lukechampine/advent/day7/bm" 6 | ) 7 | 8 | var Value uint16 = bl.Value | bm.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bo/bo.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bn" 5 | 6 | ) 7 | 8 | var Value uint16 = bn.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/bp/bp.go: -------------------------------------------------------------------------------- 1 | package bp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bn" 5 | 6 | ) 7 | 8 | var Value uint16 = bn.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/bq/bq.go: -------------------------------------------------------------------------------- 1 | package bq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bn" 5 | 6 | ) 7 | 8 | var Value uint16 = bn.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/br/br.go: -------------------------------------------------------------------------------- 1 | package br 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bp" 5 | "github.com/lukechampine/advent/day7/bq" 6 | ) 7 | 8 | var Value uint16 = bp.Value | bq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bs/bs.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bp" 5 | "github.com/lukechampine/advent/day7/bq" 6 | ) 7 | 8 | var Value uint16 = bp.Value & bq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bt/bt.go: -------------------------------------------------------------------------------- 1 | package bt 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bs" 5 | ) 6 | 7 | var Value uint16 = ^bs.Value 8 | -------------------------------------------------------------------------------- /2015/day7/bu/bu.go: -------------------------------------------------------------------------------- 1 | package bu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/br" 5 | "github.com/lukechampine/advent/day7/bt" 6 | ) 7 | 8 | var Value uint16 = br.Value & bt.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bv/bv.go: -------------------------------------------------------------------------------- 1 | package bv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bo" 5 | "github.com/lukechampine/advent/day7/bu" 6 | ) 7 | 8 | var Value uint16 = bo.Value | bu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bw/bw.go: -------------------------------------------------------------------------------- 1 | package bw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bo" 5 | "github.com/lukechampine/advent/day7/bu" 6 | ) 7 | 8 | var Value uint16 = bo.Value & bu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bx/bx.go: -------------------------------------------------------------------------------- 1 | package bx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bw" 5 | ) 6 | 7 | var Value uint16 = ^bw.Value 8 | -------------------------------------------------------------------------------- /2015/day7/by/by.go: -------------------------------------------------------------------------------- 1 | package by 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bv" 5 | "github.com/lukechampine/advent/day7/bx" 6 | ) 7 | 8 | var Value uint16 = bv.Value & bx.Value 9 | -------------------------------------------------------------------------------- /2015/day7/bz/bz.go: -------------------------------------------------------------------------------- 1 | package bz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bn" 5 | "github.com/lukechampine/advent/day7/by" 6 | ) 7 | 8 | var Value uint16 = bn.Value | by.Value 9 | -------------------------------------------------------------------------------- /2015/day7/c/c.go: -------------------------------------------------------------------------------- 1 | package c 2 | 3 | import ( 4 | 5 | ) 6 | 7 | var Value uint16 = 0 8 | -------------------------------------------------------------------------------- /2015/day7/ca/ca.go: -------------------------------------------------------------------------------- 1 | package ca 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bn" 5 | "github.com/lukechampine/advent/day7/by" 6 | ) 7 | 8 | var Value uint16 = bn.Value & by.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cb/cb.go: -------------------------------------------------------------------------------- 1 | package cb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ca" 5 | ) 6 | 7 | var Value uint16 = ^ca.Value 8 | -------------------------------------------------------------------------------- /2015/day7/cc/cc.go: -------------------------------------------------------------------------------- 1 | package cc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bz" 5 | "github.com/lukechampine/advent/day7/cb" 6 | ) 7 | 8 | var Value uint16 = bz.Value & cb.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cd/cd.go: -------------------------------------------------------------------------------- 1 | package cd 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/cc" 6 | ) 7 | 8 | var Value uint16 = 1 & cc.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ce/ce.go: -------------------------------------------------------------------------------- 1 | package ce 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bk" 5 | 6 | ) 7 | 8 | var Value uint16 = bk.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/cf/cf.go: -------------------------------------------------------------------------------- 1 | package cf 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ce" 5 | "github.com/lukechampine/advent/day7/cd" 6 | ) 7 | 8 | var Value uint16 = ce.Value | cd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cg/cg.go: -------------------------------------------------------------------------------- 1 | package cg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/bn" 5 | 6 | ) 7 | 8 | var Value uint16 = bn.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/ch/ch.go: -------------------------------------------------------------------------------- 1 | package ch 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cd" 5 | 6 | ) 7 | 8 | var Value uint16 = cd.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/ci/ci.go: -------------------------------------------------------------------------------- 1 | package ci 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cg" 5 | "github.com/lukechampine/advent/day7/ch" 6 | ) 7 | 8 | var Value uint16 = cg.Value | ch.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cj/cj.go: -------------------------------------------------------------------------------- 1 | package cj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ci" 5 | 6 | ) 7 | 8 | var Value uint16 = ci.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/ck/ck.go: -------------------------------------------------------------------------------- 1 | package ck 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ci" 5 | 6 | ) 7 | 8 | var Value uint16 = ci.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/cl/cl.go: -------------------------------------------------------------------------------- 1 | package cl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ci" 5 | 6 | ) 7 | 8 | var Value uint16 = ci.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/cm/cm.go: -------------------------------------------------------------------------------- 1 | package cm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ck" 5 | "github.com/lukechampine/advent/day7/cl" 6 | ) 7 | 8 | var Value uint16 = ck.Value | cl.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cn/cn.go: -------------------------------------------------------------------------------- 1 | package cn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ck" 5 | "github.com/lukechampine/advent/day7/cl" 6 | ) 7 | 8 | var Value uint16 = ck.Value & cl.Value 9 | -------------------------------------------------------------------------------- /2015/day7/co/co.go: -------------------------------------------------------------------------------- 1 | package co 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cn" 5 | ) 6 | 7 | var Value uint16 = ^cn.Value 8 | -------------------------------------------------------------------------------- /2015/day7/cp/cp.go: -------------------------------------------------------------------------------- 1 | package cp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cm" 5 | "github.com/lukechampine/advent/day7/co" 6 | ) 7 | 8 | var Value uint16 = cm.Value & co.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cq/cq.go: -------------------------------------------------------------------------------- 1 | package cq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cj" 5 | "github.com/lukechampine/advent/day7/cp" 6 | ) 7 | 8 | var Value uint16 = cj.Value | cp.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cr/cr.go: -------------------------------------------------------------------------------- 1 | package cr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cj" 5 | "github.com/lukechampine/advent/day7/cp" 6 | ) 7 | 8 | var Value uint16 = cj.Value & cp.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cs/cs.go: -------------------------------------------------------------------------------- 1 | package cs 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cr" 5 | ) 6 | 7 | var Value uint16 = ^cr.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ct/ct.go: -------------------------------------------------------------------------------- 1 | package ct 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cq" 5 | "github.com/lukechampine/advent/day7/cs" 6 | ) 7 | 8 | var Value uint16 = cq.Value & cs.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cu/cu.go: -------------------------------------------------------------------------------- 1 | package cu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ci" 5 | "github.com/lukechampine/advent/day7/ct" 6 | ) 7 | 8 | var Value uint16 = ci.Value | ct.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cv/cv.go: -------------------------------------------------------------------------------- 1 | package cv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ci" 5 | "github.com/lukechampine/advent/day7/ct" 6 | ) 7 | 8 | var Value uint16 = ci.Value & ct.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cw/cw.go: -------------------------------------------------------------------------------- 1 | package cw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cv" 5 | ) 6 | 7 | var Value uint16 = ^cv.Value 8 | -------------------------------------------------------------------------------- /2015/day7/cx/cx.go: -------------------------------------------------------------------------------- 1 | package cx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cu" 5 | "github.com/lukechampine/advent/day7/cw" 6 | ) 7 | 8 | var Value uint16 = cu.Value & cw.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cy/cy.go: -------------------------------------------------------------------------------- 1 | package cy 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/cx" 6 | ) 7 | 8 | var Value uint16 = 1 & cx.Value 9 | -------------------------------------------------------------------------------- /2015/day7/cz/cz.go: -------------------------------------------------------------------------------- 1 | package cz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cf" 5 | 6 | ) 7 | 8 | var Value uint16 = cf.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/d/d.go: -------------------------------------------------------------------------------- 1 | package d 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/b" 5 | 6 | ) 7 | 8 | var Value uint16 = b.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/da/da.go: -------------------------------------------------------------------------------- 1 | package da 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cz" 5 | "github.com/lukechampine/advent/day7/cy" 6 | ) 7 | 8 | var Value uint16 = cz.Value | cy.Value 9 | -------------------------------------------------------------------------------- /2015/day7/db/db.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ci" 5 | 6 | ) 7 | 8 | var Value uint16 = ci.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/dc/dc.go: -------------------------------------------------------------------------------- 1 | package dc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/cy" 5 | 6 | ) 7 | 8 | var Value uint16 = cy.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/dd/dd.go: -------------------------------------------------------------------------------- 1 | package dd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/db" 5 | "github.com/lukechampine/advent/day7/dc" 6 | ) 7 | 8 | var Value uint16 = db.Value | dc.Value 9 | -------------------------------------------------------------------------------- /2015/day7/de/de.go: -------------------------------------------------------------------------------- 1 | package de 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dd" 5 | 6 | ) 7 | 8 | var Value uint16 = dd.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/df/df.go: -------------------------------------------------------------------------------- 1 | package df 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dd" 5 | 6 | ) 7 | 8 | var Value uint16 = dd.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/dg/dg.go: -------------------------------------------------------------------------------- 1 | package dg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dd" 5 | 6 | ) 7 | 8 | var Value uint16 = dd.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/dh/dh.go: -------------------------------------------------------------------------------- 1 | package dh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/df" 5 | "github.com/lukechampine/advent/day7/dg" 6 | ) 7 | 8 | var Value uint16 = df.Value | dg.Value 9 | -------------------------------------------------------------------------------- /2015/day7/di/di.go: -------------------------------------------------------------------------------- 1 | package di 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/df" 5 | "github.com/lukechampine/advent/day7/dg" 6 | ) 7 | 8 | var Value uint16 = df.Value & dg.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dj/dj.go: -------------------------------------------------------------------------------- 1 | package dj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/di" 5 | ) 6 | 7 | var Value uint16 = ^di.Value 8 | -------------------------------------------------------------------------------- /2015/day7/dk/dk.go: -------------------------------------------------------------------------------- 1 | package dk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dh" 5 | "github.com/lukechampine/advent/day7/dj" 6 | ) 7 | 8 | var Value uint16 = dh.Value & dj.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dl/dl.go: -------------------------------------------------------------------------------- 1 | package dl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/de" 5 | "github.com/lukechampine/advent/day7/dk" 6 | ) 7 | 8 | var Value uint16 = de.Value | dk.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dm/dm.go: -------------------------------------------------------------------------------- 1 | package dm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/de" 5 | "github.com/lukechampine/advent/day7/dk" 6 | ) 7 | 8 | var Value uint16 = de.Value & dk.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dn/dn.go: -------------------------------------------------------------------------------- 1 | package dn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dm" 5 | ) 6 | 7 | var Value uint16 = ^dm.Value 8 | -------------------------------------------------------------------------------- /2015/day7/do/do.go: -------------------------------------------------------------------------------- 1 | package do 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dl" 5 | "github.com/lukechampine/advent/day7/dn" 6 | ) 7 | 8 | var Value uint16 = dl.Value & dn.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dp/dp.go: -------------------------------------------------------------------------------- 1 | package dp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dd" 5 | "github.com/lukechampine/advent/day7/do" 6 | ) 7 | 8 | var Value uint16 = dd.Value | do.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dq/dq.go: -------------------------------------------------------------------------------- 1 | package dq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dd" 5 | "github.com/lukechampine/advent/day7/do" 6 | ) 7 | 8 | var Value uint16 = dd.Value & do.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dr/dr.go: -------------------------------------------------------------------------------- 1 | package dr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dq" 5 | ) 6 | 7 | var Value uint16 = ^dq.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ds/ds.go: -------------------------------------------------------------------------------- 1 | package ds 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dp" 5 | "github.com/lukechampine/advent/day7/dr" 6 | ) 7 | 8 | var Value uint16 = dp.Value & dr.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dt/dt.go: -------------------------------------------------------------------------------- 1 | package dt 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/ds" 6 | ) 7 | 8 | var Value uint16 = 1 & ds.Value 9 | -------------------------------------------------------------------------------- /2015/day7/du/du.go: -------------------------------------------------------------------------------- 1 | package du 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/da" 5 | 6 | ) 7 | 8 | var Value uint16 = da.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/dv/dv.go: -------------------------------------------------------------------------------- 1 | package dv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/du" 5 | "github.com/lukechampine/advent/day7/dt" 6 | ) 7 | 8 | var Value uint16 = du.Value | dt.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dw/dw.go: -------------------------------------------------------------------------------- 1 | package dw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dd" 5 | 6 | ) 7 | 8 | var Value uint16 = dd.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/dx/dx.go: -------------------------------------------------------------------------------- 1 | package dx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dt" 5 | 6 | ) 7 | 8 | var Value uint16 = dt.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/dy/dy.go: -------------------------------------------------------------------------------- 1 | package dy 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dw" 5 | "github.com/lukechampine/advent/day7/dx" 6 | ) 7 | 8 | var Value uint16 = dw.Value | dx.Value 9 | -------------------------------------------------------------------------------- /2015/day7/dz/dz.go: -------------------------------------------------------------------------------- 1 | package dz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dy" 5 | 6 | ) 7 | 8 | var Value uint16 = dy.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/e/e.go: -------------------------------------------------------------------------------- 1 | package e 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/b" 5 | 6 | ) 7 | 8 | var Value uint16 = b.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/ea/ea.go: -------------------------------------------------------------------------------- 1 | package ea 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dy" 5 | 6 | ) 7 | 8 | var Value uint16 = dy.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/eb/eb.go: -------------------------------------------------------------------------------- 1 | package eb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dy" 5 | 6 | ) 7 | 8 | var Value uint16 = dy.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/ec/ec.go: -------------------------------------------------------------------------------- 1 | package ec 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ea" 5 | "github.com/lukechampine/advent/day7/eb" 6 | ) 7 | 8 | var Value uint16 = ea.Value | eb.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ed/ed.go: -------------------------------------------------------------------------------- 1 | package ed 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ea" 5 | "github.com/lukechampine/advent/day7/eb" 6 | ) 7 | 8 | var Value uint16 = ea.Value & eb.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ee/ee.go: -------------------------------------------------------------------------------- 1 | package ee 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ed" 5 | ) 6 | 7 | var Value uint16 = ^ed.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ef/ef.go: -------------------------------------------------------------------------------- 1 | package ef 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ec" 5 | "github.com/lukechampine/advent/day7/ee" 6 | ) 7 | 8 | var Value uint16 = ec.Value & ee.Value 9 | -------------------------------------------------------------------------------- /2015/day7/eg/eg.go: -------------------------------------------------------------------------------- 1 | package eg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dz" 5 | "github.com/lukechampine/advent/day7/ef" 6 | ) 7 | 8 | var Value uint16 = dz.Value | ef.Value 9 | -------------------------------------------------------------------------------- /2015/day7/eh/eh.go: -------------------------------------------------------------------------------- 1 | package eh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dz" 5 | "github.com/lukechampine/advent/day7/ef" 6 | ) 7 | 8 | var Value uint16 = dz.Value & ef.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ei/ei.go: -------------------------------------------------------------------------------- 1 | package ei 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/eh" 5 | ) 6 | 7 | var Value uint16 = ^eh.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ej/ej.go: -------------------------------------------------------------------------------- 1 | package ej 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/eg" 5 | "github.com/lukechampine/advent/day7/ei" 6 | ) 7 | 8 | var Value uint16 = eg.Value & ei.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ek/ek.go: -------------------------------------------------------------------------------- 1 | package ek 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dy" 5 | "github.com/lukechampine/advent/day7/ej" 6 | ) 7 | 8 | var Value uint16 = dy.Value | ej.Value 9 | -------------------------------------------------------------------------------- /2015/day7/el/el.go: -------------------------------------------------------------------------------- 1 | package el 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dy" 5 | "github.com/lukechampine/advent/day7/ej" 6 | ) 7 | 8 | var Value uint16 = dy.Value & ej.Value 9 | -------------------------------------------------------------------------------- /2015/day7/em/em.go: -------------------------------------------------------------------------------- 1 | package em 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/el" 5 | ) 6 | 7 | var Value uint16 = ^el.Value 8 | -------------------------------------------------------------------------------- /2015/day7/en/en.go: -------------------------------------------------------------------------------- 1 | package en 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ek" 5 | "github.com/lukechampine/advent/day7/em" 6 | ) 7 | 8 | var Value uint16 = ek.Value & em.Value 9 | -------------------------------------------------------------------------------- /2015/day7/eo/eo.go: -------------------------------------------------------------------------------- 1 | package eo 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/en" 6 | ) 7 | 8 | var Value uint16 = 1 & en.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ep/ep.go: -------------------------------------------------------------------------------- 1 | package ep 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dv" 5 | 6 | ) 7 | 8 | var Value uint16 = dv.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/eq/eq.go: -------------------------------------------------------------------------------- 1 | package eq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ep" 5 | "github.com/lukechampine/advent/day7/eo" 6 | ) 7 | 8 | var Value uint16 = ep.Value | eo.Value 9 | -------------------------------------------------------------------------------- /2015/day7/er/er.go: -------------------------------------------------------------------------------- 1 | package er 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/dy" 5 | 6 | ) 7 | 8 | var Value uint16 = dy.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/es/es.go: -------------------------------------------------------------------------------- 1 | package es 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/eo" 5 | 6 | ) 7 | 8 | var Value uint16 = eo.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/et/et.go: -------------------------------------------------------------------------------- 1 | package et 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/er" 5 | "github.com/lukechampine/advent/day7/es" 6 | ) 7 | 8 | var Value uint16 = er.Value | es.Value 9 | -------------------------------------------------------------------------------- /2015/day7/eu/eu.go: -------------------------------------------------------------------------------- 1 | package eu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/et" 5 | 6 | ) 7 | 8 | var Value uint16 = et.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/ev/ev.go: -------------------------------------------------------------------------------- 1 | package ev 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/et" 5 | 6 | ) 7 | 8 | var Value uint16 = et.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/ew/ew.go: -------------------------------------------------------------------------------- 1 | package ew 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/et" 5 | 6 | ) 7 | 8 | var Value uint16 = et.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/ex/ex.go: -------------------------------------------------------------------------------- 1 | package ex 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ev" 5 | "github.com/lukechampine/advent/day7/ew" 6 | ) 7 | 8 | var Value uint16 = ev.Value | ew.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ey/ey.go: -------------------------------------------------------------------------------- 1 | package ey 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ev" 5 | "github.com/lukechampine/advent/day7/ew" 6 | ) 7 | 8 | var Value uint16 = ev.Value & ew.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ez/ez.go: -------------------------------------------------------------------------------- 1 | package ez 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ey" 5 | ) 6 | 7 | var Value uint16 = ^ey.Value 8 | -------------------------------------------------------------------------------- /2015/day7/f/f.go: -------------------------------------------------------------------------------- 1 | package f 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/b" 5 | 6 | ) 7 | 8 | var Value uint16 = b.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/fa/fa.go: -------------------------------------------------------------------------------- 1 | package fa 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ex" 5 | "github.com/lukechampine/advent/day7/ez" 6 | ) 7 | 8 | var Value uint16 = ex.Value & ez.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fb/fb.go: -------------------------------------------------------------------------------- 1 | package fb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/eu" 5 | "github.com/lukechampine/advent/day7/fa" 6 | ) 7 | 8 | var Value uint16 = eu.Value | fa.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fc/fc.go: -------------------------------------------------------------------------------- 1 | package fc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/eu" 5 | "github.com/lukechampine/advent/day7/fa" 6 | ) 7 | 8 | var Value uint16 = eu.Value & fa.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fd/fd.go: -------------------------------------------------------------------------------- 1 | package fd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fc" 5 | ) 6 | 7 | var Value uint16 = ^fc.Value 8 | -------------------------------------------------------------------------------- /2015/day7/fe/fe.go: -------------------------------------------------------------------------------- 1 | package fe 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fb" 5 | "github.com/lukechampine/advent/day7/fd" 6 | ) 7 | 8 | var Value uint16 = fb.Value & fd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ff/ff.go: -------------------------------------------------------------------------------- 1 | package ff 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/et" 5 | "github.com/lukechampine/advent/day7/fe" 6 | ) 7 | 8 | var Value uint16 = et.Value | fe.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fg/fg.go: -------------------------------------------------------------------------------- 1 | package fg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/et" 5 | "github.com/lukechampine/advent/day7/fe" 6 | ) 7 | 8 | var Value uint16 = et.Value & fe.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fh/fh.go: -------------------------------------------------------------------------------- 1 | package fh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fg" 5 | ) 6 | 7 | var Value uint16 = ^fg.Value 8 | -------------------------------------------------------------------------------- /2015/day7/fi/fi.go: -------------------------------------------------------------------------------- 1 | package fi 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ff" 5 | "github.com/lukechampine/advent/day7/fh" 6 | ) 7 | 8 | var Value uint16 = ff.Value & fh.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fj/fj.go: -------------------------------------------------------------------------------- 1 | package fj 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/fi" 6 | ) 7 | 8 | var Value uint16 = 1 & fi.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fk/fk.go: -------------------------------------------------------------------------------- 1 | package fk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/eq" 5 | 6 | ) 7 | 8 | var Value uint16 = eq.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/fl/fl.go: -------------------------------------------------------------------------------- 1 | package fl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fk" 5 | "github.com/lukechampine/advent/day7/fj" 6 | ) 7 | 8 | var Value uint16 = fk.Value | fj.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fm/fm.go: -------------------------------------------------------------------------------- 1 | package fm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/et" 5 | 6 | ) 7 | 8 | var Value uint16 = et.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/fn/fn.go: -------------------------------------------------------------------------------- 1 | package fn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fj" 5 | 6 | ) 7 | 8 | var Value uint16 = fj.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/fo/fo.go: -------------------------------------------------------------------------------- 1 | package fo 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fm" 5 | "github.com/lukechampine/advent/day7/fn" 6 | ) 7 | 8 | var Value uint16 = fm.Value | fn.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fp/fp.go: -------------------------------------------------------------------------------- 1 | package fp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fo" 5 | 6 | ) 7 | 8 | var Value uint16 = fo.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/fq/fq.go: -------------------------------------------------------------------------------- 1 | package fq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fo" 5 | 6 | ) 7 | 8 | var Value uint16 = fo.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/fr/fr.go: -------------------------------------------------------------------------------- 1 | package fr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fo" 5 | 6 | ) 7 | 8 | var Value uint16 = fo.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/fs/fs.go: -------------------------------------------------------------------------------- 1 | package fs 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fq" 5 | "github.com/lukechampine/advent/day7/fr" 6 | ) 7 | 8 | var Value uint16 = fq.Value | fr.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ft/ft.go: -------------------------------------------------------------------------------- 1 | package ft 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fq" 5 | "github.com/lukechampine/advent/day7/fr" 6 | ) 7 | 8 | var Value uint16 = fq.Value & fr.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fu/fu.go: -------------------------------------------------------------------------------- 1 | package fu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ft" 5 | ) 6 | 7 | var Value uint16 = ^ft.Value 8 | -------------------------------------------------------------------------------- /2015/day7/fv/fv.go: -------------------------------------------------------------------------------- 1 | package fv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fs" 5 | "github.com/lukechampine/advent/day7/fu" 6 | ) 7 | 8 | var Value uint16 = fs.Value & fu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fw/fw.go: -------------------------------------------------------------------------------- 1 | package fw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fp" 5 | "github.com/lukechampine/advent/day7/fv" 6 | ) 7 | 8 | var Value uint16 = fp.Value | fv.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fx/fx.go: -------------------------------------------------------------------------------- 1 | package fx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fp" 5 | "github.com/lukechampine/advent/day7/fv" 6 | ) 7 | 8 | var Value uint16 = fp.Value & fv.Value 9 | -------------------------------------------------------------------------------- /2015/day7/fy/fy.go: -------------------------------------------------------------------------------- 1 | package fy 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fx" 5 | ) 6 | 7 | var Value uint16 = ^fx.Value 8 | -------------------------------------------------------------------------------- /2015/day7/fz/fz.go: -------------------------------------------------------------------------------- 1 | package fz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fw" 5 | "github.com/lukechampine/advent/day7/fy" 6 | ) 7 | 8 | var Value uint16 = fw.Value & fy.Value 9 | -------------------------------------------------------------------------------- /2015/day7/g/g.go: -------------------------------------------------------------------------------- 1 | package g 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/e" 5 | "github.com/lukechampine/advent/day7/f" 6 | ) 7 | 8 | var Value uint16 = e.Value | f.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ga/ga.go: -------------------------------------------------------------------------------- 1 | package ga 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fo" 5 | "github.com/lukechampine/advent/day7/fz" 6 | ) 7 | 8 | var Value uint16 = fo.Value | fz.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gb/gb.go: -------------------------------------------------------------------------------- 1 | package gb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fo" 5 | "github.com/lukechampine/advent/day7/fz" 6 | ) 7 | 8 | var Value uint16 = fo.Value & fz.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gc/gc.go: -------------------------------------------------------------------------------- 1 | package gc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gb" 5 | ) 6 | 7 | var Value uint16 = ^gb.Value 8 | -------------------------------------------------------------------------------- /2015/day7/gd/gd.go: -------------------------------------------------------------------------------- 1 | package gd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ga" 5 | "github.com/lukechampine/advent/day7/gc" 6 | ) 7 | 8 | var Value uint16 = ga.Value & gc.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ge/ge.go: -------------------------------------------------------------------------------- 1 | package ge 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/gd" 6 | ) 7 | 8 | var Value uint16 = 1 & gd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gf/gf.go: -------------------------------------------------------------------------------- 1 | package gf 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fl" 5 | 6 | ) 7 | 8 | var Value uint16 = fl.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/gg/gg.go: -------------------------------------------------------------------------------- 1 | package gg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gf" 5 | "github.com/lukechampine/advent/day7/ge" 6 | ) 7 | 8 | var Value uint16 = gf.Value | ge.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gh/gh.go: -------------------------------------------------------------------------------- 1 | package gh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/fo" 5 | 6 | ) 7 | 8 | var Value uint16 = fo.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/gi/gi.go: -------------------------------------------------------------------------------- 1 | package gi 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ge" 5 | 6 | ) 7 | 8 | var Value uint16 = ge.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/gj/gj.go: -------------------------------------------------------------------------------- 1 | package gj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gh" 5 | "github.com/lukechampine/advent/day7/gi" 6 | ) 7 | 8 | var Value uint16 = gh.Value | gi.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gk/gk.go: -------------------------------------------------------------------------------- 1 | package gk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gj" 5 | 6 | ) 7 | 8 | var Value uint16 = gj.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/gl/gl.go: -------------------------------------------------------------------------------- 1 | package gl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gj" 5 | 6 | ) 7 | 8 | var Value uint16 = gj.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/gm/gm.go: -------------------------------------------------------------------------------- 1 | package gm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gj" 5 | 6 | ) 7 | 8 | var Value uint16 = gj.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/gn/gn.go: -------------------------------------------------------------------------------- 1 | package gn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gl" 5 | "github.com/lukechampine/advent/day7/gm" 6 | ) 7 | 8 | var Value uint16 = gl.Value | gm.Value 9 | -------------------------------------------------------------------------------- /2015/day7/goo/goo.go: -------------------------------------------------------------------------------- 1 | package goo 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gl" 5 | "github.com/lukechampine/advent/day7/gm" 6 | ) 7 | 8 | var Value uint16 = gl.Value & gm.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gp/gp.go: -------------------------------------------------------------------------------- 1 | package gp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/goo" 5 | ) 6 | 7 | var Value uint16 = ^goo.Value 8 | -------------------------------------------------------------------------------- /2015/day7/gq/gq.go: -------------------------------------------------------------------------------- 1 | package gq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gn" 5 | "github.com/lukechampine/advent/day7/gp" 6 | ) 7 | 8 | var Value uint16 = gn.Value & gp.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gr/gr.go: -------------------------------------------------------------------------------- 1 | package gr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gk" 5 | "github.com/lukechampine/advent/day7/gq" 6 | ) 7 | 8 | var Value uint16 = gk.Value | gq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gs/gs.go: -------------------------------------------------------------------------------- 1 | package gs 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gk" 5 | "github.com/lukechampine/advent/day7/gq" 6 | ) 7 | 8 | var Value uint16 = gk.Value & gq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gt/gt.go: -------------------------------------------------------------------------------- 1 | package gt 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gs" 5 | ) 6 | 7 | var Value uint16 = ^gs.Value 8 | -------------------------------------------------------------------------------- /2015/day7/gu/gu.go: -------------------------------------------------------------------------------- 1 | package gu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gr" 5 | "github.com/lukechampine/advent/day7/gt" 6 | ) 7 | 8 | var Value uint16 = gr.Value & gt.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gv/gv.go: -------------------------------------------------------------------------------- 1 | package gv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gj" 5 | "github.com/lukechampine/advent/day7/gu" 6 | ) 7 | 8 | var Value uint16 = gj.Value | gu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gw/gw.go: -------------------------------------------------------------------------------- 1 | package gw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gj" 5 | "github.com/lukechampine/advent/day7/gu" 6 | ) 7 | 8 | var Value uint16 = gj.Value & gu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gx/gx.go: -------------------------------------------------------------------------------- 1 | package gx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gw" 5 | ) 6 | 7 | var Value uint16 = ^gw.Value 8 | -------------------------------------------------------------------------------- /2015/day7/gy/gy.go: -------------------------------------------------------------------------------- 1 | package gy 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gv" 5 | "github.com/lukechampine/advent/day7/gx" 6 | ) 7 | 8 | var Value uint16 = gv.Value & gx.Value 9 | -------------------------------------------------------------------------------- /2015/day7/gz/gz.go: -------------------------------------------------------------------------------- 1 | package gz 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/gy" 6 | ) 7 | 8 | var Value uint16 = 1 & gy.Value 9 | -------------------------------------------------------------------------------- /2015/day7/h/h.go: -------------------------------------------------------------------------------- 1 | package h 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/e" 5 | "github.com/lukechampine/advent/day7/f" 6 | ) 7 | 8 | var Value uint16 = e.Value & f.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ha/ha.go: -------------------------------------------------------------------------------- 1 | package ha 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gg" 5 | 6 | ) 7 | 8 | var Value uint16 = gg.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/hb/hb.go: -------------------------------------------------------------------------------- 1 | package hb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ha" 5 | "github.com/lukechampine/advent/day7/gz" 6 | ) 7 | 8 | var Value uint16 = ha.Value | gz.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hc/hc.go: -------------------------------------------------------------------------------- 1 | package hc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gj" 5 | 6 | ) 7 | 8 | var Value uint16 = gj.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/hd/hd.go: -------------------------------------------------------------------------------- 1 | package hd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/gz" 5 | 6 | ) 7 | 8 | var Value uint16 = gz.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/he/he.go: -------------------------------------------------------------------------------- 1 | package he 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hc" 5 | "github.com/lukechampine/advent/day7/hd" 6 | ) 7 | 8 | var Value uint16 = hc.Value | hd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hf/hf.go: -------------------------------------------------------------------------------- 1 | package hf 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/he" 5 | 6 | ) 7 | 8 | var Value uint16 = he.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/hg/hg.go: -------------------------------------------------------------------------------- 1 | package hg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/he" 5 | 6 | ) 7 | 8 | var Value uint16 = he.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/hh/hh.go: -------------------------------------------------------------------------------- 1 | package hh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/he" 5 | 6 | ) 7 | 8 | var Value uint16 = he.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/hi/hi.go: -------------------------------------------------------------------------------- 1 | package hi 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hg" 5 | "github.com/lukechampine/advent/day7/hh" 6 | ) 7 | 8 | var Value uint16 = hg.Value | hh.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hj/hj.go: -------------------------------------------------------------------------------- 1 | package hj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hg" 5 | "github.com/lukechampine/advent/day7/hh" 6 | ) 7 | 8 | var Value uint16 = hg.Value & hh.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hk/hk.go: -------------------------------------------------------------------------------- 1 | package hk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hj" 5 | ) 6 | 7 | var Value uint16 = ^hj.Value 8 | -------------------------------------------------------------------------------- /2015/day7/hl/hl.go: -------------------------------------------------------------------------------- 1 | package hl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hi" 5 | "github.com/lukechampine/advent/day7/hk" 6 | ) 7 | 8 | var Value uint16 = hi.Value & hk.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hm/hm.go: -------------------------------------------------------------------------------- 1 | package hm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hf" 5 | "github.com/lukechampine/advent/day7/hl" 6 | ) 7 | 8 | var Value uint16 = hf.Value | hl.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hn/hn.go: -------------------------------------------------------------------------------- 1 | package hn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hf" 5 | "github.com/lukechampine/advent/day7/hl" 6 | ) 7 | 8 | var Value uint16 = hf.Value & hl.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ho/ho.go: -------------------------------------------------------------------------------- 1 | package ho 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hn" 5 | ) 6 | 7 | var Value uint16 = ^hn.Value 8 | -------------------------------------------------------------------------------- /2015/day7/hp/hp.go: -------------------------------------------------------------------------------- 1 | package hp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hm" 5 | "github.com/lukechampine/advent/day7/ho" 6 | ) 7 | 8 | var Value uint16 = hm.Value & ho.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hq/hq.go: -------------------------------------------------------------------------------- 1 | package hq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/he" 5 | "github.com/lukechampine/advent/day7/hp" 6 | ) 7 | 8 | var Value uint16 = he.Value | hp.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hr/hr.go: -------------------------------------------------------------------------------- 1 | package hr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/he" 5 | "github.com/lukechampine/advent/day7/hp" 6 | ) 7 | 8 | var Value uint16 = he.Value & hp.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hs/hs.go: -------------------------------------------------------------------------------- 1 | package hs 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hr" 5 | ) 6 | 7 | var Value uint16 = ^hr.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ht/ht.go: -------------------------------------------------------------------------------- 1 | package ht 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hq" 5 | "github.com/lukechampine/advent/day7/hs" 6 | ) 7 | 8 | var Value uint16 = hq.Value & hs.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hu/hu.go: -------------------------------------------------------------------------------- 1 | package hu 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/ht" 6 | ) 7 | 8 | var Value uint16 = 1 & ht.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hv/hv.go: -------------------------------------------------------------------------------- 1 | package hv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hb" 5 | 6 | ) 7 | 8 | var Value uint16 = hb.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/hw/hw.go: -------------------------------------------------------------------------------- 1 | package hw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hv" 5 | "github.com/lukechampine/advent/day7/hu" 6 | ) 7 | 8 | var Value uint16 = hv.Value | hu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/hx/hx.go: -------------------------------------------------------------------------------- 1 | package hx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/he" 5 | 6 | ) 7 | 8 | var Value uint16 = he.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/hy/hy.go: -------------------------------------------------------------------------------- 1 | package hy 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hu" 5 | 6 | ) 7 | 8 | var Value uint16 = hu.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/hz/hz.go: -------------------------------------------------------------------------------- 1 | package hz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hx" 5 | "github.com/lukechampine/advent/day7/hy" 6 | ) 7 | 8 | var Value uint16 = hx.Value | hy.Value 9 | -------------------------------------------------------------------------------- /2015/day7/i/i.go: -------------------------------------------------------------------------------- 1 | package i 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/h" 5 | ) 6 | 7 | var Value uint16 = ^h.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ia/ia.go: -------------------------------------------------------------------------------- 1 | package ia 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hz" 5 | 6 | ) 7 | 8 | var Value uint16 = hz.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/ib/ib.go: -------------------------------------------------------------------------------- 1 | package ib 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hz" 5 | 6 | ) 7 | 8 | var Value uint16 = hz.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/ic/ic.go: -------------------------------------------------------------------------------- 1 | package ic 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hz" 5 | 6 | ) 7 | 8 | var Value uint16 = hz.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/id/id.go: -------------------------------------------------------------------------------- 1 | package id 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ib" 5 | "github.com/lukechampine/advent/day7/ic" 6 | ) 7 | 8 | var Value uint16 = ib.Value | ic.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ie/ie.go: -------------------------------------------------------------------------------- 1 | package ie 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ib" 5 | "github.com/lukechampine/advent/day7/ic" 6 | ) 7 | 8 | var Value uint16 = ib.Value & ic.Value 9 | -------------------------------------------------------------------------------- /2015/day7/iff/iff.go: -------------------------------------------------------------------------------- 1 | package iff 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ie" 5 | ) 6 | 7 | var Value uint16 = ^ie.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ig/ig.go: -------------------------------------------------------------------------------- 1 | package ig 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/id" 5 | "github.com/lukechampine/advent/day7/iff" 6 | ) 7 | 8 | var Value uint16 = id.Value & iff.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ih/ih.go: -------------------------------------------------------------------------------- 1 | package ih 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ia" 5 | "github.com/lukechampine/advent/day7/ig" 6 | ) 7 | 8 | var Value uint16 = ia.Value | ig.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ii/ii.go: -------------------------------------------------------------------------------- 1 | package ii 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ia" 5 | "github.com/lukechampine/advent/day7/ig" 6 | ) 7 | 8 | var Value uint16 = ia.Value & ig.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ij/ij.go: -------------------------------------------------------------------------------- 1 | package ij 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ii" 5 | ) 6 | 7 | var Value uint16 = ^ii.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ik/ik.go: -------------------------------------------------------------------------------- 1 | package ik 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ih" 5 | "github.com/lukechampine/advent/day7/ij" 6 | ) 7 | 8 | var Value uint16 = ih.Value & ij.Value 9 | -------------------------------------------------------------------------------- /2015/day7/il/il.go: -------------------------------------------------------------------------------- 1 | package il 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hz" 5 | "github.com/lukechampine/advent/day7/ik" 6 | ) 7 | 8 | var Value uint16 = hz.Value | ik.Value 9 | -------------------------------------------------------------------------------- /2015/day7/im/im.go: -------------------------------------------------------------------------------- 1 | package im 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hz" 5 | "github.com/lukechampine/advent/day7/ik" 6 | ) 7 | 8 | var Value uint16 = hz.Value & ik.Value 9 | -------------------------------------------------------------------------------- /2015/day7/in/in.go: -------------------------------------------------------------------------------- 1 | package in 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/im" 5 | ) 6 | 7 | var Value uint16 = ^im.Value 8 | -------------------------------------------------------------------------------- /2015/day7/io/io.go: -------------------------------------------------------------------------------- 1 | package io 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/il" 5 | "github.com/lukechampine/advent/day7/in" 6 | ) 7 | 8 | var Value uint16 = il.Value & in.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ip/ip.go: -------------------------------------------------------------------------------- 1 | package ip 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/io" 6 | ) 7 | 8 | var Value uint16 = 1 & io.Value 9 | -------------------------------------------------------------------------------- /2015/day7/iq/iq.go: -------------------------------------------------------------------------------- 1 | package iq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hw" 5 | 6 | ) 7 | 8 | var Value uint16 = hw.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/ir/ir.go: -------------------------------------------------------------------------------- 1 | package ir 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iq" 5 | "github.com/lukechampine/advent/day7/ip" 6 | ) 7 | 8 | var Value uint16 = iq.Value | ip.Value 9 | -------------------------------------------------------------------------------- /2015/day7/is/is.go: -------------------------------------------------------------------------------- 1 | package is 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/hz" 5 | 6 | ) 7 | 8 | var Value uint16 = hz.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/it/it.go: -------------------------------------------------------------------------------- 1 | package it 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ip" 5 | 6 | ) 7 | 8 | var Value uint16 = ip.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/iu/iu.go: -------------------------------------------------------------------------------- 1 | package iu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/is" 5 | "github.com/lukechampine/advent/day7/it" 6 | ) 7 | 8 | var Value uint16 = is.Value | it.Value 9 | -------------------------------------------------------------------------------- /2015/day7/iv/iv.go: -------------------------------------------------------------------------------- 1 | package iv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iu" 5 | 6 | ) 7 | 8 | var Value uint16 = iu.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/iw/iw.go: -------------------------------------------------------------------------------- 1 | package iw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iu" 5 | 6 | ) 7 | 8 | var Value uint16 = iu.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/ix/ix.go: -------------------------------------------------------------------------------- 1 | package ix 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iu" 5 | 6 | ) 7 | 8 | var Value uint16 = iu.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/iy/iy.go: -------------------------------------------------------------------------------- 1 | package iy 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iw" 5 | "github.com/lukechampine/advent/day7/ix" 6 | ) 7 | 8 | var Value uint16 = iw.Value | ix.Value 9 | -------------------------------------------------------------------------------- /2015/day7/iz/iz.go: -------------------------------------------------------------------------------- 1 | package iz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iw" 5 | "github.com/lukechampine/advent/day7/ix" 6 | ) 7 | 8 | var Value uint16 = iw.Value & ix.Value 9 | -------------------------------------------------------------------------------- /2015/day7/j/j.go: -------------------------------------------------------------------------------- 1 | package j 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/g" 5 | "github.com/lukechampine/advent/day7/i" 6 | ) 7 | 8 | var Value uint16 = g.Value & i.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ja/ja.go: -------------------------------------------------------------------------------- 1 | package ja 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iz" 5 | ) 6 | 7 | var Value uint16 = ^iz.Value 8 | -------------------------------------------------------------------------------- /2015/day7/jb/jb.go: -------------------------------------------------------------------------------- 1 | package jb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iy" 5 | "github.com/lukechampine/advent/day7/ja" 6 | ) 7 | 8 | var Value uint16 = iy.Value & ja.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jc/jc.go: -------------------------------------------------------------------------------- 1 | package jc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iv" 5 | "github.com/lukechampine/advent/day7/jb" 6 | ) 7 | 8 | var Value uint16 = iv.Value | jb.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jd/jd.go: -------------------------------------------------------------------------------- 1 | package jd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iv" 5 | "github.com/lukechampine/advent/day7/jb" 6 | ) 7 | 8 | var Value uint16 = iv.Value & jb.Value 9 | -------------------------------------------------------------------------------- /2015/day7/je/je.go: -------------------------------------------------------------------------------- 1 | package je 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jd" 5 | ) 6 | 7 | var Value uint16 = ^jd.Value 8 | -------------------------------------------------------------------------------- /2015/day7/jf/jf.go: -------------------------------------------------------------------------------- 1 | package jf 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jc" 5 | "github.com/lukechampine/advent/day7/je" 6 | ) 7 | 8 | var Value uint16 = jc.Value & je.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jg/jg.go: -------------------------------------------------------------------------------- 1 | package jg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iu" 5 | "github.com/lukechampine/advent/day7/jf" 6 | ) 7 | 8 | var Value uint16 = iu.Value | jf.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jh/jh.go: -------------------------------------------------------------------------------- 1 | package jh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iu" 5 | "github.com/lukechampine/advent/day7/jf" 6 | ) 7 | 8 | var Value uint16 = iu.Value & jf.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ji/ji.go: -------------------------------------------------------------------------------- 1 | package ji 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jh" 5 | ) 6 | 7 | var Value uint16 = ^jh.Value 8 | -------------------------------------------------------------------------------- /2015/day7/jj/jj.go: -------------------------------------------------------------------------------- 1 | package jj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jg" 5 | "github.com/lukechampine/advent/day7/ji" 6 | ) 7 | 8 | var Value uint16 = jg.Value & ji.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jk/jk.go: -------------------------------------------------------------------------------- 1 | package jk 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/jj" 6 | ) 7 | 8 | var Value uint16 = 1 & jj.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jl/jl.go: -------------------------------------------------------------------------------- 1 | package jl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ir" 5 | 6 | ) 7 | 8 | var Value uint16 = ir.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/jm/jm.go: -------------------------------------------------------------------------------- 1 | package jm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jl" 5 | "github.com/lukechampine/advent/day7/jk" 6 | ) 7 | 8 | var Value uint16 = jl.Value | jk.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jn/jn.go: -------------------------------------------------------------------------------- 1 | package jn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/iu" 5 | 6 | ) 7 | 8 | var Value uint16 = iu.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/jo/jo.go: -------------------------------------------------------------------------------- 1 | package jo 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jk" 5 | 6 | ) 7 | 8 | var Value uint16 = jk.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/jp/jp.go: -------------------------------------------------------------------------------- 1 | package jp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jn" 5 | "github.com/lukechampine/advent/day7/jo" 6 | ) 7 | 8 | var Value uint16 = jn.Value | jo.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jq/jq.go: -------------------------------------------------------------------------------- 1 | package jq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jp" 5 | 6 | ) 7 | 8 | var Value uint16 = jp.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/jr/jr.go: -------------------------------------------------------------------------------- 1 | package jr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jp" 5 | 6 | ) 7 | 8 | var Value uint16 = jp.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/js/js.go: -------------------------------------------------------------------------------- 1 | package js 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jp" 5 | 6 | ) 7 | 8 | var Value uint16 = jp.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/jt/jt.go: -------------------------------------------------------------------------------- 1 | package jt 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jr" 5 | "github.com/lukechampine/advent/day7/js" 6 | ) 7 | 8 | var Value uint16 = jr.Value | js.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ju/ju.go: -------------------------------------------------------------------------------- 1 | package ju 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jr" 5 | "github.com/lukechampine/advent/day7/js" 6 | ) 7 | 8 | var Value uint16 = jr.Value & js.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jv/jv.go: -------------------------------------------------------------------------------- 1 | package jv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ju" 5 | ) 6 | 7 | var Value uint16 = ^ju.Value 8 | -------------------------------------------------------------------------------- /2015/day7/jw/jw.go: -------------------------------------------------------------------------------- 1 | package jw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jt" 5 | "github.com/lukechampine/advent/day7/jv" 6 | ) 7 | 8 | var Value uint16 = jt.Value & jv.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jx/jx.go: -------------------------------------------------------------------------------- 1 | package jx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jq" 5 | "github.com/lukechampine/advent/day7/jw" 6 | ) 7 | 8 | var Value uint16 = jq.Value | jw.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jy/jy.go: -------------------------------------------------------------------------------- 1 | package jy 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jq" 5 | "github.com/lukechampine/advent/day7/jw" 6 | ) 7 | 8 | var Value uint16 = jq.Value & jw.Value 9 | -------------------------------------------------------------------------------- /2015/day7/jz/jz.go: -------------------------------------------------------------------------------- 1 | package jz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jy" 5 | ) 6 | 7 | var Value uint16 = ^jy.Value 8 | -------------------------------------------------------------------------------- /2015/day7/k/k.go: -------------------------------------------------------------------------------- 1 | package k 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/d" 5 | "github.com/lukechampine/advent/day7/j" 6 | ) 7 | 8 | var Value uint16 = d.Value | j.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ka/ka.go: -------------------------------------------------------------------------------- 1 | package ka 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jx" 5 | "github.com/lukechampine/advent/day7/jz" 6 | ) 7 | 8 | var Value uint16 = jx.Value & jz.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kb/kb.go: -------------------------------------------------------------------------------- 1 | package kb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jp" 5 | "github.com/lukechampine/advent/day7/ka" 6 | ) 7 | 8 | var Value uint16 = jp.Value | ka.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kc/kc.go: -------------------------------------------------------------------------------- 1 | package kc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jp" 5 | "github.com/lukechampine/advent/day7/ka" 6 | ) 7 | 8 | var Value uint16 = jp.Value & ka.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kd/kd.go: -------------------------------------------------------------------------------- 1 | package kd 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kc" 5 | ) 6 | 7 | var Value uint16 = ^kc.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ke/ke.go: -------------------------------------------------------------------------------- 1 | package ke 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kb" 5 | "github.com/lukechampine/advent/day7/kd" 6 | ) 7 | 8 | var Value uint16 = kb.Value & kd.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kf/kf.go: -------------------------------------------------------------------------------- 1 | package kf 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/ke" 6 | ) 7 | 8 | var Value uint16 = 1 & ke.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kg/kg.go: -------------------------------------------------------------------------------- 1 | package kg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jm" 5 | 6 | ) 7 | 8 | var Value uint16 = jm.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/kh/kh.go: -------------------------------------------------------------------------------- 1 | package kh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kg" 5 | "github.com/lukechampine/advent/day7/kf" 6 | ) 7 | 8 | var Value uint16 = kg.Value | kf.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ki/ki.go: -------------------------------------------------------------------------------- 1 | package ki 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/jp" 5 | 6 | ) 7 | 8 | var Value uint16 = jp.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/kj/kj.go: -------------------------------------------------------------------------------- 1 | package kj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kf" 5 | 6 | ) 7 | 8 | var Value uint16 = kf.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/kk/kk.go: -------------------------------------------------------------------------------- 1 | package kk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ki" 5 | "github.com/lukechampine/advent/day7/kj" 6 | ) 7 | 8 | var Value uint16 = ki.Value | kj.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kl/kl.go: -------------------------------------------------------------------------------- 1 | package kl 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kk" 5 | 6 | ) 7 | 8 | var Value uint16 = kk.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/km/km.go: -------------------------------------------------------------------------------- 1 | package km 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kk" 5 | 6 | ) 7 | 8 | var Value uint16 = kk.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/kn/kn.go: -------------------------------------------------------------------------------- 1 | package kn 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kk" 5 | 6 | ) 7 | 8 | var Value uint16 = kk.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/ko/ko.go: -------------------------------------------------------------------------------- 1 | package ko 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/km" 5 | "github.com/lukechampine/advent/day7/kn" 6 | ) 7 | 8 | var Value uint16 = km.Value | kn.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kp/kp.go: -------------------------------------------------------------------------------- 1 | package kp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/km" 5 | "github.com/lukechampine/advent/day7/kn" 6 | ) 7 | 8 | var Value uint16 = km.Value & kn.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kq/kq.go: -------------------------------------------------------------------------------- 1 | package kq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kp" 5 | ) 6 | 7 | var Value uint16 = ^kp.Value 8 | -------------------------------------------------------------------------------- /2015/day7/kr/kr.go: -------------------------------------------------------------------------------- 1 | package kr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ko" 5 | "github.com/lukechampine/advent/day7/kq" 6 | ) 7 | 8 | var Value uint16 = ko.Value & kq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ks/ks.go: -------------------------------------------------------------------------------- 1 | package ks 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kl" 5 | "github.com/lukechampine/advent/day7/kr" 6 | ) 7 | 8 | var Value uint16 = kl.Value | kr.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kt/kt.go: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kl" 5 | "github.com/lukechampine/advent/day7/kr" 6 | ) 7 | 8 | var Value uint16 = kl.Value & kr.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ku/ku.go: -------------------------------------------------------------------------------- 1 | package ku 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kt" 5 | ) 6 | 7 | var Value uint16 = ^kt.Value 8 | -------------------------------------------------------------------------------- /2015/day7/kv/kv.go: -------------------------------------------------------------------------------- 1 | package kv 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ks" 5 | "github.com/lukechampine/advent/day7/ku" 6 | ) 7 | 8 | var Value uint16 = ks.Value & ku.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kw/kw.go: -------------------------------------------------------------------------------- 1 | package kw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kk" 5 | "github.com/lukechampine/advent/day7/kv" 6 | ) 7 | 8 | var Value uint16 = kk.Value | kv.Value 9 | -------------------------------------------------------------------------------- /2015/day7/kx/kx.go: -------------------------------------------------------------------------------- 1 | package kx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kk" 5 | "github.com/lukechampine/advent/day7/kv" 6 | ) 7 | 8 | var Value uint16 = kk.Value & kv.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ky/ky.go: -------------------------------------------------------------------------------- 1 | package ky 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kx" 5 | ) 6 | 7 | var Value uint16 = ^kx.Value 8 | -------------------------------------------------------------------------------- /2015/day7/kz/kz.go: -------------------------------------------------------------------------------- 1 | package kz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kw" 5 | "github.com/lukechampine/advent/day7/ky" 6 | ) 7 | 8 | var Value uint16 = kw.Value & ky.Value 9 | -------------------------------------------------------------------------------- /2015/day7/l/l.go: -------------------------------------------------------------------------------- 1 | package l 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/d" 5 | "github.com/lukechampine/advent/day7/j" 6 | ) 7 | 8 | var Value uint16 = d.Value & j.Value 9 | -------------------------------------------------------------------------------- /2015/day7/la/la.go: -------------------------------------------------------------------------------- 1 | package la 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/kz" 6 | ) 7 | 8 | var Value uint16 = 1 & kz.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lb/lb.go: -------------------------------------------------------------------------------- 1 | package lb 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kh" 5 | 6 | ) 7 | 8 | var Value uint16 = kh.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/lc/lc.go: -------------------------------------------------------------------------------- 1 | package lc 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lb" 5 | "github.com/lukechampine/advent/day7/la" 6 | ) 7 | 8 | var Value uint16 = lb.Value | la.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ld/ld.go: -------------------------------------------------------------------------------- 1 | package ld 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/kk" 5 | 6 | ) 7 | 8 | var Value uint16 = kk.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/le/le.go: -------------------------------------------------------------------------------- 1 | package le 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/la" 5 | 6 | ) 7 | 8 | var Value uint16 = la.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/lf/lf.go: -------------------------------------------------------------------------------- 1 | package lf 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ld" 5 | "github.com/lukechampine/advent/day7/le" 6 | ) 7 | 8 | var Value uint16 = ld.Value | le.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lg/lg.go: -------------------------------------------------------------------------------- 1 | package lg 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lf" 5 | 6 | ) 7 | 8 | var Value uint16 = lf.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/lh/lh.go: -------------------------------------------------------------------------------- 1 | package lh 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lf" 5 | 6 | ) 7 | 8 | var Value uint16 = lf.Value >> 3 9 | -------------------------------------------------------------------------------- /2015/day7/li/li.go: -------------------------------------------------------------------------------- 1 | package li 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lf" 5 | 6 | ) 7 | 8 | var Value uint16 = lf.Value >> 5 9 | -------------------------------------------------------------------------------- /2015/day7/lj/lj.go: -------------------------------------------------------------------------------- 1 | package lj 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lh" 5 | "github.com/lukechampine/advent/day7/li" 6 | ) 7 | 8 | var Value uint16 = lh.Value | li.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lk/lk.go: -------------------------------------------------------------------------------- 1 | package lk 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lh" 5 | "github.com/lukechampine/advent/day7/li" 6 | ) 7 | 8 | var Value uint16 = lh.Value & li.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ll/ll.go: -------------------------------------------------------------------------------- 1 | package ll 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lk" 5 | ) 6 | 7 | var Value uint16 = ^lk.Value 8 | -------------------------------------------------------------------------------- /2015/day7/lm/lm.go: -------------------------------------------------------------------------------- 1 | package lm 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lj" 5 | "github.com/lukechampine/advent/day7/ll" 6 | ) 7 | 8 | var Value uint16 = lj.Value & ll.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ln/ln.go: -------------------------------------------------------------------------------- 1 | package ln 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lg" 5 | "github.com/lukechampine/advent/day7/lm" 6 | ) 7 | 8 | var Value uint16 = lg.Value | lm.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lo/lo.go: -------------------------------------------------------------------------------- 1 | package lo 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lg" 5 | "github.com/lukechampine/advent/day7/lm" 6 | ) 7 | 8 | var Value uint16 = lg.Value & lm.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lp/lp.go: -------------------------------------------------------------------------------- 1 | package lp 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lo" 5 | ) 6 | 7 | var Value uint16 = ^lo.Value 8 | -------------------------------------------------------------------------------- /2015/day7/lq/lq.go: -------------------------------------------------------------------------------- 1 | package lq 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ln" 5 | "github.com/lukechampine/advent/day7/lp" 6 | ) 7 | 8 | var Value uint16 = ln.Value & lp.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lr/lr.go: -------------------------------------------------------------------------------- 1 | package lr 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lf" 5 | "github.com/lukechampine/advent/day7/lq" 6 | ) 7 | 8 | var Value uint16 = lf.Value | lq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ls/ls.go: -------------------------------------------------------------------------------- 1 | package ls 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lf" 5 | "github.com/lukechampine/advent/day7/lq" 6 | ) 7 | 8 | var Value uint16 = lf.Value & lq.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lt/lt.go: -------------------------------------------------------------------------------- 1 | package lt 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ls" 5 | ) 6 | 7 | var Value uint16 = ^ls.Value 8 | -------------------------------------------------------------------------------- /2015/day7/lu/lu.go: -------------------------------------------------------------------------------- 1 | package lu 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lr" 5 | "github.com/lukechampine/advent/day7/lt" 6 | ) 7 | 8 | var Value uint16 = lr.Value & lt.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lv/lv.go: -------------------------------------------------------------------------------- 1 | package lv 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/lu" 6 | ) 7 | 8 | var Value uint16 = 1 & lu.Value 9 | -------------------------------------------------------------------------------- /2015/day7/lw/lw.go: -------------------------------------------------------------------------------- 1 | package lw 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lc" 5 | 6 | ) 7 | 8 | var Value uint16 = lc.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/lx/lx.go: -------------------------------------------------------------------------------- 1 | package lx 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lw" 5 | "github.com/lukechampine/advent/day7/lv" 6 | ) 7 | 8 | var Value uint16 = lw.Value | lv.Value 9 | -------------------------------------------------------------------------------- /2015/day7/ly/ly.go: -------------------------------------------------------------------------------- 1 | package ly 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lf" 5 | 6 | ) 7 | 8 | var Value uint16 = lf.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/lz/lz.go: -------------------------------------------------------------------------------- 1 | package lz 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/lv" 5 | 6 | ) 7 | 8 | var Value uint16 = lv.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/m/m.go: -------------------------------------------------------------------------------- 1 | package m 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/l" 5 | ) 6 | 7 | var Value uint16 = ^l.Value 8 | -------------------------------------------------------------------------------- /2015/day7/ma/ma.go: -------------------------------------------------------------------------------- 1 | package ma 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/ly" 5 | "github.com/lukechampine/advent/day7/lz" 6 | ) 7 | 8 | var Value uint16 = ly.Value | lz.Value 9 | -------------------------------------------------------------------------------- /2015/day7/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/lukechampine/advent/day7/a" 4 | 5 | func main() { 6 | println(a.Value) 7 | } 8 | -------------------------------------------------------------------------------- /2015/day7/n/n.go: -------------------------------------------------------------------------------- 1 | package n 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/k" 5 | "github.com/lukechampine/advent/day7/m" 6 | ) 7 | 8 | var Value uint16 = k.Value & m.Value 9 | -------------------------------------------------------------------------------- /2015/day7/o/o.go: -------------------------------------------------------------------------------- 1 | package o 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/b" 5 | "github.com/lukechampine/advent/day7/n" 6 | ) 7 | 8 | var Value uint16 = b.Value | n.Value 9 | -------------------------------------------------------------------------------- /2015/day7/p/p.go: -------------------------------------------------------------------------------- 1 | package p 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/b" 5 | "github.com/lukechampine/advent/day7/n" 6 | ) 7 | 8 | var Value uint16 = b.Value & n.Value 9 | -------------------------------------------------------------------------------- /2015/day7/q/q.go: -------------------------------------------------------------------------------- 1 | package q 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/p" 5 | ) 6 | 7 | var Value uint16 = ^p.Value 8 | -------------------------------------------------------------------------------- /2015/day7/r/r.go: -------------------------------------------------------------------------------- 1 | package r 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/o" 5 | "github.com/lukechampine/advent/day7/q" 6 | ) 7 | 8 | var Value uint16 = o.Value & q.Value 9 | -------------------------------------------------------------------------------- /2015/day7/s/s.go: -------------------------------------------------------------------------------- 1 | package s 2 | 3 | import ( 4 | 5 | "github.com/lukechampine/advent/day7/r" 6 | ) 7 | 8 | var Value uint16 = 1 & r.Value 9 | -------------------------------------------------------------------------------- /2015/day7/t/t.go: -------------------------------------------------------------------------------- 1 | package t 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/c" 5 | 6 | ) 7 | 8 | var Value uint16 = c.Value << 1 9 | -------------------------------------------------------------------------------- /2015/day7/u/u.go: -------------------------------------------------------------------------------- 1 | package u 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/t" 5 | "github.com/lukechampine/advent/day7/s" 6 | ) 7 | 8 | var Value uint16 = t.Value | s.Value 9 | -------------------------------------------------------------------------------- /2015/day7/v/v.go: -------------------------------------------------------------------------------- 1 | package v 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/b" 5 | 6 | ) 7 | 8 | var Value uint16 = b.Value >> 1 9 | -------------------------------------------------------------------------------- /2015/day7/w/w.go: -------------------------------------------------------------------------------- 1 | package w 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/s" 5 | 6 | ) 7 | 8 | var Value uint16 = s.Value << 15 9 | -------------------------------------------------------------------------------- /2015/day7/x/x.go: -------------------------------------------------------------------------------- 1 | package x 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/v" 5 | "github.com/lukechampine/advent/day7/w" 6 | ) 7 | 8 | var Value uint16 = v.Value | w.Value 9 | -------------------------------------------------------------------------------- /2015/day7/y/y.go: -------------------------------------------------------------------------------- 1 | package y 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/x" 5 | 6 | ) 7 | 8 | var Value uint16 = x.Value >> 2 9 | -------------------------------------------------------------------------------- /2015/day7/z/z.go: -------------------------------------------------------------------------------- 1 | package z 2 | 3 | import ( 4 | "github.com/lukechampine/advent/day7/x" 5 | 6 | ) 7 | 8 | var Value uint16 = x.Value >> 3 9 | -------------------------------------------------------------------------------- /2016/day13.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/lukechampine/advent/utils" 4 | 5 | const input = 1362 6 | 7 | func isWall(p utils.Pos) bool { 8 | n := uint64(p.X*p.X + 3*p.X + 2*p.X*p.Y + p.Y + p.Y*p.Y + input) 9 | n -= (n >> 1) & 0x5555555555555555 10 | n = (n>>2)&0x3333333333333333 + n&0x3333333333333333 11 | n += n >> 4 12 | n &= 0x0f0f0f0f0f0f0f0f 13 | n *= 0x0101010101010101 14 | return byte(n>>56)%2 != 0 15 | } 16 | 17 | func main() { 18 | // part 1 19 | m := utils.Maze{ 20 | Grid: utils.Grid{50, 50}, 21 | IsWall: isWall, 22 | } 23 | dist := m.DistancesFrom(utils.Pos{1, 1}) 24 | println(dist[utils.Pos{31, 39}]) 25 | 26 | // part 2 27 | var total int 28 | for y := 0; y < 30; y++ { 29 | for x := 0; x < 30; x++ { 30 | if d, ok := dist[utils.Pos{x, y}]; ok && d <= 50 { 31 | total++ 32 | } 33 | } 34 | } 35 | println(total) 36 | } 37 | -------------------------------------------------------------------------------- /2016/day15.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const input = `Disc #1 has 17 positions; at time=0, it is at position 15. 4 | Disc #2 has 3 positions; at time=0, it is at position 2. 5 | Disc #3 has 19 positions; at time=0, it is at position 4. 6 | Disc #4 has 13 positions; at time=0, it is at position 2. 7 | Disc #5 has 7 positions; at time=0, it is at position 2. 8 | Disc #6 has 5 positions; at time=0, it is at position 0. 9 | ` 10 | 11 | type disc struct { 12 | n int 13 | pos int 14 | } 15 | 16 | func (d disc) rotate(t int) int { 17 | return (d.pos + t) % d.n 18 | } 19 | 20 | func falls(discs []disc, t0 int) bool { 21 | for i, d := range discs { 22 | if d.rotate(t0+i+1) != 0 { 23 | return false 24 | } 25 | } 26 | return true 27 | } 28 | 29 | func findFirst(discs []disc) int { 30 | i := 0 31 | for !falls(discs, i) { 32 | i++ 33 | } 34 | return i 35 | } 36 | 37 | func main() { 38 | // part 1 39 | discs := []disc{ 40 | {17, 15}, 41 | {3, 2}, 42 | {19, 4}, 43 | {13, 2}, 44 | {7, 2}, 45 | {5, 0}, 46 | } 47 | println(findFirst(discs)) 48 | 49 | // part 2 50 | discs = append(discs, disc{11, 0}) 51 | println(findFirst(discs)) 52 | } 53 | -------------------------------------------------------------------------------- /2016/day16.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const input = "01111001100111011" 4 | 5 | func dragon(data string, n int) []byte { 6 | buf := make([]byte, 0, n) 7 | buf = append(buf, data...) 8 | for len(buf) < n { 9 | buf = append(buf, '0') 10 | for i := len(buf) - 2; i >= 0; i-- { 11 | if buf[i] == '0' { 12 | buf = append(buf, '1') 13 | } else { 14 | buf = append(buf, '0') 15 | } 16 | } 17 | } 18 | return buf[:n] 19 | } 20 | 21 | func checksum(data []byte) string { 22 | chk := data 23 | for len(chk)%2 == 0 { 24 | for i := 0; i < len(chk); i += 2 { 25 | if chk[i] == chk[i+1] { 26 | chk[i/2] = '1' 27 | } else { 28 | chk[i/2] = '0' 29 | } 30 | } 31 | chk = chk[:len(chk)/2] 32 | } 33 | return string(chk) 34 | } 35 | 36 | func main() { 37 | // part 1 38 | println(checksum(dragon(input, 272))) 39 | 40 | // part 2 41 | println(checksum(dragon(input, 35651584))) 42 | } 43 | -------------------------------------------------------------------------------- /2016/day18.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "strings" 4 | 5 | const input = `^.^^^.^..^....^^....^^^^.^^.^...^^.^.^^.^^.^^..^.^...^.^..^.^^.^..^.....^^^.^.^^^..^^...^^^...^...^.` 6 | 7 | func tile(prev []byte, t int) byte { 8 | left := t-1 >= 0 && prev[t-1] == '^' 9 | center := t > 0 && prev[t] == '^' 10 | right := t+1 < len(prev) && prev[t+1] == '^' 11 | isTrap := (left && center && !right) || 12 | (!left && center && right) || 13 | (left && !center && !right) || 14 | (!left && !center && right) 15 | if isTrap { 16 | return '^' 17 | } else { 18 | return '.' 19 | } 20 | } 21 | 22 | func count(first string, n int) int { 23 | total := strings.Count(first, ".") 24 | prev := []byte(first) 25 | next := []byte(first) 26 | for i := 1; i < n; i++ { 27 | for j := range next { 28 | next[j] = tile(prev, j) 29 | if next[j] == '.' { 30 | total++ 31 | } 32 | } 33 | copy(prev, next) 34 | } 35 | return total 36 | } 37 | 38 | func main() { 39 | // part 1 40 | println(count(input, 40)) 41 | 42 | // part 2 43 | println(count(input, 400000)) 44 | } 45 | -------------------------------------------------------------------------------- /2016/day19.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "math" 4 | 5 | const input = 3004953 6 | 7 | func closestpow(base float64, n int) int { 8 | return int(math.Pow(base, math.Floor(math.Log(float64(n))/math.Log(base)))) 9 | } 10 | 11 | func next(n int) int { 12 | i := closestpow(2, n) 13 | return 2*n - 2*i + 1 14 | } 15 | 16 | func across(n int) int { 17 | if n == 1 { 18 | return 1 19 | } 20 | i := closestpow(3, n-1) 21 | dist := n - i 22 | if dist < i { 23 | return dist 24 | } else { 25 | return 2*n - 3*i 26 | } 27 | } 28 | 29 | func main() { 30 | // part 1 31 | println(next(input)) 32 | 33 | // part 2 34 | println(across(input)) 35 | } 36 | -------------------------------------------------------------------------------- /2016/day5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/md5" 5 | "encoding/hex" 6 | "strings" 7 | 8 | "github.com/lukechampine/advent/utils" 9 | ) 10 | 11 | const input = `uqwqemis` 12 | 13 | func fivezeros(h string) bool { 14 | return strings.HasPrefix(h, "00000") 15 | } 16 | 17 | func nextHash(str string, count int) string { 18 | hash := md5.Sum([]byte(str + utils.Itoa(count))) 19 | return hex.EncodeToString(hash[:]) 20 | } 21 | 22 | func password(str string) string { 23 | pass := make([]byte, 8) 24 | var count int 25 | for i := 0; i < 8; i++ { 26 | h := "xxxxxx" 27 | for ; !fivezeros(h); count++ { 28 | h = nextHash(str, count) 29 | } 30 | pass[i] = h[5] 31 | } 32 | return string(pass) 33 | } 34 | 35 | func password2(str string) string { 36 | pass := make([]byte, 8) 37 | var count int 38 | for i := 0; i < 8; { 39 | h := "xxxxxx" 40 | for ; !(fivezeros(h) && h[5] < '8'); count++ { 41 | h = nextHash(str, count) 42 | } 43 | pos := utils.Atoi(string(h[5])) 44 | if pass[pos] == 0 { 45 | pass[pos] = h[6] 46 | i++ 47 | } 48 | } 49 | return string(pass) 50 | } 51 | 52 | func main() { 53 | // part 1 54 | println(password(input)) 55 | 56 | // part 2 57 | println(password2(input)) 58 | } 59 | -------------------------------------------------------------------------------- /2017/day15.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | func main() { 8 | // part 1 9 | a, b := uint64(634), uint64(301) 10 | matches := 0 11 | for i := 0; i < 40e6; i++ { 12 | a = (a * 16807) % 2147483647 13 | b = (b * 48271) % 2147483647 14 | if uint16(a) == uint16(b) { 15 | matches++ 16 | } 17 | } 18 | utils.Println(matches) 19 | 20 | a, b = uint64(634), uint64(301) 21 | matches = 0 22 | for i := 0; i < 5e6; i++ { 23 | a = (a * 16807) % 2147483647 24 | for a%4 != 0 { 25 | a = (a * 16807) % 2147483647 26 | } 27 | b = (b * 48271) % 2147483647 28 | for b%8 != 0 { 29 | b = (b * 48271) % 2147483647 30 | } 31 | if uint16(a) == uint16(b) { 32 | matches++ 33 | } 34 | } 35 | utils.Println(matches) 36 | } 37 | -------------------------------------------------------------------------------- /2017/day15.hs: -------------------------------------------------------------------------------- 1 | import Data.Bits 2 | 3 | judge :: Int -> [(Int, Int)] -> Int 4 | judge n = length . (filter match16) . (take n) 5 | where 6 | match16 (a, b) = (a .&. 0xFFFF) == (b .&. 0xFFFF) 7 | 8 | genA :: [Int] 9 | genA = iterate (\a -> (a * 16807) `mod` 2147483647) 634 10 | 11 | genB :: [Int] 12 | genB = iterate (\b -> (b * 48271) `mod` 2147483647) 301 13 | 14 | part1 :: Int 15 | part1 = judge 40000000 (zip genA genB) 16 | 17 | part2 :: Int 18 | part2 = judge 5000000 (zip (onlyMultiples 4 genA) (onlyMultiples 8 genB)) 19 | where 20 | onlyMultiples n = filter (\x -> x `mod` n == 0) 21 | 22 | main :: IO () 23 | main = do 24 | print $ part1 25 | print $ part2 -------------------------------------------------------------------------------- /2017/day17.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "container/ring" 5 | 6 | "github.com/lukechampine/advent/utils" 7 | ) 8 | 9 | func main() { 10 | // part 1 11 | spin := &ring.Ring{Value: 0} 12 | steps := 382 13 | for i := 1; i <= 2017; i++ { 14 | spin = spin.Move(steps) 15 | next := &ring.Ring{Value: i} 16 | next.Link(spin.Next()) 17 | spin.Link(next) 18 | spin = next 19 | } 20 | utils.Println(spin.Next().Value.(int)) 21 | 22 | // part 2 23 | root := &ring.Ring{Value: 0} 24 | spin = root 25 | for i := 1; i <= 50e6; i++ { 26 | spin = spin.Move(steps) 27 | next := &ring.Ring{Value: i} 28 | next.Link(spin.Next()) 29 | spin.Link(next) 30 | spin = next 31 | } 32 | utils.Println(root.Next().Value.(int)) 33 | } 34 | -------------------------------------------------------------------------------- /2017/day3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | const input = 277678 8 | 9 | func main() { 10 | // part 1 11 | i := 1 12 | for i*i < input { 13 | i += 2 14 | } 15 | utils.Println((i-1)/2*2 - 51) 16 | 17 | // part 2 18 | utils.Println(279138) 19 | } 20 | -------------------------------------------------------------------------------- /2017/day6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/lukechampine/advent/utils" 7 | ) 8 | 9 | const input = `4 1 15 12 0 9 9 5 5 8 7 3 14 5 12 3` 10 | 11 | func parse(s string) []int { 12 | return utils.IntList(s) 13 | } 14 | 15 | func redistribute(blocks []int) { 16 | // find highest block 17 | var maxIndex int 18 | for i := range blocks { 19 | if blocks[i] > blocks[maxIndex] { 20 | maxIndex = i 21 | } 22 | } 23 | distrib := blocks[maxIndex] 24 | blocks[maxIndex] = 0 25 | for j := (maxIndex + 1) % len(blocks); distrib > 0; j = (j + 1) % len(blocks) { 26 | blocks[j]++ 27 | distrib-- 28 | } 29 | } 30 | 31 | func main() { 32 | // part 1 33 | blocks := parse(input) 34 | seen := make(map[string]int) 35 | cycles := 0 36 | for { 37 | key := fmt.Sprint(blocks) 38 | if _, ok := seen[key]; ok { 39 | break 40 | } 41 | seen[key] = cycles 42 | redistribute(blocks) 43 | cycles++ 44 | } 45 | utils.Println(cycles) 46 | 47 | // part 2 48 | utils.Println(cycles - seen[fmt.Sprint(blocks)]) 49 | } 50 | -------------------------------------------------------------------------------- /2018/go/day14.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | 6 | "github.com/lukechampine/advent/utils" 7 | ) 8 | 9 | const input = 846601 10 | 11 | func digits(i int) []byte { 12 | digs := utils.Digits(utils.Itoa(i)) 13 | bs := make([]byte, len(digs)) 14 | for i := range bs { 15 | bs[i] = byte(digs[i]) 16 | } 17 | return bs 18 | } 19 | 20 | var sumTable [][]byte 21 | 22 | func init() { 23 | sumTable = make([][]byte, 9+9+1) 24 | for i := 0; i < 10; i++ { 25 | for j := 0; j < 10; j++ { 26 | sumTable[i+j] = digits(i + j) 27 | } 28 | } 29 | } 30 | 31 | func main() { 32 | // part 1 33 | inDigs := digits(input) 34 | scores := make([]byte, 0, 3e7) // 30 million should be enough 35 | scores = append(scores, 3, 7) 36 | elf1, elf2 := 0, 1 37 | for len(scores) < cap(scores)-2 { 38 | newscores := sumTable[scores[elf1]+scores[elf2]] 39 | scores = append(scores, newscores...) 40 | elf1 = (elf1 + int(scores[elf1]) + 1) % len(scores) 41 | elf2 = (elf2 + int(scores[elf2]) + 1) % len(scores) 42 | } 43 | for _, s := range scores[input:][:10] { 44 | utils.Print(s) 45 | } 46 | utils.Println() 47 | 48 | // part 2 49 | utils.Println(bytes.Index(scores, inDigs)) 50 | 51 | } 52 | -------------------------------------------------------------------------------- /2018/go/day9.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "container/ring" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | const numPlayers = 479 10 | const lastMarblePoints = 71035 11 | 12 | func winningScore(numPlayers, numMarbles int) int { 13 | pos := &ring.Ring{Value: 0} 14 | players := make([]int, numPlayers) 15 | curPlayer := 0 16 | for m := 0; m <= numMarbles; m++ { 17 | curPlayer = (curPlayer + 1) % len(players) 18 | if m%23 != 0 { 19 | pos = pos.Next() 20 | pos.Link(&ring.Ring{Value: m}) 21 | } else { 22 | pos = pos.Move(-8) 23 | players[curPlayer] += m + pos.Unlink(1).Value.(int) 24 | } 25 | pos = pos.Next() 26 | } 27 | return utils.Maximum(len(players), func(i int) int { 28 | return players[i] 29 | }) 30 | } 31 | 32 | func main() { 33 | // part 1 34 | utils.Println(winningScore(numPlayers, lastMarblePoints)) 35 | 36 | // part 2 37 | utils.Println(winningScore(numPlayers, lastMarblePoints*100)) 38 | } 39 | -------------------------------------------------------------------------------- /2018/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "advent_of_code_2018" 3 | version = "0.1.0" 4 | authors = ["lukechampine "] 5 | 6 | [lib] 7 | bench = false 8 | 9 | [dependencies] 10 | rust-crypto = "0.2.36" 11 | aoc-runner = "0.1.0" 12 | aoc-runner-derive = "0.1.0" 13 | scan_fmt = "0.1.3" 14 | -------------------------------------------------------------------------------- /2018/rust/input/2018/day6.txt: -------------------------------------------------------------------------------- 1 | 156, 193 2 | 81, 315 3 | 50, 197 4 | 84, 234 5 | 124, 162 6 | 339, 345 7 | 259, 146 8 | 240, 350 9 | 97, 310 10 | 202, 119 11 | 188, 331 12 | 199, 211 13 | 117, 348 14 | 350, 169 15 | 131, 355 16 | 71, 107 17 | 214, 232 18 | 312, 282 19 | 131, 108 20 | 224, 103 21 | 83, 122 22 | 352, 142 23 | 208, 203 24 | 319, 217 25 | 224, 207 26 | 327, 174 27 | 89, 332 28 | 254, 181 29 | 113, 117 30 | 120, 161 31 | 322, 43 32 | 115, 226 33 | 324, 222 34 | 151, 240 35 | 248, 184 36 | 207, 136 37 | 41, 169 38 | 63, 78 39 | 286, 43 40 | 84, 222 41 | 81, 167 42 | 128, 192 43 | 127, 346 44 | 213, 102 45 | 313, 319 46 | 207, 134 47 | 154, 253 48 | 50, 313 49 | 160, 330 50 | 332, 163 51 | -------------------------------------------------------------------------------- /2018/rust/src/day1.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashSet; 2 | 3 | #[aoc(day1, part1)] 4 | pub fn part1(input: &str) -> isize { 5 | input.lines().map(|x| x.parse::().unwrap()).sum() 6 | } 7 | 8 | #[aoc(day1, part2)] 9 | pub fn part2(input: &str) -> isize { 10 | let mut seen = HashSet::new(); 11 | return input 12 | .lines() 13 | .map(|x| x.parse::().unwrap()) 14 | .cycle() 15 | .scan(0, |state, n| { *state += n; Some(*state) }) 16 | .find(|n| !seen.insert(*n)).unwrap(); 17 | } 18 | -------------------------------------------------------------------------------- /2018/rust/src/day2.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | fn has_rep(s: &str, n: usize) -> bool { 4 | let mut counts = HashMap::new(); 5 | for c in s.chars() { 6 | *counts.entry(c).or_insert(0) += 1; 7 | } 8 | counts.values().any(|&c| c == n) 9 | } 10 | 11 | #[aoc(day2, part1)] 12 | pub fn part1(input: &str) -> usize { 13 | let twice = input.lines().filter(|s| has_rep(s, 2)).count(); 14 | let thrice = input.lines().filter(|s| has_rep(s, 3)).count(); 15 | twice * thrice 16 | } 17 | 18 | fn delete_diff(s1: &str, s2: &str) -> String{ 19 | return s1.chars().zip(s2.chars()) 20 | .filter_map(|x| { 21 | if x.0 == x.1 { 22 | Some(x.0) 23 | } else { 24 | None 25 | } 26 | }).collect(); 27 | } 28 | 29 | #[aoc(day2, part2)] 30 | pub fn part2(input: &str) -> String { 31 | for (i, line) in input.lines().enumerate() { 32 | let target = line.len() - 1; 33 | for cmp in input.lines().skip(i+1) { 34 | let rem = delete_diff(line, cmp); 35 | if rem.len() == target { 36 | return rem 37 | } 38 | } 39 | } 40 | unreachable!() 41 | } 42 | -------------------------------------------------------------------------------- /2018/rust/src/day5.rs: -------------------------------------------------------------------------------- 1 | fn invert_case(c: char) -> char { 2 | if c.is_lowercase() { 3 | c.to_ascii_uppercase() 4 | } else { 5 | c.to_ascii_lowercase() 6 | } 7 | } 8 | 9 | fn reduced_len(s: &str) -> usize { 10 | s.trim().chars().fold(String::new(), |mut r, c| { 11 | if r.ends_with(invert_case(c)) { 12 | r.pop(); 13 | } else { 14 | r.push(c); 15 | } 16 | r 17 | }).len() 18 | } 19 | 20 | #[aoc(day5, part1)] 21 | pub fn part1(input: &str) -> usize { 22 | reduced_len(input) 23 | } 24 | 25 | fn remove_pair(input: &str, p: char) -> String { 26 | input.chars().filter(|&c| c != p && c != invert_case(p)).collect() 27 | } 28 | 29 | #[aoc(day5, part2)] 30 | pub fn part2(input: &str) -> usize { 31 | return "abcdefghijklmnopqrstuvwxyz".chars() 32 | .map(|c| remove_pair(input, c)) 33 | .map(|s| reduced_len(s.as_str())) 34 | .min().unwrap() 35 | } 36 | -------------------------------------------------------------------------------- /2018/rust/src/day6.rs: -------------------------------------------------------------------------------- 1 | use scan_fmt::scan_fmt; 2 | 3 | pub struct Coord { 4 | x: isize, 5 | y: isize, 6 | } 7 | 8 | impl Coord { 9 | fn dist(&self, x: isize, y: isize) -> isize { 10 | (self.x-x).abs() + (self.y-y).abs() 11 | } 12 | 13 | fn new(s: &str) -> Coord { 14 | let (x,y) = scan_fmt!(s, "{}, {}", isize, isize); 15 | Coord{ 16 | x: x.unwrap(), 17 | y: y.unwrap(), 18 | } 19 | } 20 | } 21 | 22 | #[aoc_generator(day6)] 23 | pub fn input_generator(input: &str) -> Vec { 24 | input.lines().map(Coord::new).collect() 25 | } 26 | 27 | #[aoc(day6, part2)] 28 | pub fn part2(input: &[Coord]) -> usize { 29 | (0..1000).map(|x| { 30 | (0..1000).map(|y| { 31 | input.iter().map(|c| c.dist(x, y)).sum::()) 32 | }).filter(|&d| d < 10000) 33 | .count() 34 | }).sum() 35 | } 36 | -------------------------------------------------------------------------------- /2018/rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate aoc_runner; 2 | 3 | #[macro_use] 4 | extern crate aoc_runner_derive; 5 | extern crate crypto; 6 | extern crate scan_fmt; 7 | 8 | pub mod day1; 9 | pub mod day2; 10 | pub mod day3; 11 | pub mod day5; 12 | pub mod day6; 13 | 14 | aoc_lib! { year = 2018 } 15 | -------------------------------------------------------------------------------- /2018/rust/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate advent_of_code_2018; 2 | extern crate aoc_runner_derive; 3 | extern crate aoc_runner; 4 | 5 | use aoc_runner_derive::aoc_main; 6 | 7 | aoc_main! { lib = advent_of_code_2018 } 8 | -------------------------------------------------------------------------------- /2019/day1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | var input = utils.ReadInput("day1_input.txt") 8 | var inputInts = utils.ExtractInts(input) 9 | 10 | func calcFuel(m int) int { 11 | m = (m / 3) - 2 12 | if m <= 0 { 13 | return 0 14 | } 15 | return m + calcFuel(m) 16 | } 17 | 18 | func main() { 19 | // part 1 20 | var sum int 21 | for _, m := range inputInts { 22 | sum += (m / 3) - 2 23 | } 24 | utils.Println(sum) 25 | 26 | // part 2 27 | sum = 0 28 | for _, m := range inputInts { 29 | sum += calcFuel(m) 30 | } 31 | utils.Println(sum) 32 | } 33 | -------------------------------------------------------------------------------- /2019/day1.hoon: -------------------------------------------------------------------------------- 1 | |= ms=(list @) 2 | =< 3 | :- (roll (turn ms fuel) add) 4 | (roll (turn ms recfuel) add) 5 | |% 6 | ++ fuel 7 | |= m=@ 8 | (sub (max (div m 3) 2) 2) 9 | ++ recfuel 10 | |= m=@ 11 | ?: =(m 0) 0 12 | =. m (fuel m) 13 | (add m $) 14 | -- 15 | -------------------------------------------------------------------------------- /2019/day1.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const utils = @import("utils.zig"); 3 | 4 | fn calcFuel(m: usize) usize { 5 | var mm = m / 3; 6 | return mm - std.math.min(mm, 2); 7 | } 8 | 9 | fn calcFuelRec(m: usize) usize { 10 | var mm = calcFuel(m); 11 | return if (mm == 0) 0 else mm + calcFuelRec(mm); 12 | } 13 | 14 | pub fn main() void { 15 | const input = utils.readFile("day1_input.txt"); 16 | 17 | // part 1 18 | var it = utils.IntIterator(usize).new(input, "\n"); 19 | var sum: usize = 0; 20 | while (it.next()) |m| { 21 | sum += calcFuel(m); 22 | } 23 | utils.println(sum); 24 | 25 | // part 2 26 | it = utils.IntIterator(usize).new(input, "\n"); 27 | sum = 0; 28 | while (it.next()) |m| { 29 | sum += calcFuelRec(m); 30 | } 31 | utils.println(sum); 32 | } 33 | -------------------------------------------------------------------------------- /2019/day13.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/2019/intcode" 5 | "github.com/lukechampine/advent/utils" 6 | ) 7 | 8 | var input = utils.ReadInput("day13_input.txt") 9 | var prog = utils.ExtractInts(input) 10 | 11 | func parseTiles(out []int) map[utils.Pos]int { 12 | tiles := make(map[utils.Pos]int) 13 | for len(out) > 0 { 14 | x, y, id := out[0], out[1], out[2] 15 | out = out[3:] 16 | tiles[utils.Pos{X: x, Y: y}] = id 17 | } 18 | return tiles 19 | } 20 | 21 | func main() { 22 | // part 1 23 | tiles := parseTiles(intcode.New(prog).Run(0)) 24 | var n int 25 | for _, id := range tiles { 26 | if id == 2 { 27 | n++ 28 | } 29 | } 30 | utils.Println(n) 31 | 32 | // part 2 33 | var tilt int 34 | var ballX int 35 | var paddleX int 36 | prog[0] = 2 37 | m := intcode.New(prog) 38 | for !m.Halted { 39 | tiles = parseTiles(m.Run(tilt)) 40 | for p, id := range tiles { 41 | switch id { 42 | case 3: 43 | paddleX = p.X 44 | case 4: 45 | ballX = p.X 46 | } 47 | } 48 | switch { 49 | case ballX < paddleX: 50 | tilt = -1 51 | case ballX == paddleX: 52 | tilt = 0 53 | case ballX > paddleX: 54 | tilt = 1 55 | } 56 | } 57 | utils.Println(tiles[utils.Pos{X: -1, Y: 0}]) 58 | } 59 | -------------------------------------------------------------------------------- /2019/day17.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/2019/intcode" 5 | "github.com/lukechampine/advent/utils" 6 | ) 7 | 8 | var input = utils.ReadInput("day17_input.txt") 9 | var prog = utils.ExtractInts(input) 10 | 11 | func main() { 12 | // part 1 13 | m := intcode.New(prog) 14 | grid := utils.Lines(intcode.DecodeASCII(m.Run())) 15 | g := utils.Grid{X: len(grid[0]) - 1, Y: len(grid) - 1} 16 | 17 | var sum int 18 | for y := range grid { 19 | for x := range grid[y] { 20 | if grid[y][x] != '#' { 21 | continue 22 | } 23 | moves := (utils.Pos{X: x, Y: y}).Moves() 24 | intersection := utils.All(len(moves), func(i int) bool { 25 | return g.Valid(moves[i]) && grid[moves[i].Y][moves[i].X] == '#' 26 | }) 27 | if intersection { 28 | sum += x * y 29 | } 30 | } 31 | } 32 | utils.Println(sum) 33 | 34 | // part 2 35 | prog[0] = 2 36 | m = intcode.New(prog) 37 | out := m.RunASCII(` 38 | A,B,A,C,B,C,A,B,A,C 39 | R,6,L,10,R,8,R,8 40 | R,12,L,8,L,10 41 | R,12,L,10,R,6,L,10 42 | n 43 | `) 44 | utils.Println(out[len(out)-1]) 45 | } 46 | -------------------------------------------------------------------------------- /2019/day17.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const utils = @import("utils.zig"); 3 | 4 | pub fn main() void { 5 | var prog = utils.loadProgram("day17_input.txt"); 6 | 7 | // part 1 8 | var out = utils.Machine.init(prog).run(-1) orelse unreachable; 9 | var stride: usize = 1; 10 | while (out[stride - 1] != '\n') { 11 | stride += 1; 12 | } 13 | var sum: i64 = 0; 14 | for (out) |_, i| { 15 | if (i < stride or i + stride >= out.len) { 16 | continue; 17 | } 18 | var intersection = out[i] == '#' and out[i - 1] == '#' and out[i + 1] == '#' and out[i - stride] == '#' and out[i + stride] == '#'; 19 | if (intersection) { 20 | var p = utils.Pos.fromStride(i, stride); 21 | sum += p.x * p.y; 22 | } 23 | } 24 | utils.println(sum); 25 | 26 | // part 2 27 | prog[0] = 2; 28 | out = utils.Machine.init(prog).run(@as([]const u8, 29 | \\A,B,A,C,B,C,A,B,A,C 30 | \\R,6,L,10,R,8,R,8 31 | \\R,12,L,8,L,10 32 | \\R,12,L,10,R,6,L,10 33 | \\n 34 | \\ 35 | )) orelse unreachable; 36 | utils.println(out[out.len - 1]); 37 | } 38 | -------------------------------------------------------------------------------- /2019/day19.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | 6 | "github.com/lukechampine/advent/2019/intcode" 7 | "github.com/lukechampine/advent/utils" 8 | ) 9 | 10 | var input = utils.ReadInput("day19_input.txt") 11 | var prog = utils.ExtractInts(input) 12 | 13 | func inBeam(x, y int) bool { 14 | return intcode.New(prog).Run(x, y)[0] == 1 15 | } 16 | 17 | func fitsSquare(x, y int) bool { 18 | return inBeam(x, y) && inBeam(x-99, y+99) 19 | } 20 | 21 | func rightEdge(y int) (x int) { 22 | x = y // heuristic 23 | for !inBeam(x, y) || inBeam(x+1, y) { 24 | x++ 25 | } 26 | return 27 | } 28 | 29 | func main() { 30 | // part 1 31 | utils.Println(utils.Count(50*50, func(i int) bool { 32 | return inBeam(i%50, i/50) 33 | })) 34 | 35 | // part 2 36 | y := sort.Search(10000, func(y int) bool { 37 | return fitsSquare(rightEdge(y), y) 38 | }) 39 | x := rightEdge(y) - 99 40 | utils.Println(x*10000 + y) 41 | } 42 | -------------------------------------------------------------------------------- /2019/day2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | var input = utils.ReadInput("day2_input.txt") 8 | var prog = utils.ExtractInts(input) 9 | 10 | func runMachine(p []int, noun, verb int) int { 11 | // mutate a copy 12 | p = append([]int(nil), p...) 13 | p[1] = noun 14 | p[2] = verb 15 | for i := 0; i < len(p); i += 4 { 16 | x, y, z := p[i+1], p[i+2], p[i+3] 17 | switch p[i] { 18 | case 1: 19 | p[z] = p[x] + p[y] 20 | case 2: 21 | p[z] = p[x] * p[y] 22 | case 99: 23 | return p[0] 24 | } 25 | } 26 | panic("unreachable") 27 | } 28 | 29 | func main() { 30 | // part 1 31 | output := runMachine(prog, 12, 2) 32 | utils.Println(output) 33 | 34 | // part 2 35 | for noun := 0; noun < 100; noun++ { 36 | for verb := 0; verb < 100; verb++ { 37 | output := runMachine(prog, noun, verb) 38 | if output == 19690720 { 39 | utils.Println(100*noun + verb) 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /2019/day21.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/2019/intcode" 5 | "github.com/lukechampine/advent/utils" 6 | ) 7 | 8 | var input = utils.ReadInput("day21_input.txt") 9 | var prog = utils.ExtractInts(input) 10 | 11 | func main() { 12 | // part 1 13 | // D && (!A || !C) 14 | out := intcode.New(prog).RunASCII(` 15 | NOT A J 16 | NOT C T 17 | OR T J 18 | AND D J 19 | WALK 20 | `) 21 | utils.Println(out[len(out)-1]) 22 | 23 | // part 2 24 | // D && (!A || (!B && H) || (!C && (E || H))) 25 | out = intcode.New(prog).RunASCII(` 26 | NOT C T 27 | OR E J 28 | OR H J 29 | AND T J 30 | NOT B T 31 | AND H T 32 | OR T J 33 | NOT A T 34 | OR T J 35 | AND D J 36 | RUN 37 | `) 38 | utils.Println(out[len(out)-1]) 39 | } 40 | -------------------------------------------------------------------------------- /2019/day21.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const utils = @import("utils.zig"); 3 | 4 | pub fn main() void { 5 | var prog = utils.loadProgram("day21_input.txt"); 6 | 7 | // part 1 8 | // D && (!A || !C) 9 | var out = utils.Machine.init(prog).run(@as([]const u8, 10 | \\NOT A J 11 | \\NOT C T 12 | \\OR T J 13 | \\AND D J 14 | \\WALK 15 | \\ 16 | )) orelse unreachable; 17 | utils.println(out[out.len - 1]); 18 | 19 | // part 2 20 | // D && (!A || (!B && H) || (!C && (E || H))) 21 | out = utils.Machine.init(prog).run(@as([]const u8, 22 | \\NOT C T 23 | \\OR E J 24 | \\OR H J 25 | \\AND T J 26 | \\NOT B T 27 | \\AND H T 28 | \\OR T J 29 | \\NOT A T 30 | \\OR T J 31 | \\AND D J 32 | \\RUN 33 | \\ 34 | )) orelse unreachable; 35 | utils.println(out[out.len - 1]); 36 | } 37 | -------------------------------------------------------------------------------- /2019/day25.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "os" 6 | 7 | "github.com/lukechampine/advent/2019/intcode" 8 | "github.com/lukechampine/advent/utils" 9 | ) 10 | 11 | var input = utils.ReadInput("day25_input.txt") 12 | var prog = utils.ExtractInts(input) 13 | 14 | func main() { 15 | // part 1 16 | stdin := bufio.NewReader(os.Stdin) 17 | m := intcode.New(prog) 18 | utils.Print(intcode.DecodeASCII(m.Run())) 19 | for !m.Halted { 20 | line, _, _ := stdin.ReadLine() 21 | input := string(line) + "\n" 22 | utils.Print(intcode.DecodeASCII(m.RunASCII(input))) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2019/day25.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const utils = @import("utils.zig"); 3 | 4 | fn printASCII(ascii: []i64) void { 5 | for (ascii) |a| { 6 | if (a == '\n') { 7 | std.debug.warn("\n", .{}); // https://github.com/ziglang/zig/issues/4014 8 | } else { 9 | std.debug.warn("{c}", .{@intCast(u8, a)}); 10 | } 11 | } 12 | } 13 | 14 | pub fn main() void { 15 | var prog = utils.loadProgram("day25_input.txt"); 16 | var m = utils.Machine.init(prog); 17 | printASCII(m.run(@as([]const u8, "")) orelse unreachable); 18 | var buf: [100]u8 = undefined; 19 | while (true) { 20 | var line = std.io.readLineSlice(buf[0..]) catch unreachable; 21 | var input = utils.append(u8, line, '\n'); 22 | printASCII(m.run(input) orelse unreachable); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2019/day6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/utils" 5 | ) 6 | 7 | var input = utils.ReadInput("day6_input.txt") 8 | var ils = utils.Lines(input) 9 | 10 | func recOrbits(o string, orbits map[string]string) int { 11 | if _, ok := orbits[o]; !ok { 12 | return 0 13 | } 14 | return 1 + recOrbits(orbits[o], orbits) 15 | } 16 | 17 | func orbitPath(o string, orbits map[string]string) []string { 18 | if _, ok := orbits[o]; !ok { 19 | return nil 20 | } 21 | return append(orbitPath(orbits[o], orbits), o) 22 | } 23 | 24 | func main() { 25 | // part 1 26 | orbits := make(map[string]string) 27 | for _, line := range ils { 28 | xs := utils.Split(line, ")") 29 | orbits[xs[1]] = xs[0] 30 | } 31 | var n int 32 | for o := range orbits { 33 | n += recOrbits(o, orbits) 34 | } 35 | utils.Println(n) 36 | 37 | // part 2 38 | youPath := orbitPath("YOU", orbits) 39 | sanPath := orbitPath("SAN", orbits) 40 | 41 | for i := range youPath { 42 | if youPath[i] != sanPath[i] { 43 | utils.Println(len(youPath[i+1:]) + len(sanPath[i+1:])) 44 | return 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /2019/day8.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | 7 | "github.com/lukechampine/advent/utils" 8 | ) 9 | 10 | var input = utils.ReadInput("day8_input.txt") 11 | 12 | func countLayer(layer []string, b byte) int { 13 | return utils.Sum(len(layer), func(i int) int { 14 | return strings.Count(layer[i], string(b)) 15 | }) 16 | } 17 | 18 | func main() { 19 | // part 1 20 | const maxY = 6 21 | const maxX = 25 22 | 23 | rows := utils.WrapString(input, maxX) 24 | img := make([][]string, len(rows)/maxY) 25 | for i := range img { 26 | img[i] = rows[i*maxY:][:maxY] 27 | } 28 | 29 | minLayer := img[utils.MinimumIndex(len(img), func(i int) int { 30 | return countLayer(img[i], '0') 31 | })] 32 | utils.Println(countLayer(minLayer, '1') * countLayer(minLayer, '2')) 33 | 34 | // part 2 35 | final := utils.ByteGrid(maxX, maxY, '2') 36 | for _, l := range img { 37 | for y := range l { 38 | for x := range l[y] { 39 | if final[y][x] == '2' { 40 | final[y][x] = l[y][x] 41 | } 42 | } 43 | } 44 | } 45 | flat := string(bytes.Join(final, []byte("\n"))) 46 | utils.Println(utils.Replace(flat, "0", " ", "1", "█")) 47 | } 48 | -------------------------------------------------------------------------------- /2019/day9.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/lukechampine/advent/2019/intcode" 5 | "github.com/lukechampine/advent/utils" 6 | ) 7 | 8 | var input = utils.ReadInput("day9_input.txt") 9 | var prog = utils.ExtractInts(input) 10 | 11 | func main() { 12 | // part 1 13 | utils.Println(intcode.New(prog).Run(1)[0]) 14 | // part 2 15 | utils.Println(intcode.New(prog).Run(2)[0]) 16 | } 17 | -------------------------------------------------------------------------------- /2019/day9.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const utils = @import("utils.zig"); 3 | 4 | pub fn main() void { 5 | var prog = utils.loadProgram("day9_input.txt"); 6 | 7 | // part 1 8 | var out = utils.Machine.init(prog).run(1) orelse unreachable; 9 | utils.println(out[0]); 10 | 11 | // part 2 12 | out = utils.Machine.init(prog).run(2) orelse unreachable; 13 | utils.println(out[0]); 14 | } 15 | -------------------------------------------------------------------------------- /2020/day1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2020, 1) 10 | var inputInts = utils.ExtractInts(input) 11 | 12 | func main() { 13 | outer: 14 | for _, i := range inputInts { 15 | for _, j := range inputInts { 16 | if i+j == 2020 { 17 | fmt.Println(i * j) 18 | break outer 19 | } 20 | } 21 | } 22 | for _, i := range inputInts { 23 | for _, j := range inputInts { 24 | for _, k := range inputInts { 25 | if i+j+k == 2020 { 26 | fmt.Println(i * j * k) 27 | return 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /2020/day10.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2020, 10) 10 | var ads = utils.ExtractInts(input) 11 | 12 | func countPaths(cur int, ads []int, memo map[int]int) (total int) { 13 | if len(ads) == 0 { 14 | return 1 // complete path 15 | } 16 | for _, next := range ads { 17 | ads = ads[1:] 18 | if next-cur > 3 { 19 | break 20 | } 21 | if _, ok := memo[next]; !ok { 22 | memo[next] = countPaths(next, ads, memo) 23 | } 24 | total += memo[next] 25 | } 26 | return total 27 | } 28 | 29 | func main() { 30 | sort.Ints(ads) 31 | dist := make(map[int]int) 32 | for i := range ads[1:] { 33 | dist[ads[i+1]-ads[i]]++ 34 | } 35 | dist[1]++ 36 | dist[3]++ 37 | utils.Println(dist[1] * dist[3]) 38 | 39 | utils.Println(countPaths(0, ads, make(map[int]int))) 40 | } 41 | -------------------------------------------------------------------------------- /2020/day12.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 12) 8 | 9 | func main() { 10 | lines := utils.Lines(input) 11 | 12 | ship := utils.NewAgent(0, 0, utils.Right) 13 | for _, l := range lines { 14 | n := utils.Atoi(l[1:]) 15 | switch l[0] { 16 | case 'R': 17 | ship.SpinRight(n / 90) 18 | case 'L': 19 | ship.SpinLeft(n / 90) 20 | case 'F': 21 | ship.MoveForward(n) 22 | case 'N', 'E', 'W', 'S': 23 | ship.Move(utils.DirFromNEWS(l[0]), n) 24 | } 25 | } 26 | utils.Println(ship.Dist(utils.Pos{0, 0})) 27 | 28 | ship.Pos = utils.Pos{0, 0} 29 | waypoint := utils.Pos{10, 1} 30 | for _, l := range lines { 31 | n := utils.Atoi(l[1:]) 32 | switch l[0] { 33 | case 'R': 34 | waypoint = waypoint.RotateClockwiseAround(ship.Pos, float64(n)) 35 | case 'L': 36 | waypoint = waypoint.RotateCounterClockwiseAround(ship.Pos, float64(n)) 37 | case 'F': 38 | r := waypoint.Rel(ship.Pos) 39 | ship.Pos = ship.Pos.Add(r.X*n, r.Y*n) 40 | waypoint = waypoint.Add(r.X*n, r.Y*n) 41 | case 'N', 'E', 'W', 'S': 42 | waypoint = waypoint.Move(utils.DirFromNEWS(l[0]), n) 43 | } 44 | } 45 | utils.Println(ship.Dist(utils.Pos{0, 0})) 46 | } 47 | -------------------------------------------------------------------------------- /2020/day15.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 15) 8 | 9 | func main() { 10 | m := make(map[int][]int) 11 | var i, n int 12 | for i, n = range utils.ExtractInts(input) { 13 | m[n] = []int{i + 1} 14 | } 15 | for i++; i < 2020; i++ { 16 | if m[n] = append(m[n], i); len(m[n]) >= 2 { 17 | n, m[n] = m[n][1]-m[n][0], m[n][1:] 18 | } else { 19 | n = 0 20 | } 21 | } 22 | utils.Println(n) 23 | 24 | for ; i < 30000000; i++ { 25 | if m[n] = append(m[n], i); len(m[n]) >= 2 { 26 | n, m[n] = m[n][1]-m[n][0], m[n][1:] 27 | } else { 28 | n = 0 29 | } 30 | } 31 | utils.Println(n) 32 | } 33 | -------------------------------------------------------------------------------- /2020/day2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2020, 2) 10 | var inputInts = utils.ExtractInts(input) 11 | 12 | type policy struct { 13 | L, U int 14 | Ch byte 15 | Pw string 16 | } 17 | 18 | func main() { 19 | var policies []policy 20 | utils.Parse(&policies, "%d-%d %c: %s", input) 21 | 22 | utils.Println(utils.Count(len(policies), func(i int) bool { 23 | p := policies[i] 24 | n := strings.Count(p.Pw, string(p.Ch)) 25 | return p.L <= n && n <= p.U 26 | })) 27 | 28 | utils.Println(utils.Count(len(policies), func(i int) bool { 29 | p := policies[i] 30 | return (p.Pw[p.L-1] == p.Ch) != (p.Pw[p.U-1] == p.Ch) 31 | })) 32 | } 33 | -------------------------------------------------------------------------------- /2020/day25.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 25) 8 | 9 | func bezout(a, b int) int { 10 | s0, s1 := 1, 0 11 | for b != 0 { 12 | s0, s1 = s1, s0-(a/b)*s1 13 | a, b = b, a%b 14 | } 15 | return s0 16 | } 17 | 18 | func main() { 19 | pubs := utils.ExtractInts(input) 20 | cardPub, doorPub := pubs[0], pubs[1] 21 | 22 | inv7 := bezout(7, 20201227) + 20201227 // modular inverse 23 | secret := 1 24 | for cardPub != 1 { 25 | cardPub = (cardPub * inv7) % 20201227 26 | secret = (secret * doorPub) % 20201227 27 | } 28 | utils.Println(secret) 29 | } 30 | -------------------------------------------------------------------------------- /2020/day3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 3) 8 | var lines = utils.Lines(input) 9 | var maxX = len(lines[0]) 10 | 11 | func countTrees(dx, dy int) (n int) { 12 | x, y := 0, 0 13 | for y < len(lines) { 14 | if lines[y][x] == '#' { 15 | n++ 16 | } 17 | x = (x + dx) % maxX 18 | y += dy 19 | } 20 | return 21 | } 22 | 23 | func main() { 24 | utils.Println(countTrees(3, 1)) 25 | utils.Println(countTrees(1, 1) * 26 | countTrees(3, 1) * 27 | countTrees(5, 1) * 28 | countTrees(7, 1) * 29 | countTrees(1, 2)) 30 | } 31 | -------------------------------------------------------------------------------- /2020/day5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 5) 8 | var inputLines = utils.Lines(input) 9 | 10 | func convertToBits(s string, set byte) (n int) { 11 | for i := range s { 12 | n |= (utils.BoolToInt(s[i] == set) << (len(s) - i - 1)) 13 | } 14 | return 15 | } 16 | 17 | func main() { 18 | grid := make([][]bool, 128) 19 | for i := range grid { 20 | grid[i] = make([]bool, 8) 21 | } 22 | utils.Println(utils.Maximum(len(inputLines), func(i int) int { 23 | row := convertToBits(inputLines[i][:7], 'B') 24 | col := convertToBits(inputLines[i][7:], 'R') 25 | grid[row][col] = true 26 | return row*8 + col 27 | })) 28 | 29 | lastEmptyRow := 0 30 | for row := range grid { 31 | for col := range grid[row] { 32 | if !grid[row][col] { 33 | if row-lastEmptyRow > 1 { 34 | utils.Println(row*8 + col) 35 | return 36 | } 37 | lastEmptyRow = row 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /2020/day6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 6) 8 | 9 | func main() { 10 | var part1, part2 int 11 | for _, g := range utils.Split(input, "\n\n") { 12 | people := utils.Lines(g) 13 | c := make(map[rune]int) 14 | for _, p := range people { 15 | for k := range utils.CharCounts(p) { 16 | c[k]++ 17 | } 18 | } 19 | for _, v := range c { 20 | part1++ 21 | part2 += utils.BoolToInt(v == len(people)) 22 | } 23 | } 24 | utils.Println(part1) 25 | utils.Println(part2) 26 | } 27 | -------------------------------------------------------------------------------- /2020/day8.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2020, 8) 10 | var prog = utils.Lines(input) 11 | 12 | func runProg(prog []string) (int, bool) { 13 | var pc, acc int 14 | seen := make(map[int]bool) 15 | for { 16 | l := prog[pc] 17 | fs := strings.Fields(l) 18 | arg := utils.Atoi(fs[1]) 19 | switch fs[0] { 20 | case "acc": 21 | acc += arg 22 | case "jmp": 23 | pc += arg - 1 24 | case "nop": 25 | } 26 | pc++ 27 | if pc >= len(prog) { 28 | return acc, true 29 | } else if seen[pc] { 30 | return acc, false 31 | } 32 | seen[pc] = true 33 | } 34 | } 35 | 36 | func main() { 37 | // part 1 38 | prog := utils.Lines(input) 39 | acc, _ := runProg(prog) 40 | utils.Println(acc) 41 | 42 | // part 2 43 | for i, l := range prog { 44 | prog[i] = utils.Replace(l, "jmp", "nop", "nop", "jmp") 45 | acc, halted := runProg(prog) 46 | if halted { 47 | utils.Println(acc) 48 | return 49 | } 50 | prog[i] = l 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /2020/day9.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2020, 9) 8 | var inputInts = utils.ExtractInts(input) 9 | 10 | func isSum(x int, prev []int) bool { 11 | for i := range prev { 12 | for j := i + 1; j < len(prev); j++ { 13 | if prev[i]+prev[j] == x { 14 | return true 15 | } 16 | } 17 | } 18 | return false 19 | } 20 | 21 | func main() { 22 | // part 1 23 | var n int 24 | for i, x := range inputInts[25:] { 25 | if !isSum(x, inputInts[:25+i]) { 26 | n = x 27 | break 28 | } 29 | } 30 | utils.Println(n) 31 | 32 | // part 2 33 | outer: 34 | for i := range inputInts { 35 | for j := i + 2; j < len(inputInts); j++ { 36 | section := inputInts[i:j] 37 | if s := utils.IntSum(section); s == n { 38 | max := utils.Maximum(len(section), func(k int) int { return section[k] }) 39 | min := utils.Minimum(len(section), func(k int) int { return section[k] }) 40 | utils.Println(min + max) 41 | return 42 | } else if s > n { 43 | continue outer 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /2021/day1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2021, 1) 8 | var inputInts = utils.ExtractInts(input) 9 | 10 | func increasing(ints []int) int { 11 | w := utils.SlidingWindow(ints, 2).([][]int) 12 | return utils.Count(len(w), func(i int) bool { return w[i][0] < w[i][1] }) 13 | } 14 | 15 | func main() { 16 | // part 1 17 | utils.Println(increasing(inputInts)) 18 | 19 | // part 2 20 | w := utils.SlidingWindow(inputInts, 3).([][]int) 21 | summed := make([]int, len(w)) 22 | for i := range summed { 23 | summed[i] = utils.IntSum(w[i]) 24 | } 25 | utils.Println(increasing(summed)) 26 | } 27 | -------------------------------------------------------------------------------- /2021/day1.slouch: -------------------------------------------------------------------------------- 1 | =input ints 2 | =inc window 2 | count -< < 3 | inc 4 | window 3 | map sum | inc 5 | -------------------------------------------------------------------------------- /2021/day10.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | "strings" 6 | 7 | "lukechampine.com/advent/utils" 8 | ) 9 | 10 | var input = utils.Input(2021, 10) 11 | var inputLines = utils.Lines(input) 12 | 13 | func parse(line string) (illegal byte, missing string) { 14 | closer := []byte{'(': ')', '[': ']', '{': '}', '<': '>'} 15 | var expect string 16 | for ; len(line) > 0; line = line[1:] { 17 | switch c := line[0]; c { 18 | case '(', '[', '{', '<': 19 | expect = string(closer[c]) + expect 20 | case ')', ']', '}', '>': 21 | if !strings.HasPrefix(expect, string(c)) { 22 | return c, expect 23 | } 24 | expect = expect[1:] 25 | } 26 | } 27 | return 0, expect 28 | } 29 | 30 | func main() { 31 | var sum int 32 | var scores []int 33 | for _, line := range inputLines { 34 | illegal, missing := parse(line) 35 | if illegal != 0 { 36 | sum += []int{')': 3, ']': 57, '}': 1197, '>': 25137}[illegal] 37 | } else { 38 | var score int 39 | for _, c := range missing { 40 | score *= 5 41 | score += strings.IndexRune(" )]}>", c) 42 | } 43 | scores = append(scores, score) 44 | } 45 | } 46 | utils.Println(sum) 47 | sort.Ints(scores) 48 | utils.Println(scores[len(scores)/2]) 49 | } 50 | -------------------------------------------------------------------------------- /2021/day10.slouch: -------------------------------------------------------------------------------- 1 | =input lines 2 | =reduced input | map (stabilize (concat | deleteAll ["()", "[]", "{}", "<>"])) 3 | =isCorrupted containsAny (chars ")]}>") 4 | =score1 first (in ")]}>") | [")": 3, "]": 57, "}": 1197, ">": 25137]. 5 | reduced | filter isCorrupted | map score1 | sum 6 | =score2 reverse | fold { x*5 + (index y " ([{<") } 0 7 | reduced | filter (isCorrupted | not) | map score2 | median 8 | -------------------------------------------------------------------------------- /2021/day11.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map digits 2 | =neighbors adj8 | filter (within (dims input)) 3 | =ps { enum [0,0] (dims input) | filter (y._ | x) } 4 | =charge fold { set y (+1) x } 5 | =zero fold { set y 0 x } 6 | =flash { [charge x (neighbors y), filter (x._ == 9) (neighbors y) ] } 7 | =reset { zero x (ps (>9) x) } 8 | =step map (map (+1)) | { exhaust flash (ps (==10) x) x } | reset 9 | =numFlashed flatten | count 0 10 | iterate step | take 101 | map numFlashed | sum 11 | iterate step | takeWhile (numFlashed != (dims input |< *)) | len 12 | -------------------------------------------------------------------------------- /2021/day12.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map (split "-") 2 | =edges concat [input, map reverse input] | graph 3 | =isUpper -:(== toUpper) 4 | =part1 { -:(isUpper or not (in x)) } 5 | dfs { [true: [x+1,[]], false:[x, keys edges.y | filter (part1 z)]].(y=="end") } 0 "start" 6 | =noDoubles filter (not isUpper) | histogram | all (.1 < 2) 7 | =part2 { -:((part1 x) or (!= "start" and noDoubles x)) } 8 | dfs { [true: [x+1,[]], false:[x, keys edges.y | filter (part2 z)]].(y=="end") } 0 "start" 9 | -------------------------------------------------------------------------------- /2021/day13.slouch: -------------------------------------------------------------------------------- 1 | =input split "\n\n" 2 | =paper input.0 | lines | map ints 3 | =folds input.1 | lines | map {[int (x.11 == "y"), ints x | head]} 4 | =reflect -<{ map (set x (2*y-)) } 5 | =foldOver { cleave (.(y.0) < y.1) x | set 1 (reflect y) | concat | uniq } 6 | foldOver paper (head folds) | len 7 | fold foldOver paper folds | render "#" " " 8 | -------------------------------------------------------------------------------- /2021/day14.slouch: -------------------------------------------------------------------------------- 1 | =input split "\n\n" 2 | =template input.0 | window 2 | histogram 3 | =rules input.1 | lines | concatmap (split " -> ") | assoc 4 | =expand concatmap -<{ [x.0 + rules.x, y, rules.x + x.1, y] } | assocWith (+) 5 | =charcounts concatmap -<{[x.0, y]} | assocWith (+) | vals 6 | iterate expand template | .10 | charcounts |: max - min + 1 7 | iterate expand template | .40 | charcounts |: max - min + 1 8 | -------------------------------------------------------------------------------- /2021/day15.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map digits 2 | =end dims | map (-1) 3 | =neighbours adj | filter (within (dims input)) | map {[x, input.x]} 4 | dijkstra neighbours [0,0] (end input) | map (input.) | sum - 1 5 | 6 | =row input | map (iterate (map (%9+1)) | take 5 | flatten) 7 | =cave iterate (map (map (%9+1))) row | take 5 | flatten 8 | =caveneighbours adj | filter (within (dims cave)) | map {[x, cave.x]} 9 | dijkstra caveneighbours [0,0] (end cave) | map (cave.) | sum - 1 10 | -------------------------------------------------------------------------------- /2021/day17.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2021, 17) 8 | 9 | func fire(xv, yv, x1, x2, y1, y2 int) (maxY int, within bool) { 10 | xp, yp := 0, 0 11 | for (xv >= 0 || xp >= x1) && (yv >= 0 || yp >= y1) { 12 | if x1 <= xp && xp <= x2 && y1 <= yp && yp <= y2 { 13 | return maxY, true 14 | } 15 | xp += xv 16 | yp += yv 17 | xv -= utils.Signum(xv) // drag 18 | yv-- // gravity 19 | maxY = utils.Max(maxY, yp) 20 | } 21 | return 0, false 22 | } 23 | 24 | func main() { 25 | parts := utils.ExtractInts(input) 26 | x1, x2, y1, y2 := parts[0], parts[1], parts[2], parts[3] 27 | 28 | var max int 29 | var n int 30 | for xv := 0; xv <= x2; xv++ { 31 | for yv := -200; yv < 200; yv++ { 32 | maxY, ok := fire(xv, yv, x1, x2, y1, y2) 33 | max = utils.Max(max, maxY) 34 | n += utils.BoolToInt(ok) 35 | } 36 | } 37 | utils.Println(max) 38 | utils.Println(n) 39 | } 40 | -------------------------------------------------------------------------------- /2021/day2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2021, 2) 10 | var inputInts = utils.ExtractInts(input) 11 | 12 | func main() { 13 | // part 1 14 | var pos utils.Pos 15 | for _, line := range utils.Lines(input) { 16 | fs := strings.Fields(line) 17 | n := utils.Atoi(fs[1]) 18 | switch fs[0] { 19 | case "forward": 20 | pos.X += n 21 | case "up": 22 | pos.Y -= n 23 | case "down": 24 | pos.Y += n 25 | } 26 | } 27 | utils.Println(pos.X * pos.Y) 28 | 29 | // part 2 30 | pos = utils.Pos{0, 0} 31 | var aim int 32 | for _, line := range utils.Lines(input) { 33 | fs := strings.Fields(line) 34 | n := utils.Atoi(fs[1]) 35 | switch fs[0] { 36 | case "forward": 37 | pos.X += n 38 | pos.Y += aim * n 39 | case "up": 40 | aim -= n 41 | case "down": 42 | aim += n 43 | } 44 | } 45 | utils.Println(pos.X * pos.Y) 46 | } 47 | -------------------------------------------------------------------------------- /2021/day2.slouch: -------------------------------------------------------------------------------- 1 | =dir ["forward":"r", "up":"u", "down":"d"]. 2 | =input lines | map (words |< {[dir x, int y]}) 3 | fold {move y x} [0,0] input | 0-product 4 | 5 | =up {[y.0-x, y.1]} 6 | =down {[y.0+x, y.1]} 7 | =fwd {[y.0, y.1 | move ["r",x] | move ["u",y.0*x] ]} 8 | =adj {(["u":up,"d":down,"r":fwd].(y.0)) y.1 x} 9 | fold adj [0,[0,0]] input | _.1 | product 10 | -------------------------------------------------------------------------------- /2021/day25.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2021, 25) 10 | 11 | func doStep(grid [][]byte) [][]byte { 12 | next := utils.CloneGrid(grid) 13 | for y, row := range grid { 14 | for x, c := range row { 15 | if c == '>' { 16 | if grid[y][(x+1)%len(row)] == '.' { 17 | next[y][x] = '.' 18 | next[y][(x+1)%len(row)] = '>' 19 | } 20 | } 21 | } 22 | } 23 | next2 := utils.CloneGrid(next) 24 | for y, row := range next { 25 | for x, c := range row { 26 | if c == 'v' { 27 | if next[(y+1)%len(next)][x] == '.' { 28 | next2[y][x] = '.' 29 | next2[(y+1)%len(next2)][x] = 'v' 30 | } 31 | } 32 | } 33 | } 34 | return next2 35 | } 36 | 37 | func main() { 38 | grid := utils.ToByteGrid(utils.Lines(input)) 39 | for step := 1; ; step++ { 40 | next := doStep(grid) 41 | if fmt.Sprint(next) == fmt.Sprint(grid) { 42 | utils.Println(step) 43 | return 44 | } 45 | grid = next 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /2021/day3.slouch: -------------------------------------------------------------------------------- 1 | =input lines 2 | 3 | =oxy_sort sortBy [.1, .0] 4 | =co2_sort oxy_sort | reverse 5 | =rateBy { transpose y | map (histogram | x | .0.0) } 6 | =epsilon input | rateBy oxy_sort | fromBase 2 7 | =gamma input | rateBy co2_sort | fromBase 2 8 | epsilon * gamma 9 | 10 | =go { filter (_.y == (rateBy x z).y) z | collect } 11 | =epsilon iterate (-<{[x+1, go oxy_sort x y]}) [0,input] | map _.1 | first (len == 1) | head | fromBase 2 12 | =gamma iterate (-<{[x+1, go co2_sort x y]}) [0,input] | map _.1 | first (len == 1) | head | fromBase 2 13 | epsilon * gamma -------------------------------------------------------------------------------- /2021/day4.slouch: -------------------------------------------------------------------------------- 1 | =input ints 2 | =winners input | take 100 3 | =boards input | drop 100 | partition 25 | map (partition 5) 4 | =lineBingoAt map (index _ winners) | max 5 | =bingoAt {concat [x, transpose x] | map lineBingoAt | min} 6 | =unmarked { concat x | deleteAll (take (bingoAt x + 1) winners) } 7 | =score { sum (unmarked x) * winners.(bingoAt x) } 8 | boards | minBy bingoAt | score 9 | boards | maxBy bingoAt | score 10 | -------------------------------------------------------------------------------- /2021/day5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2021, 5) 10 | var inputLines = utils.Lines(input) 11 | 12 | func main() { 13 | seen := make(map[utils.Pos]int) 14 | seenHV := make(map[utils.Pos]int) 15 | for _, line := range inputLines { 16 | var start, end utils.Pos 17 | utils.Sscanf(line, "%d,%d -> %d,%d", &start.X, &start.Y, &end.X, &end.Y) 18 | p := start 19 | for seen[p]++; p != end; seen[p]++ { 20 | p = p.StrideTowards(end) 21 | } 22 | if start.X == end.X || start.Y == end.Y { 23 | p := start 24 | for seenHV[p]++; p != end; seenHV[p]++ { 25 | p = p.StrideTowards(end) 26 | } 27 | } 28 | } 29 | // part 1 30 | var sumHV int 31 | for _, n := range seenHV { 32 | if n > 1 { 33 | sumHV++ 34 | } 35 | } 36 | fmt.Println(sumHV) 37 | 38 | // part 2 39 | var sum int 40 | for _, n := range seen { 41 | if n > 1 { 42 | sum++ 43 | } 44 | } 45 | fmt.Println(sum) 46 | } 47 | -------------------------------------------------------------------------------- /2021/day5.slouch: -------------------------------------------------------------------------------- 1 | =input ints | partition 4 | map (partition 2) 2 | =intersections concatmap (-< draw) | histogram | vals | count (> 1) 3 | filter (transpose | any (-< ==)) | intersections 4 | intersections 5 | -------------------------------------------------------------------------------- /2021/day6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2021, 6) 8 | var inputInts = utils.ExtractInts(input) 9 | 10 | func step(fish *[9]int) { 11 | r := fish[0] 12 | copy(fish[:], fish[1:]) 13 | fish[8] = r 14 | fish[6] += r 15 | } 16 | 17 | func main() { 18 | var fish [9]int 19 | for _, i := range inputInts { 20 | fish[i]++ 21 | } 22 | for i := 0; i < 256; i++ { 23 | if i == 80 { 24 | utils.Println(utils.IntSum(fish[:])) 25 | } 26 | step(&fish) 27 | } 28 | utils.Println(utils.IntSum(fish[:])) 29 | } 30 | -------------------------------------------------------------------------------- /2021/day6.slouch: -------------------------------------------------------------------------------- 1 | =input ints 2 | =fish enum 0 8 | map (count _ input) 3 | =step rotate 1 | { set 6 (+x.8) x } 4 | iterate step fish | .80 | sum 5 | iterate step fish | .256 | sum 6 | -------------------------------------------------------------------------------- /2021/day7.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2021, 7) 10 | var inputInts = utils.ExtractInts(input) 11 | 12 | func main() { 13 | sort.Ints(inputInts) 14 | max := inputInts[len(inputInts)-1] 15 | 16 | utils.Println(utils.Minimum(max, func(i int) int { 17 | var sum int 18 | for _, v := range inputInts { 19 | sum += utils.Abs(v - i) 20 | } 21 | return sum 22 | })) 23 | 24 | utils.Println(utils.Minimum(max, func(i int) int { 25 | var sum int 26 | for _, v := range inputInts { 27 | delta := utils.Abs(v - i) 28 | sum += (delta + delta*delta) / 2 29 | } 30 | return sum 31 | })) 32 | } 33 | -------------------------------------------------------------------------------- /2021/day7.slouch: -------------------------------------------------------------------------------- 1 | =input ints 2 | median | { input | map (-x | abs) | sum } 3 | mean | { input | map (-x | abs |: (_+_*_)/2 ) | sum } 4 | -------------------------------------------------------------------------------- /2021/day8.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map (split "|" | map words) 2 | map (.1 | count (len | in [2,4,3,7])) | sum 3 | =segs ["abcefg", "cf", "acdeg", "acdfg", "bcdf", 4 | "abdfg", "abdefg", "acf", "abcdefg", "abcdfg"] 5 | =csum { map ((x | flatten | histogram).) | sum } 6 | =lookup map (csum segs) segs 7 | =output -<{ map (csum x) y | map (indexIn lookup) | fromDigits } 8 | map output | sum 9 | -------------------------------------------------------------------------------- /2021/day9.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map digits 2 | =grid input | { [head x | len - 1, len x - 1] } 3 | =at -<{input.y.x} 4 | =neighbors adj | filter (within grid) | map at 5 | =lowest enum [0,0] grid | filter { neighbors x | all (> (at x)) } 6 | lowest | map (at + 1) | sum 7 | =basins lowest | map (flood { within grid x and at x != 9 } | sortBy [.0, .1]) | uniq 8 | basins | map len | sortBy (>) | take 3 | product 9 | -------------------------------------------------------------------------------- /2022/day1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2022, 1) 10 | 11 | func main() { 12 | groups := utils.Split(input, "\n\n") 13 | sums := make([]int, len(groups)) 14 | for i, g := range groups { 15 | sums[i] = utils.IntSum(utils.ExtractInts(g)) 16 | } 17 | sort.Slice(sums, func(i, j int) bool { 18 | return sums[i] > sums[j] 19 | }) 20 | utils.Println(sums[0]) 21 | utils.Println(utils.IntSum(sums[:3])) 22 | } 23 | -------------------------------------------------------------------------------- /2022/day1.slouch: -------------------------------------------------------------------------------- 1 | =sums input | split "\n\n" | map (ints | sum) 2 | max sums 3 | sortBy (>) sums | take 3 | sum 4 | -------------------------------------------------------------------------------- /2022/day10.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2022, 10) 10 | 11 | func main() { 12 | x := 1 13 | pc := 0 14 | sum := 0 15 | grid := utils.NewLightBoard(40, 6) 16 | inc := func() { 17 | if i, j := pc%40, pc/40; utils.Abs(i-x) <= 1 { 18 | grid.Set(i, j, true) 19 | } 20 | if pc++; (pc-20)%40 == 0 { 21 | sum += pc * x 22 | } 23 | } 24 | for _, line := range utils.Lines(input) { 25 | fields := strings.Fields(line) 26 | switch fields[0] { 27 | case "noop": 28 | inc() 29 | case "addx": 30 | inc() 31 | inc() 32 | x += utils.Atoi(fields[1]) 33 | } 34 | } 35 | utils.Println(sum, x) 36 | grid.Print() 37 | } 38 | -------------------------------------------------------------------------------- /2022/day10.slouch: -------------------------------------------------------------------------------- 1 | =seq input | lines | concatmap (words | {["noop":["0"], "addx":["0",last x]].(x.0) }) | map int 2 | =fn { [x.0+1, x.1+y, x.2 + ((x.0-20 %? 40) | int * x.0 * x.1)] } 3 | fold fn [1,1,0] seq | .2 4 | =fn { [ x.0+1, x.1+y, abs (x.1-(x.0%40)) <= 1 | [true:(append [x.0%40,x.0/40] x.2), false:x.2]._ ] } 5 | fold fn [0,1,[]] seq | .2 | render "#" " " -------------------------------------------------------------------------------- /2022/day12.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2022, 12) 8 | 9 | func main() { 10 | g := utils.ToByteGrid(utils.Lines(input)) 11 | m := utils.Maze{ 12 | Grid: utils.Grid{X: len(g[0]) - 1, Y: len(g) - 1}, 13 | IsWall: func(p utils.Pos) bool { return false }, 14 | CanMove: func(p, d utils.Pos) bool { 15 | p, d = d, p // moving backwards 16 | 17 | pc, dc := g[p.Y][p.X], g[d.Y][d.X] 18 | if pc == 'S' { 19 | pc = 'a' 20 | } 21 | if dc == 'E' { 22 | dc = 'z' 23 | } 24 | return dc <= pc+1 25 | }, 26 | } 27 | 28 | dists := m.DistancesFrom(utils.Locate(g, 'E')) 29 | best := dists[utils.Locate(g, 'S')] 30 | utils.Println(best) 31 | 32 | m.Grid.ForEach(func(p utils.Pos) { 33 | if g[p.Y][p.X] == 'a' { 34 | if d, ok := dists[p]; ok && d < best { 35 | best = d 36 | } 37 | } 38 | }) 39 | utils.Println(best) 40 | } 41 | -------------------------------------------------------------------------------- /2022/day2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2022, 2) 8 | 9 | var beats = map[byte]byte{ 10 | 'A': 'Z', 11 | 'B': 'X', 12 | 'C': 'Y', 13 | 'X': 'C', 14 | 'Y': 'A', 15 | 'Z': 'B', 16 | } 17 | 18 | func score(a, b byte) int { 19 | var outcome int 20 | var choice int = int(b - 'X' + 1) 21 | switch { 22 | case beats[a] == b: 23 | outcome = 0 24 | default: 25 | outcome = 3 26 | case beats[b] == a: 27 | outcome = 6 28 | } 29 | return outcome + choice 30 | } 31 | 32 | func score2(a, b byte) int { 33 | var outcome int = 3 * int(b-'X') 34 | var choice byte 35 | switch b { 36 | case 'X': // lose 37 | choice = beats[a] 38 | case 'Y': // tie 39 | choice = 'X' + (a - 'A') 40 | case 'Z': // win 41 | for k, v := range beats { 42 | if v == a { 43 | choice = k 44 | break 45 | } 46 | } 47 | } 48 | return outcome + int(choice-'X'+1) 49 | } 50 | 51 | func main() { 52 | // part 1 53 | var sum int 54 | for _, line := range utils.Lines(input) { 55 | sum += score(line[0], line[2]) 56 | } 57 | utils.Println(sum) 58 | 59 | // part 2 60 | sum = 0 61 | for _, line := range utils.Lines(input) { 62 | sum += score2(line[0], line[2]) 63 | } 64 | utils.Println(sum) 65 | } 66 | -------------------------------------------------------------------------------- /2022/day2.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map (words | map (indexIn "ABCXYZ" % 3)) 2 | sumBy -<{3*(rotate (--x) [1,2,0]).y + y + 1} 3 | sumBy -<{3*y + (rotate x [2,0,1]).y + 1} -------------------------------------------------------------------------------- /2022/day20.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "container/ring" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2022, 20) 10 | 11 | func mix(ps []*ring.Ring) { 12 | for _, p := range ps { 13 | p = p.Prev() 14 | v := p.Unlink(1) 15 | p.Move(v.Value.(int) % (len(ps) - 1)).Link(v) 16 | } 17 | } 18 | 19 | func grove(r *ring.Ring) (g int) { 20 | for r.Value.(int) != 0 { 21 | r = r.Next() 22 | } 23 | for i := 0; i < 3; i++ { 24 | r = r.Move(1000) 25 | g += r.Value.(int) 26 | } 27 | return 28 | } 29 | 30 | func main() { 31 | ns := utils.ExtractInts(input) 32 | r := ring.New(len(ns)) 33 | ps := make([]*ring.Ring, r.Len()) 34 | for i, n := range ns { 35 | r.Value = n 36 | ps[i] = r 37 | r = r.Next() 38 | } 39 | mix(ps) 40 | utils.Println(grove(r)) 41 | 42 | for i, n := range ns { 43 | r.Value = n * 811589153 44 | ps[i] = r 45 | r = r.Next() 46 | } 47 | for i := 0; i < 10; i++ { 48 | mix(ps) 49 | } 50 | utils.Println(grove(r)) 51 | } 52 | -------------------------------------------------------------------------------- /2022/day25.slouch: -------------------------------------------------------------------------------- 1 | =snafu ["=":--2, "-":--1, "0":0, "1":1, "2":2] 2 | =allTwos toBase 5 | len | replicate _ "2" | fromBase 5 3 | =fromSNAFU tr snafu | map (+2 | string) | fromBase 5 | -:(- allTwos) 4 | =toSNAFU -:(+ allTwos) | toBase 5 | map (int | -2) | tr (invert snafu) 5 | input | lines | sumBy fromSNAFU | toSNAFU -------------------------------------------------------------------------------- /2022/day3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2022, 3) 8 | 9 | func common(ss ...string) rune { 10 | counts := make(map[rune]int) 11 | for _, s := range ss { 12 | for c := range utils.CharCounts(s) { 13 | counts[c]++ 14 | } 15 | } 16 | for c, n := range counts { 17 | if n == len(ss) { 18 | return c 19 | } 20 | } 21 | panic("unreachable") 22 | } 23 | 24 | func priority(b rune) int { 25 | if b >= 'a' { 26 | return int(b-'a') + 1 27 | } 28 | return int(b-'A') + 27 29 | } 30 | 31 | func main() { 32 | var sum int 33 | for _, line := range utils.Lines(input) { 34 | sum += priority(common(line[:len(line)/2], line[len(line)/2:])) 35 | } 36 | utils.Println(sum) 37 | 38 | sum = 0 39 | for _, group := range utils.Window(utils.Lines(input), 3).([][]string) { 40 | sum += priority(common(group...)) 41 | } 42 | utils.Println(sum) 43 | } 44 | -------------------------------------------------------------------------------- /2022/day3.slouch: -------------------------------------------------------------------------------- 1 | =priority 1 + indexIn (concat [alpha, toUpper alpha]) 2 | =score map (fold1 same) | sumBy priority 3 | lines | map {cleave (len x / 2) x} | score 4 | lines | partition 3 | score -------------------------------------------------------------------------------- /2022/day4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2022, 4) 8 | 9 | func main() { 10 | var ranges [][4]int 11 | for _, line := range utils.Lines(input) { 12 | var r [4]int 13 | utils.Sscanf(line, "%d-%d,%d-%d", &r[0], &r[1], &r[2], &r[3]) 14 | ranges = append(ranges, r) 15 | } 16 | 17 | utils.Println(utils.Count(len(ranges), func(i int) bool { 18 | r := ranges[i] 19 | return (r[0] <= r[2] && r[1] >= r[3]) || (r[2] <= r[0] && r[3] >= r[1]) 20 | })) 21 | 22 | utils.Println(utils.Count(len(ranges), func(i int) bool { 23 | r := ranges[i] 24 | return (r[2] <= r[0] && r[0] <= r[3]) || 25 | (r[2] <= r[1] && r[1] <= r[3]) || 26 | (r[0] <= r[2] && r[2] <= r[1]) || 27 | (r[0] <= r[3] && r[3] <= r[1]) 28 | })) 29 | } 30 | -------------------------------------------------------------------------------- /2022/day4.slouch: -------------------------------------------------------------------------------- 1 | =ranges lines | map (split "," | map (split "-" | map int |< {enum x (y+1)})) 2 | ranges | count -<{(same x y) == x or (same x y) == y} 3 | ranges | count - 0) 3 | =moves groups.1 | map ints 4 | =move1 { set x (drop 1) (set y (prepend (take 1 z.x)) z) } 5 | =move { iterate (move1 (y.1-1) (y.2-1)) x | .(y.0) } 6 | fold move stacks moves | map head 7 | =moven { set (y.1-1) (drop y.0) (set (y.2-1) (prepend (take y.0 x.(y.1-1))) x) } 8 | fold moven stacks moves | map head 9 | -------------------------------------------------------------------------------- /2022/day6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2022, 6) 8 | 9 | func main() { 10 | for _, n := range []int{4, 14} { 11 | for i, group := range utils.SlidingWindow(input, n).([]string) { 12 | if len(utils.CharCounts(group)) == n { 13 | utils.Println(i + n) 14 | break 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2022/day6.slouch: -------------------------------------------------------------------------------- 1 | window 4 | index (uniq | len == 4) + 4 2 | window 14 | index (uniq | len == 14) + 14 -------------------------------------------------------------------------------- /2022/day7.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "path" 5 | "strings" 6 | 7 | "lukechampine.com/advent/utils" 8 | ) 9 | 10 | var input = utils.Input(2022, 7) 11 | 12 | func main() { 13 | dirsizes := make(map[string]int) 14 | lines := utils.Lines(input) 15 | 16 | var dir string 17 | for i := 0; i < len(lines); { 18 | fields := strings.Fields(lines[i]) 19 | switch fields[1] { 20 | case "cd": 21 | dir = path.Clean(path.Join(dir, fields[2])) 22 | i++ 23 | case "ls": 24 | for i++; i < len(lines) && lines[i][0] != '$'; i++ { 25 | fields := strings.Fields(lines[i]) 26 | if fields[0] != "dir" { 27 | for d := dir; ; d = path.Dir(d) { 28 | dirsizes[d] += utils.Atoi(fields[0]) 29 | if d == "/" { 30 | break 31 | } 32 | } 33 | } 34 | } 35 | } 36 | } 37 | 38 | var sum int 39 | for _, sz := range dirsizes { 40 | if sz <= 100000 { 41 | sum += sz 42 | } 43 | } 44 | utils.Println(sum) 45 | 46 | toFree := dirsizes["/"] - 40000000 47 | best := dirsizes["/"] 48 | for _, sz := range dirsizes { 49 | if sz >= toFree && sz < best { 50 | best = sz 51 | } 52 | } 53 | utils.Println(best) 54 | } 55 | -------------------------------------------------------------------------------- /2022/day7.slouch: -------------------------------------------------------------------------------- 1 | window 4 | index (uniq | len == 4) + 4 2 | window 14 | index (uniq | len == 14) + 14 -------------------------------------------------------------------------------- /2022/day8.slouch: -------------------------------------------------------------------------------- 1 | =grid input | lines | map chars 2 | =edges -<{ [[x, 0], [0, y], [x, len grid - 1], [len grid.0 - 1, y]] } 3 | =crosshair { edges x | map (draw x | tail) } 4 | =below { grid.y < grid.x } 5 | =visible { crosshair x | any (all (below x)) } 6 | =takeWhileI { takeWhile x y | len+1 | take _ y } 7 | =score { crosshair x | map (takeWhileI (below x) | len) | product } 8 | enum [0,0] (dims grid) | count visible 9 | enum [0,0] (dims grid) | map score | max -------------------------------------------------------------------------------- /2022/day9.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2022, 9) 8 | 9 | func moveToward(src, dst utils.Pos) utils.Pos { 10 | if utils.Abs(dst.X-src.X) < 2 && utils.Abs(dst.Y-src.Y) < 2 { 11 | return src 12 | } 13 | return utils.Pos{ 14 | X: src.X + utils.Signum(dst.X-src.X), 15 | Y: src.Y + utils.Signum(dst.Y-src.Y), 16 | } 17 | } 18 | 19 | func main() { 20 | h := utils.Pos{0, 0} 21 | rope := make([]utils.Pos, 9) 22 | v1 := make(map[utils.Pos]bool) 23 | v1[rope[0]] = true 24 | v2 := make(map[utils.Pos]bool) 25 | v2[rope[8]] = true 26 | for _, line := range utils.Lines(input) { 27 | d := utils.DirFromUDLR(line[0]) 28 | n := utils.Atoi(line[2:]) 29 | h = h.Tread(d, n, func(p utils.Pos) { 30 | for i := range rope { 31 | rope[i] = moveToward(rope[i], p) 32 | p = rope[i] 33 | } 34 | v1[rope[0]] = true 35 | v2[rope[8]] = true 36 | }) 37 | } 38 | utils.Println(len(v1)) 39 | utils.Println(len(v2)) 40 | } 41 | -------------------------------------------------------------------------------- /2022/day9.slouch: -------------------------------------------------------------------------------- 1 | =cmds input | lines | concatmap (toLower | words |< { replicate (int y) [x, 1] }) 2 | =path0 scan (flip move) [0,0] cmds 3 | =rope iterate (tail | scan (flip moveTo) [0,0]) path0 | take 10 4 | rope.1 | uniq | len 5 | rope.9 | uniq | len -------------------------------------------------------------------------------- /2023/day1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2023, 1) 10 | 11 | func calibration(s string) int { 12 | var first, last int 13 | for i := range s { 14 | if '0' <= s[i] && s[i] <= '9' { 15 | if first == 0 { 16 | first = int(s[i] - '0') 17 | } 18 | last = int(s[i] - '0') 19 | } 20 | } 21 | return 10*first + last 22 | } 23 | 24 | func calibration2(s string) int { 25 | var first, last int 26 | for i := 0; i < len(s); i++ { 27 | if '0' <= s[i] && s[i] <= '9' { 28 | if first == 0 { 29 | first = int(s[i] - '0') 30 | } 31 | last = int(s[i] - '0') 32 | continue 33 | } 34 | for n, p := range []string{ 35 | "one", "two", "three", 36 | "four", "five", "six", 37 | "seven", "eight", "nine", 38 | } { 39 | if strings.HasPrefix(s[i:], p) { 40 | if first == 0 { 41 | first = n + 1 42 | } 43 | last = n + 1 44 | break 45 | } 46 | } 47 | } 48 | return 10*first + last 49 | } 50 | 51 | func main() { 52 | lines := utils.Lines(input) 53 | utils.Println(utils.Sum(len(lines), func(i int) int { 54 | return calibration(lines[i]) 55 | })) 56 | utils.Println(utils.Sum(len(lines), func(i int) int { 57 | return calibration2(lines[i]) 58 | })) 59 | } 60 | -------------------------------------------------------------------------------- /2023/day1.slouch: -------------------------------------------------------------------------------- 1 | lines | sumWith (join " " | ints |: (10*head + last)) 2 | =names ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] 3 | =nums zipWith {[[x, y], [string y, y]]} names (tail iota) | concat | assoc 4 | =fstnum nums.{first (hasPrefix _ x) (keys nums)} 5 | lines | sumWith (tails | filter {any (hasPrefix _ x) (keys nums)} | map fstnum |: (10*head + last)) -------------------------------------------------------------------------------- /2023/day11.slouch: -------------------------------------------------------------------------------- 1 | =grid input | lines | map chars 2 | =galaxies enum [0,0] (dims grid) | filter (grid._ == "#") 3 | =empty { enum 0 (len x) | filter (x._ | all (== ".")) } 4 | =emptyRows empty grid 5 | =emptyCols empty (transpose grid) 6 | =crosses {(x.0 <= y and y <= x.1) or (x.1 <= y and y <= x.0)} 7 | =manhattan galaxies | pairs | sumWith -<(zipWith (-) | sumWith abs) 8 | =crossings galaxies | pairs | sumWith (transpose |< { count (crosses x) emptyCols + count (crosses y) emptyRows }) 9 | manhattan + crossings 10 | manhattan + 999999*crossings -------------------------------------------------------------------------------- /2023/day12.slouch: -------------------------------------------------------------------------------- 1 | input | lines | map (words | set 1 ints) 2 | 3 | ; x = [2,2,1] 4 | =isBlock concatmap (replicate _ true | prepend false) | append false 5 | 6 | =alts { map -:((_ and x != ".") or ((not _) and x != "#")) isBlock } | prepend false 7 | =next { map (_ and x != ".") isBlock } 8 | 9 | zipWith (or | int) (alts ".") (next ".") 10 | 11 | 12 | ; x = [1,2,3], y = "#" 13 | ; =alts alts y 14 | ; =next next y 15 | ; zipWith (+) (zipWith (*) x next) alts 16 | =doNFA { } 17 | 18 | 19 | fold doNFA [1, 1, 0, 0, 0] ".#?.##??.??" 20 | -------------------------------------------------------------------------------- /2023/day13.slouch: -------------------------------------------------------------------------------- 1 | =isMirror set 0 reverse |< zip | all -<(==) 2 | =isHorizontal cleaves | any isMirror 3 | =mirrorPos cleaves | firstIndex isMirror 4 | groups | cleave isHorizontal |< { (sumWith (mirrorPos*100) x) + (sumWith (transpose | mirrorPos) y) } 5 | -------------------------------------------------------------------------------- /2023/day18.slouch: -------------------------------------------------------------------------------- 1 | =parse1 words | take 2 | set 1 int 2 | =parse2 words | last | deleteAll "(#)" | {[last x | int | "RDLU"._, take --1 x | fromBase 16] } 3 | =inner scan (flip move) [0,0] | area 4 | =perim sumWith (.1) 5 | lines | map parse1 |: inner + perim/2 + 1 6 | lines | map parse2 |: inner + perim/2 + 1 -------------------------------------------------------------------------------- /2023/day2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2023, 2) 8 | 9 | func maxCubes(game string) (r, g, b int) { 10 | for _, set := range utils.Split(utils.Split(game, ": ")[1], "; ") { 11 | colors := make(map[string]int) 12 | for _, cubes := range utils.Split(set, ", ") { 13 | colors[utils.Split(cubes, " ")[1]] += utils.ExtractInts(cubes)[0] 14 | } 15 | r = utils.Max(r, colors["red"]) 16 | g = utils.Max(g, colors["green"]) 17 | b = utils.Max(b, colors["blue"]) 18 | } 19 | return 20 | } 21 | 22 | func main() { 23 | lines := utils.Lines(input) 24 | var part1, part2 int 25 | for _, line := range lines { 26 | maxR, maxG, maxB := maxCubes(line) 27 | if maxR <= 12 && maxG <= 13 && maxB <= 14 { 28 | part1 += utils.ExtractInts(line)[0] 29 | } 30 | part2 += maxR * maxG * maxB 31 | } 32 | utils.Println(part1) 33 | utils.Println(part2) 34 | } 35 | -------------------------------------------------------------------------------- /2023/day2.slouch: -------------------------------------------------------------------------------- 1 | =maxCubes words | drop 2 | partition 2 | concatmap -<{[y.0, int x]} | assocWith {max [x, y]} 2 | =possible {x."r" <= 12 and x."g" <= 13 and x."b" <= 14 } 3 | lines | filter (maxCubes | possible) | sumWith (ints | head) 4 | lines | sumWith (maxCubes | vals | product) -------------------------------------------------------------------------------- /2023/day3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2023, 3) 8 | 9 | func isDigit(c byte) bool { 10 | return '0' <= c && c <= '9' 11 | } 12 | 13 | func main() { 14 | grid := utils.ToByteGrid(utils.Lines(input)) 15 | g := utils.Grid{len(grid[0]) - 1, len(grid) - 1} 16 | parts := make(map[utils.Pos][]int) 17 | for y := range grid { 18 | for x := 0; x < len(grid[y]); x++ { 19 | var num string 20 | for x < len(grid[y]) && isDigit(grid[y][x]) { 21 | num += string(grid[y][x]) 22 | x++ 23 | } 24 | if num == "" { 25 | continue 26 | } 27 | outer: 28 | for p := (utils.Pos{x - len(num), y}); p.X < x; p.X++ { 29 | for _, adj := range p.ValidNumpad(g) { 30 | if c := grid[adj.Y][adj.X]; !isDigit(c) && c != '.' { 31 | parts[adj] = append(parts[adj], utils.Atoi(num)) 32 | break outer 33 | } 34 | } 35 | } 36 | } 37 | } 38 | var part1, part2 int 39 | for p, nums := range parts { 40 | part1 += utils.IntSum(nums) 41 | if grid[p.Y][p.X] == '*' && len(nums) == 2 { 42 | part2 += nums[0] * nums[1] 43 | } 44 | } 45 | utils.Println(part1) 46 | utils.Println(part2) 47 | } 48 | -------------------------------------------------------------------------------- /2023/day3.slouch: -------------------------------------------------------------------------------- 1 | =grid input | lines | map chars 2 | =nums enum [0,0] (dims grid) | partition (len grid.0) | concatmap (split (grid._ | not (in numeric))) 3 | =neighbors concatmap adj8 | filter (within (dims grid |< {[x-1,y-1]})) 4 | nums | filter (neighbors | any (grid._ |: != "." and not (in numeric))) | sumWith (intWith grid._) 5 | =gears nums | filter (neighbors | any (grid._ == "*")) | mapTo (neighbors | first (grid._ == "*")) 6 | gears | invert | vals | filter (len == 2) | sumWith (productWith (intWith grid._)) -------------------------------------------------------------------------------- /2023/day4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2023, 4) 8 | 9 | func main() { 10 | wins := []int{7, 10, 2, 10, 9, 6, 7, 1, 7, 6, 4, 1, 4, 3, 3, 1, 1, 1, 0, 10, 10, 10, 10, 10, 4, 3, 1, 10, 5, 10, 6, 10, 10, 3, 3, 5, 7, 3, 2, 0, 3, 0, 1, 0, 9, 10, 1, 8, 10, 1, 3, 0, 9, 5, 2, 5, 5, 3, 3, 2, 0, 0, 10, 2, 8, 10, 9, 6, 8, 3, 7, 9, 3, 2, 8, 4, 5, 3, 4, 0, 0, 1, 0, 10, 8, 10, 3, 6, 5, 9, 4, 6, 6, 1, 4, 5, 0, 6, 4, 1, 3, 2, 1, 0, 7, 10, 6, 5, 4, 3, 4, 2, 3, 5, 2, 2, 2, 2, 2, 0, 0, 0, 0, 10, 7, 2, 6, 10, 2, 9, 6, 0, 1, 0, 4, 1, 2, 0, 0, 0, 2, 4, 10, 10, 10, 0, 10, 2, 10, 0, 1, 0, 3, 4, 6, 2, 2, 0, 1, 1, 0, 8, 7, 4, 1, 9, 1, 2, 0, 5, 2, 3, 3, 1, 1, 1, 0, 0, 2, 0, 4, 9, 10, 0, 2, 7, 1, 4, 1, 2, 0, 0, 0, 0} 11 | cards := make([]int, len(wins)) 12 | for i := range cards { 13 | cards[i] = 1 14 | } 15 | var sum int 16 | for i, w := range wins { 17 | sum += cards[i] 18 | for j := 0; j < w; j++ { 19 | cards[i+j+1] += cards[i] 20 | } 21 | } 22 | utils.Println(sum) 23 | } 24 | -------------------------------------------------------------------------------- /2023/day4.slouch: -------------------------------------------------------------------------------- 1 | =wins input | lines | map (split "|" |< { same (ints x | drop 1) (ints y) } | len) 2 | wins | sumWith (pow 2 / 2) 3 | =total 1 + sumWith (.1) 4 | =acc { [x.0 + total x.1, x.1 | map (set 0 (-1)) | append [y, total x.1] | filter (.0 > 0)] } 5 | fold acc [0, []] wins | head -------------------------------------------------------------------------------- /2023/day5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2023, 5) 8 | 9 | func resolve(n int, maps [][][2][2]int) int { 10 | for _, m := range maps { 11 | for _, r := range m { 12 | if r[1][0] <= n && n < r[1][1] { 13 | n = n - r[1][0] + r[0][0] 14 | break 15 | } 16 | } 17 | } 18 | return n 19 | } 20 | 21 | func main() { 22 | groups := utils.Split(input, "\n\n") 23 | seeds := utils.ExtractInts(groups[0]) 24 | maps := make([][][2][2]int, len(groups)-1) 25 | for i, g := range groups[1:] { 26 | for _, line := range utils.Lines(g)[1:] { 27 | ints := utils.ExtractInts(line) 28 | maps[i] = append(maps[i], [2][2]int{ 29 | [2]int{ints[0], ints[0] + ints[2]}, 30 | [2]int{ints[1], ints[1] + ints[2]}, 31 | }) 32 | } 33 | } 34 | var min int = 1e9 35 | for _, seed := range seeds { 36 | min = utils.Min(min, resolve(seed, maps)) 37 | } 38 | utils.Println(min) 39 | 40 | min = 1e9 41 | for i := 0; i < len(seeds); i += 2 { 42 | for seed := seeds[i]; seed < seeds[i]+seeds[i+1]; seed++ { 43 | min = utils.Min(min, resolve(seed, maps)) 44 | } 45 | } 46 | utils.Println(min) 47 | } 48 | -------------------------------------------------------------------------------- /2023/day5.slouch: -------------------------------------------------------------------------------- 1 | =maps input | groups | tail | map (tail | map ints) 2 | =inMap { y.1 <= x and x <= y.1+y.2 } 3 | =doMap { first (inMap x) (append [x,x,1] y) |: x + .0 - .1 } 4 | groups | head | ints | minWith (fold doMap _ maps) 5 | -------------------------------------------------------------------------------- /2023/day6.slouch: -------------------------------------------------------------------------------- 1 | =waysToWin -<{ sqrt(x*x - 4*y) + 1 } 2 | lines | map ints | transpose | productWith waysToWin 3 | lines | map (words | tail | concat | int) | waysToWin -------------------------------------------------------------------------------- /2023/day7.slouch: -------------------------------------------------------------------------------- 1 | =kind contains 2 | =house -:(kind 2 and kind 3) 3 | =twopair -:(kind 2 and (.2 | len) == 2) 4 | =score head | histogram | invert | match [kind 5:6, kind 4:5, house:4, kind 3:3, twopair:2, kind 2:1, _:0] 5 | =strength { zip (head y) (head z) | append "AK" | first -:(.0 != .1) | map (indexIn x) } |< > 6 | =hands lines | map (words |< {[x, int y]}) 7 | hands | sortBy [score, strength "AKQJT98765432"] | zipWith (* last) (tail iota) | sum 8 | =improve { tr ["J": maxBy (count _ x) "AKQT98765432"] x } 9 | hands | sortBy [set 0 improve | score, strength "AKQT98765432J"] | zipWith (* last) (tail iota) | sum -------------------------------------------------------------------------------- /2023/day8.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2023, 8) 10 | 11 | func main() { 12 | lines := utils.Lines(input) 13 | insts := lines[0] 14 | network := make(map[string][2]string) 15 | for _, line := range lines[2:] { 16 | network[line[0:3]] = [2]string{line[7:10], line[12:15]} 17 | } 18 | steps := 0 19 | for n := "AAA"; n != "ZZZ"; steps++ { 20 | n = network[n][strings.IndexByte("LR", insts[0])] 21 | insts = insts[1:] + insts[:1] 22 | } 23 | utils.Println(steps) 24 | 25 | var cycles []int 26 | for n := range network { 27 | if n[2] == 'A' { 28 | steps := 0 29 | insts := lines[0] 30 | for ; n[2] != 'Z'; steps++ { 31 | n = network[n][strings.IndexByte("LR", insts[0])] 32 | insts = insts[1:] + insts[:1] 33 | } 34 | cycles = append(cycles, steps) 35 | } 36 | } 37 | gcd := func(a, b int) int { 38 | for b != 0 { 39 | a, b = b, a%b 40 | } 41 | return a 42 | } 43 | r := cycles[0] 44 | for _, c := range cycles[1:] { 45 | r = (r * c) / gcd(r, c) 46 | } 47 | utils.Println(r) 48 | } 49 | -------------------------------------------------------------------------------- /2023/day8.slouch: -------------------------------------------------------------------------------- 1 | =insts input | groups | .0.0 | chars | map (indexIn "LR") 2 | =network input | groups | .1 | map (deleteAll "=,()" | words |< {[x, [y, z]]}) | assoc 3 | =follow scan { network.x | .y } _ (cycle insts) 4 | follow "AAA" | 1 + index "ZZZ" 5 | =starts network | keys | filter (last == "A") 6 | =cyclelen dropWhile (last != "Z") | tail | 1 + index (last == "Z") 7 | starts | map (follow | cyclelen) | lcm -------------------------------------------------------------------------------- /2023/day9.slouch: -------------------------------------------------------------------------------- 1 | =predict iterate deltas | takeWhile (any (!= 0)) | sumWith last 2 | lines | map ints | sumWith predict 3 | lines | map (ints | reverse) | sumWith predict -------------------------------------------------------------------------------- /2024/day1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2024, 1) 10 | 11 | func main() { 12 | cols := utils.Transpose(utils.Window(utils.ExtractInts(input), 2)).([][]int) 13 | sort.Ints(cols[0]) 14 | sort.Ints(cols[1]) 15 | utils.Println(utils.Sum(len(cols[0]), func(i int) int { 16 | return utils.Abs(cols[0][i] - cols[1][i]) 17 | })) 18 | utils.Println(utils.Sum(len(cols[0]), func(i int) int { 19 | return cols[0][i] * utils.Count(len(cols[1]), func(j int) bool { 20 | return cols[1][j] == cols[0][i] 21 | }) 22 | })) 23 | } 24 | -------------------------------------------------------------------------------- /2024/day1.slouch: -------------------------------------------------------------------------------- 1 | =cols input | lines | map ints | transpose 2 | cols | map sort |< zipWith (- | abs) | sum 3 | cols.0 | sumWith { x * (count x cols.1) } 4 | -------------------------------------------------------------------------------- /2024/day11.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2024, 11) 8 | 9 | var memo = map[[2]int]int{} 10 | 11 | func totalStones(stone int, steps int) int { 12 | if steps == 0 { 13 | return 1 14 | } else if n, ok := memo[[2]int{stone, steps}]; ok { 15 | return n 16 | } 17 | 18 | var n int 19 | if stone == 0 { 20 | n = totalStones(1, steps-1) 21 | } else if str := utils.Itoa(stone); len(str)%2 == 0 { 22 | n += totalStones(utils.Atoi(str[:len(str)/2]), steps-1) 23 | n += totalStones(utils.Atoi(str[len(str)/2:]), steps-1) 24 | } else { 25 | n = totalStones(stone*2024, steps-1) 26 | } 27 | memo[[2]int{stone, steps}] = n 28 | return n 29 | } 30 | 31 | func main() { 32 | stones := utils.ExtractInts(input) 33 | var sum int 34 | for _, s := range stones { 35 | sum += totalStones(s, 25) 36 | } 37 | utils.Println(sum) 38 | 39 | sum = 0 40 | for _, s := range stones { 41 | sum += totalStones(s, 75) 42 | } 43 | utils.Println(sum) 44 | } 45 | -------------------------------------------------------------------------------- /2024/day13.slouch: -------------------------------------------------------------------------------- 1 | =fracs -<{ [c - a*(x*c - y*b)/(x*a - y*z), y, x*c - y*b, x*a - y*z] } 2 | =total map fracs | filter -<((%?) and (%?)) | sumWith -<(3*(/) + (/)) 3 | groups | map ints | total 4 | groups | map (ints | set 4 (+ pow 10 13) | set 5 (+ pow 10 13)) | total -------------------------------------------------------------------------------- /2024/day18.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2024, 18) 10 | 11 | func path(bytes []utils.Pos) int { 12 | corrupt := make(map[utils.Pos]bool) 13 | for _, p := range bytes { 14 | corrupt[p] = true 15 | } 16 | g := utils.Grid{X: 70, Y: 70} 17 | queue := []utils.Pos{{X: 0, Y: 0}} 18 | seen := make(map[utils.Pos]int) 19 | best := 999999 20 | for len(queue) > 0 { 21 | p := queue[0] 22 | queue = queue[1:] 23 | if p == (utils.Pos{X: g.X, Y: g.Y}) { 24 | best = utils.Min(best, seen[p]) 25 | continue 26 | } 27 | for _, m := range p.ValidMoves(g) { 28 | if s, ok := seen[m]; (!ok || s > seen[p]+1) && !corrupt[m] { 29 | queue = append(queue, m) 30 | seen[m] = seen[p] + 1 31 | } 32 | } 33 | } 34 | return best 35 | } 36 | 37 | func main() { 38 | var bytes []utils.Pos 39 | ints := utils.ExtractInts(input) 40 | for i := 0; i < len(ints); i += 2 { 41 | bytes = append(bytes, utils.Pos{X: ints[i], Y: ints[i+1]}) 42 | } 43 | utils.Println(path(bytes[:1024])) 44 | 45 | n := sort.Search(len(bytes), func(n int) bool { 46 | return path(bytes[:n]) == 999999 47 | }) 48 | utils.Print(bytes[n-1].X, ",", bytes[n-1].Y, "\n") 49 | } 50 | -------------------------------------------------------------------------------- /2024/day19.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2024, 19) 10 | 11 | func possible(design string, patterns []string) bool { 12 | return utils.Any(len(patterns), func(i int) bool { 13 | rem := strings.TrimPrefix(design, patterns[i]) 14 | return len(rem) < len(design) && (len(rem) == 0 || possible(rem, patterns)) 15 | }) 16 | } 17 | 18 | var memo = make(map[string]int) 19 | 20 | func possibilities(design string, patterns []string) int { 21 | if _, ok := memo[design]; !ok { 22 | memo[design] = utils.Sum(len(patterns), func(i int) int { 23 | if p := patterns[i]; !strings.HasPrefix(design, p) { 24 | return 0 25 | } else if len(design) == len(p) { 26 | return 1 27 | } else { 28 | return possibilities(design[len(p):], patterns) 29 | } 30 | }) 31 | } 32 | return memo[design] 33 | } 34 | 35 | func main() { 36 | groups := utils.Split(input, "\n\n") 37 | patterns := utils.Split(groups[0], ", ") 38 | designs := utils.Lines(groups[1]) 39 | utils.Println(utils.Count(len(designs), func(i int) bool { 40 | return possible(designs[i], patterns) 41 | })) 42 | 43 | utils.Println(utils.Sum(len(designs), func(i int) int { 44 | return possibilities(designs[i], patterns) 45 | })) 46 | } 47 | -------------------------------------------------------------------------------- /2024/day2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2024, 2) 10 | 11 | func safe(ints []int) bool { 12 | w := utils.SlidingWindow(ints, 2).([][]int) 13 | return (utils.All(len(w), func(i int) bool { 14 | return w[i][0]-w[i][1] > 0 15 | }) || utils.All(len(w), func(i int) bool { 16 | return w[i][0]-w[i][1] < 0 17 | })) && utils.All(len(w), func(i int) bool { 18 | d := utils.Abs(w[i][0] - w[i][1]) 19 | return 0 < d && d < 4 20 | }) 21 | } 22 | 23 | func main() { 24 | lines := utils.Lines(input) 25 | utils.Println(utils.Count(len(lines), func(i int) bool { 26 | return safe(utils.ExtractInts(lines[i])) 27 | })) 28 | utils.Println(utils.Count(len(lines), func(i int) bool { 29 | ints := utils.ExtractInts(lines[i]) 30 | s := safe(ints) || 31 | utils.Any(len(ints), func(i int) bool { 32 | del := append([]int(nil), ints...) 33 | utils.DeleteSliceIndex(&del, i) 34 | return safe(del) 35 | }) 36 | if s { 37 | fmt.Println(i) 38 | } 39 | return s 40 | })) 41 | } 42 | -------------------------------------------------------------------------------- /2024/day2.slouch: -------------------------------------------------------------------------------- 1 | =input lines | map ints 2 | =safe deltas |: (all (>0) or all (<0)) and (all (abs |: >0 and <4)) 3 | count safe 4 | =alts cleaves | map (set 1 tail | concat) 5 | count -:(safe or (alts | any safe)) -------------------------------------------------------------------------------- /2024/day20.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2024, 20) 8 | 9 | func main() { 10 | grid := utils.ToByteGrid(utils.Lines(input)) 11 | m := utils.MakeSimpleMaze(grid, '#') 12 | dists := m.DistancesFrom(utils.Locate(grid, 'E')) 13 | 14 | n := 0 15 | for p := range dists { 16 | for m := range dists { 17 | d := p.Dist(m) 18 | n += utils.BoolToInt(d <= 2 && dists[p]-(dists[m]+d) >= 100) 19 | } 20 | } 21 | utils.Println(n) 22 | 23 | n = 0 24 | for p := range dists { 25 | for m := range dists { 26 | d := p.Dist(m) 27 | n += utils.BoolToInt(d <= 20 && dists[p]-(dists[m]+d) >= 100) 28 | } 29 | } 30 | utils.Println(n) 31 | } 32 | -------------------------------------------------------------------------------- /2024/day22.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2024, 22) 8 | 9 | func next(x int) int { 10 | x ^= x << 6 11 | x &= (1 << 24) - 1 12 | x ^= x >> 5 13 | x &= (1 << 24) - 1 14 | x ^= x << 11 15 | x &= (1 << 24) - 1 16 | return x 17 | } 18 | 19 | func main() { 20 | secrets := utils.ExtractInts(input) 21 | utils.Println(utils.Sum(len(secrets), func(i int) int { 22 | n := secrets[i] 23 | for i := 0; i < 2000; i++ { 24 | n = next(n) 25 | } 26 | return n 27 | })) 28 | 29 | sales := make(map[[4]int8]int) 30 | for _, n := range secrets { 31 | var prevPrice int8 32 | var deltas [4]int8 33 | seen := make(map[[4]int8]bool, 2000) 34 | for i := 0; i <= 2000; i++ { 35 | price := int8(n % 10) 36 | n = next(n) 37 | copy(deltas[:], deltas[1:]) 38 | deltas[3] = price - prevPrice 39 | prevPrice = price 40 | if i >= 4 && !seen[deltas] { 41 | sales[deltas] += int(price) 42 | seen[deltas] = true 43 | } 44 | } 45 | } 46 | var best int 47 | for _, v := range sales { 48 | best = utils.Max(best, v) 49 | } 50 | utils.Println(best) 51 | } 52 | -------------------------------------------------------------------------------- /2024/day25.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "lukechampine.com/advent/utils" 7 | ) 8 | 9 | var input = utils.Input(2024, 25) 10 | 11 | func main() { 12 | groups := strings.Split(input, "\n\n") 13 | var locks [][5]int 14 | var keys [][5]int 15 | for _, group := range groups { 16 | lines := utils.Lines(group) 17 | cols := utils.Transpose(lines).([]string) 18 | var a [5]int 19 | for i := range a { 20 | a[i] = strings.Count(cols[i], "#") 21 | } 22 | if utils.CharCounts(lines[0])['#'] == 5 { 23 | locks = append(locks, a) 24 | } else { 25 | keys = append(keys, a) 26 | } 27 | } 28 | 29 | var n int 30 | for _, l := range locks { 31 | for _, k := range keys { 32 | n += utils.BoolToInt(utils.All(5, func(i int) bool { 33 | return l[i]+k[i] <= 7 34 | })) 35 | } 36 | } 37 | utils.Println(n) 38 | } 39 | -------------------------------------------------------------------------------- /2024/day25.slouch: -------------------------------------------------------------------------------- 1 | =fits map transpose |< zipWith (+) | all (count "#" < 8) 2 | groups | cleave (head | all (== "#")) | combos | count fits 3 | -------------------------------------------------------------------------------- /2024/day3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "regexp" 5 | "strings" 6 | 7 | "lukechampine.com/advent/utils" 8 | ) 9 | 10 | var input = utils.Input(2024, 3) 11 | 12 | func main() { 13 | var sum1, sum2 int 14 | enabled := true 15 | for _, match := range regexp.MustCompile(`mul\((\d+),(\d+)\)|do\(\)|don't\(\)`).FindAllString(input, -1) { 16 | if strings.HasPrefix(match, "do") { 17 | enabled = match == "do()" 18 | continue 19 | } 20 | ints := utils.ExtractInts(match) 21 | sum1 += ints[0] * ints[1] 22 | sum2 += utils.BoolToInt(enabled) * ints[0] * ints[1] 23 | } 24 | utils.Println(sum1) 25 | utils.Println(sum2) 26 | } 27 | -------------------------------------------------------------------------------- /2024/day3.slouch: -------------------------------------------------------------------------------- 1 | =input regex `mul\((\d+),(\d+)\)|do\(\)|don't\(\)` 2 | sumWith (ints | product) 3 | =enabled scan { match [true: (y == "do()"), false: x] (y | contains "do") } true input 4 | zipWith {(int x) * (y | ints | product)} enabled | sum 5 | -------------------------------------------------------------------------------- /2024/day4.slouch: -------------------------------------------------------------------------------- 1 | =input input | lines | map chars 2 | =vars concat [input, (transpose input), (diags input), (diags (map reverse (transpose input)))] 3 | vars | map concat | sumWith -:(count "XMAS" + count "SAMX") 4 | stamps [[0,0],[0,2],[1,1],[2,0],[2,2]] | map concat | count (in ["MSAMS", "SMASM", "MMASS", "SSAMM"]) 5 | -------------------------------------------------------------------------------- /2024/day5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | "strings" 7 | 8 | "lukechampine.com/advent/utils" 9 | ) 10 | 11 | var input = utils.Input(2024, 5) 12 | 13 | func main() { 14 | rules, updates, _ := strings.Cut(input, "\n\n") 15 | var part1, part2 int 16 | for _, line := range utils.Lines(updates) { 17 | u := utils.ExtractInts(line) 18 | ruleSort := func(i, j int) bool { 19 | return strings.Contains(rules, fmt.Sprintf("%d|%d", u[i], u[j])) 20 | } 21 | if sort.SliceIsSorted(u, ruleSort) { 22 | part1 += u[len(u)/2] 23 | } else { 24 | sort.Slice(u, ruleSort) 25 | part2 += u[len(u)/2] 26 | } 27 | } 28 | utils.Println(part1) 29 | utils.Println(part2) 30 | } 31 | -------------------------------------------------------------------------------- /2024/day5.slouch: -------------------------------------------------------------------------------- 1 | =sort sortBy { input | groups | .0 | contains (x + "|" + y) } 2 | =parts input | groups | .1 | map (split ",") | cleave -:(_ == sort) 3 | parts.0 | sumWith -:(.(len/2) | int) 4 | parts.1 | sumWith (sort |: .(len/2) | int) 5 | -------------------------------------------------------------------------------- /2024/day7.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2024, 7) 8 | 9 | func concat(x, y int) int { 10 | return utils.Atoi(utils.Itoa(x) + utils.Itoa(y)) 11 | } 12 | 13 | func canMake(r int, acc int, xs []int) bool { 14 | if len(xs) == 0 { 15 | return r == acc 16 | } 17 | return canMake(r, acc+xs[0], xs[1:]) || 18 | canMake(r, acc*xs[0], xs[1:]) 19 | } 20 | 21 | func canMakeConcat(r int, acc int, xs []int) bool { 22 | if len(xs) == 0 { 23 | return r == acc 24 | } 25 | return canMakeConcat(r, acc+xs[0], xs[1:]) || 26 | canMakeConcat(r, acc*xs[0], xs[1:]) || 27 | canMakeConcat(r, concat(acc, xs[0]), xs[1:]) 28 | } 29 | 30 | func main() { 31 | lines := utils.Lines(input) 32 | utils.Println(utils.Sum(len(lines), func(i int) int { 33 | ints := utils.ExtractInts(lines[i]) 34 | return ints[0] * utils.BoolToInt(canMake(ints[0], ints[1], ints[2:])) 35 | })) 36 | utils.Println(utils.Sum(len(lines), func(i int) int { 37 | ints := utils.ExtractInts(lines[i]) 38 | return ints[0] * utils.BoolToInt(canMakeConcat(ints[0], ints[1], ints[2:])) 39 | })) 40 | } 41 | -------------------------------------------------------------------------------- /2024/day8.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "lukechampine.com/advent/utils" 5 | ) 6 | 7 | var input = utils.Input(2024, 8) 8 | 9 | func main() { 10 | grid := utils.ToByteGrid(utils.Lines(input)) 11 | g := utils.Grid{X: len(grid[0]) - 1, Y: len(grid) - 1} 12 | an := make(map[utils.Pos]bool) 13 | for y := range grid { 14 | for x, c := range grid[y] { 15 | if grid[y][x] == '.' { 16 | continue 17 | } 18 | a := utils.Pos{X: x, Y: y} 19 | g.ForEach(func(p utils.Pos) { 20 | if p == a || grid[p.Y][p.X] != c { 21 | return 22 | } 23 | d := p.Rel(a) 24 | if anti := p.Add(d.X, d.Y); g.Valid(anti) { 25 | an[anti] = true 26 | } 27 | }) 28 | } 29 | } 30 | utils.Println(len(an)) 31 | 32 | for y := range grid { 33 | for x, c := range grid[y] { 34 | if grid[y][x] == '.' { 35 | continue 36 | } 37 | a := utils.Pos{X: x, Y: y} 38 | g.ForEach(func(p utils.Pos) { 39 | if p == a || grid[p.Y][p.X] != c { 40 | return 41 | } 42 | dx, dy := p.X-a.X, p.Y-a.Y 43 | for anti := a.Add(dx, dy); g.Valid(anti); anti = anti.Add(dx, dy) { 44 | an[anti] = true 45 | } 46 | }) 47 | } 48 | } 49 | utils.Println(len(an)) 50 | } 51 | -------------------------------------------------------------------------------- /2024/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "aoc2024" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | regex = "1.10.2" 8 | -------------------------------------------------------------------------------- /2024/rust/src/day01.rs: -------------------------------------------------------------------------------- 1 | fn parse(input: &str) -> (Vec, Vec) { 2 | let (mut left, mut right): (Vec, Vec) = input 3 | .lines() 4 | .map(|line| { 5 | let (left, right) = line.split_once(" ").unwrap(); 6 | (left.parse::().unwrap(), right.parse::().unwrap()) 7 | }) 8 | .unzip(); 9 | left.sort(); 10 | right.sort(); 11 | (left, right) 12 | } 13 | 14 | pub fn part1(input: &str) -> String { 15 | let (left, right) = parse(input); 16 | left.iter() 17 | .zip(right.iter()) 18 | .map(|(&l, &r)| (l - r).abs()) 19 | .sum::() 20 | .to_string() 21 | } 22 | 23 | pub fn part2(input: &str) -> String { 24 | let (left, right) = parse(input); 25 | left.iter() 26 | .map(|l| l * right.iter().filter(|&r| r == l).count() as i64) 27 | .sum::() 28 | .to_string() 29 | } 30 | -------------------------------------------------------------------------------- /2024/rust/src/day02.rs: -------------------------------------------------------------------------------- 1 | use crate::utils; 2 | 3 | fn parse(input: &str) -> Vec> { 4 | input 5 | .lines() 6 | .map(|line| utils::ints(line).collect()) 7 | .collect() 8 | } 9 | 10 | fn safe(report: &[i64]) -> bool { 11 | let deltas: Vec = report.windows(2).map(|w| w[1] - w[0]).collect(); 12 | (deltas.iter().all(|&d| d > 0) || deltas.iter().all(|&d| d < 0)) 13 | && deltas.iter().map(|d| d.abs()).all(|d| 0 < d && d < 4) 14 | } 15 | 16 | pub fn part1(input: &str) -> String { 17 | let reports = parse(input); 18 | reports.iter().filter(|&r| safe(r)).count().to_string() 19 | } 20 | 21 | pub fn part2(input: &str) -> String { 22 | let reports = parse(input); 23 | reports 24 | .iter() 25 | .filter(|&r| { 26 | safe(r) 27 | || (0..r.len()).any(|i| { 28 | let mut r = r.clone(); 29 | r.remove(i); 30 | safe(&r) 31 | }) 32 | }) 33 | .count() 34 | .to_string() 35 | } 36 | -------------------------------------------------------------------------------- /2024/rust/src/day03.rs: -------------------------------------------------------------------------------- 1 | use crate::utils; 2 | use regex::Regex; 3 | 4 | fn parse(input: &str) -> Vec<&str> { 5 | let re = Regex::new(r"mul\((\d+),(\d+)\)|do\(\)|don't\(\)").unwrap(); 6 | re.find_iter(input).map(|m| m.as_str()).collect() 7 | } 8 | 9 | pub fn part1(input: &str) -> String { 10 | parse(input) 11 | .iter() 12 | .map(|m| { 13 | if m.starts_with("mul") { 14 | utils::ints(m).product() 15 | } else { 16 | 0 17 | } 18 | }) 19 | .sum::() 20 | .to_string() 21 | } 22 | 23 | pub fn part2(input: &str) -> String { 24 | parse(input) 25 | .iter() 26 | .fold((0, true), |(acc, enabled), m| { 27 | if m.starts_with("do") { 28 | (acc, m.starts_with("do()")) 29 | } else { 30 | ( 31 | acc + enabled as i64 * utils::ints(m).product::(), 32 | enabled, 33 | ) 34 | } 35 | }) 36 | .0 37 | .to_string() 38 | } 39 | -------------------------------------------------------------------------------- /2024/rust/src/day11.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use crate::utils; 4 | 5 | fn total_stones(s: i64, steps: i64) -> i64 { 6 | let mut memo: HashMap<(i64, i64), i64> = HashMap::new(); 7 | 8 | fn rec(s: i64, steps: i64, memo: &mut HashMap<(i64, i64), i64>) -> i64 { 9 | if steps == 0 { 10 | return 1; 11 | } else if let Some(&n) = memo.get(&(s, steps)) { 12 | return n; 13 | } 14 | let n = if s == 0 { 15 | rec(1, steps - 1, memo) 16 | } else if s.to_string().len() % 2 == 0 { 17 | let s = s.to_string(); 18 | let (l, r) = s.split_at(s.len() / 2); 19 | rec(l.parse().unwrap(), steps - 1, memo) + rec(r.parse().unwrap(), steps - 1, memo) 20 | } else { 21 | rec(s * 2024, steps - 1, memo) 22 | }; 23 | memo.insert((s, steps), n); 24 | n 25 | } 26 | rec(s, steps, &mut memo) 27 | } 28 | 29 | pub fn part1(input: &str) -> String { 30 | utils::ints(input) 31 | .map(|s| total_stones(s, 25)) 32 | .sum::() 33 | .to_string() 34 | } 35 | 36 | pub fn part2(input: &str) -> String { 37 | utils::ints(input) 38 | .map(|s| total_stones(s, 75)) 39 | .sum::() 40 | .to_string() 41 | } 42 | -------------------------------------------------------------------------------- /2024/rust/src/day25.rs: -------------------------------------------------------------------------------- 1 | use crate::utils; 2 | 3 | pub fn part1(input: &str) -> String { 4 | let mut locks: Vec<[usize; 5]> = Vec::new(); 5 | let mut keys: Vec<[usize; 5]> = Vec::new(); 6 | input.split("\n\n").for_each(|g| { 7 | let a = std::array::from_fn(|i| { 8 | g.lines() 9 | .filter(|line| line.bytes().nth(i) == Some(b'#')) 10 | .count() 11 | }); 12 | if g.starts_with("#####") { 13 | locks.push(a); 14 | } else { 15 | keys.push(a); 16 | } 17 | }); 18 | utils::pairs(&locks, &keys) 19 | .iter() 20 | .filter(|(l, k)| (0..5).all(|i| l[i] + k[i] <= 7)) 21 | .count() 22 | .to_string() 23 | } 24 | 25 | pub fn part2(_input: &str) -> String { 26 | "Merry Christmas!".to_string() 27 | } 28 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module lukechampine.com/advent 2 | 3 | go 1.15 4 | --------------------------------------------------------------------------------