Advent of Code 2023
Day 1 - Part 1
sample01_1 = """
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
"""
input01_1 = """
jjfvnnlfivejj1
6fourfour
ninevbmltwo69
pcg91vqrfpxxzzzoneightzt
jpprthxgjfive3one1qckhrptpqdc
mxphxfnffninethreetdj5jgknqfrxmhxfivexcxqv
three7pktwo4279z
1qcbszfgonedjcqj66929
fivesixthreeptcqjnkzgdfgzspmlvmmhn3
vm2sixseven
1nine6oneeightnine5lfrzmzh7
7onevsffj78ninejcnnvgn65
qstwonepcd3twosixrmcnxhfzv
3bnjfrfourseventwo
zpcdmvmktlrrq8sixgjtxxjpt8fcstt1
nine1gkmptbfsix87
9ldmlbchvnvgfivesixnine7zrt
45mjmblfqjvf9
onehcpgmvd837sgzgsqqrtseven
rhjfvkznjdvlgv9one8
22xkkdsvfvfourhdpchs
sixzjx5kvjbcfgcsrjndznkrtf6
1fourmk8three3seven
4716lpzhdcbone6seventwo
443two27
9sgtwoseven6
pjtbhxchqfseven18tznxpbsppk
9eightwonkt
htsgxmrfsevenone8qjxhjsixnbsvcf5
5jmnjnnfsfoursevenprtjzdxmxj7six
dthreenrzonefourcxfrzsvtfz9xb
6kvfn
vlfbzpbpseven8tspgqfdzkmfivefourzjzdbxgtvx
2rfqtfttqzkkzdjbjxnx51xrzczxmfmc2two
3fnncmsdz1bnxvlfxng
seven789bgzpszjd3
6four8gjsmbztmp
sjvmmb9h
6jqttjkpjc145
9threedzjjqnhrngktscfmc
5onesix
nine2onelpzhtrbninexkgtjqg
6nined
29xzfour7seven9pcvdbcgvtv
hjdtscdc6twotwosixsevensix9six
stmpvhnssixtwoffnhpn25
45fourbpsghkqxqm9fmvhssbntdtwo64
nine835four
leightwothreesevenlhlmqcgcpfour9
fgsfsqgkcctzcltpvpjhlb5eight4one
four9four184five9
67seven7twobdcltwonenh
nsdbone5two16
sixsix3jxfctsrsvfcrpbxtthmspdlqqrnckxtngnx
fxftk3svcczpknmfourhlndmg
eight4sevenmrlkcqx4three
7ninerpcrqt46gtnlzlmknine
hppggtwohcckscs5eighttwo
phzdqznlbkthreephllsb32eighttwo9six
6four8fxcmngbnine3
seven6five23seven
9seven6bfqkxsjvcpninehmprgsldb
tffjstchhs3rnjsmlnr3sevenlkjzkrdg3mmlgbgnnjzoneightm
913
lvsqbjjsonethreeone864ncrlpdghgkfive
fvlmhpxcrktwo3ninejm6eightxmc
sevenjbnc2zvxnr4
mqjztddmfmnskhlvvp2
six1fivesixsevenninenine
vpbpbsixsqvxfvf6
6jjqln83one
3dbone3
ssczbsgp2fourdknjszzbvtlgtdplgplrnznmhdfivefdd
threesevenqctdslt457
eightthree9eightfiveninetzhmhg
bsmzhmrm1eight5
pzhpleighttbhhfxfdgprfjsxrzl7sixsixjgghqbr
one5onecfdbpvxbdlmmdbxqdlbldjbz8
qxsbz4rjdgcfsvmqthreeone3mtwo
13zls3
zpjlgbjrkl6four5
264sevenfive
413vhsevennpbnine
gn9sevenhhhnblflxkeightnine
hgdfdsdb5seven
eightczrstqtcjmrpbhhdxrflkcjpsdjbskfvzdglt6nine
jrgr15mzkpt5
lxzlvmrdcvglcjsjzxm3748hjlvtgz
ninekxcqcpztqfoureightsrdhtmnbpsqkc5
vxfdkmp4fourtwopdpfmcqnrqkmvf
prkkmcccpone4qthree
lxxqfourkrttdqlhkjhp5
five7three
sixmljbdl2seven8six3ffrfc
6threexgtvlxthree5fiveseven
three86pztxhlcfour
eightfiveeight79
5ljzqvbgknk4
seven4cnrxrv9
brtwone8jsvbpstpmlbrxrjfivehhhqbvk
three69two3dhvzj9
fourfoursevenninelpjs5threevnc3
42nine441xbc
sevenfour2tqb42one
btccgptzllfivesixtwo6
hdbzgcmznbnrq8cvzrqtpqm
jqzmone5threehrqhbdnfxhkqnvm
98nrcvftzpslxnine
five58one8snpvggzjbqthree79
lkccfpfn37onenine6
css9four2
jbtffive6mtfzvkdpjnthreeeight
224fourtwojc4
spceightwolbrcfkbrtwo8dkfmvrmrglmrsxlseven9nine
threeckdrrznbbhnpsrmbrxlmfjz1twothree2
3twokcfivetwosix4
k12mqeighthgdtthxjtwo
coneightqtpgsjseven5dzqpvgtjm
dpkjqkx22llklllblknine4
svjmxbq8hfzjsbtccjdmqvbjcpklmqbseven665
8rbfzjxlqx
onefive3nineeight5
eightqrlkf4two
931
41cvfivebfsxdkljjjkjhm8ftfdtnpsdmtkln
sixjcnbeightnjtbck72dg
tworvqfjdlr545lbpmlxknsd
kgnt7fiveone3
twofourrxmcmj894stppprqjf
qcqpxnztmntwok34three28
four1sevennlqvbk
6fkjkbc
2htpxbqvtg3one
2threezhxzfslfxhvzdbfour15
nrfdrzdjtlthreeonennzfbone9one
sixtwosevenqplrqvxreight6
djmzrfq3eight7five5
jthreeeight51sixqlvgvm
foureighteight4vvg98
tttrnk2ctfpk7692mbccxhmpnl2
bbsix2
1two3five89zjrjnbpt6
29787jbhkhtbnbgfoursixfour
vpzmcqcvfour58
9eightfcvfeight4one
cdbdlseven6zvzl3tshhdtlczsstdbksthree
three78
hdmmprbbk9hvkpb
vfivencslcc974
6jthreesevenstksbsxttctjkdnxgjseven
sixeight38sevenfive
7sixnzcfgfjpzmcdsprgcnvspfive
tttcfpm9sevennine
x7dfxhgtqmeightveightfgrqj
zktxptkzztwobztnfqvgxlkrsdhqhntqcnfknine6
9kthreenglrnrxn8sixzlfdmfcdvnd
xjznine3332jtrfnkf
688k3eightone
4four2chz
1zpbmzvgxmhqdkr3four89four
nqbthreeztjmkdgtwo53
qvfjzclkrkslfmtpdhjeight4fivefour
964eight91qhghxjxhcdslsnfour
45twojrbjxb
292sixthreekgzpzxxxk
6dgmmtwotwo
1msixthree4sixeighttwoeight
sixfourt9k
one1five6fourthreetwo7two
fourjmbfrhltwosix42
frgfnk8
138
4nn79fourfour28
7zs5eightonenineqnzpsf6
bqjndhdtqqhpmltzfv27bqvgklpmfvhgvplbpnxhjvprpldpg
48tcrntjbninesbkkbbd
nineeight5nineljhnxhqbpkbbkttwo
scbbhqpcxthree1three1
vlczgnrlz38threekjone
nine7ckxh
hpgvrtkpqpbjdlkpj2
ninetwo63hhnsmoneightjtl
zkhrcrb743fhjpfvdcxq9three
nineeight5pfour9sixsqjnkpg3
sixthreectddzgzrh9
xjdgplninetfcldlnzftcv63four
fivefourmrrb1three
2mqxhngvb8
5njfgllzxnjlqdgn
five34fourfive1cddmdhrbmrjpz
fiveg6seven1
eightggzxtddx8mgl7seven9five
6tlmlfrsixbtznxhhpclb
twospsjtmnfnmfv36
tcnmlsljtwo9onekcksj
6onenine9mhznxmoneightnvq
4seven6jxtknddnkfivefivenine
qxpcxrxstwoninekvlsmtckcd1cxqccqss2
8pk3xjbsevengfcseveneighteight
7sevenstsmqcthreexqdh
three6sevenmeightjeight5four
958eightvg9bjrfpjfq6
9zninegdmqrtxtlnfiveeight3twotwo
989pdblcmkxhn
sixvvkvjlndtqjlcqsixktmhpzs9d
4threepzgdjvsqhseven
fzfmnine5eight
sevenvv78threexpfxxktwo5
8pgjdzvb1
vj7
sevennine3eightfzpxdxpmseightwozvb
gxftsptzcm1jcnmkqxnxr5five9onefour
2fiveclxxnxmsevenzmz6rfvhkrseven3
fqqdlnkb45lgjjnk5seventwo
six5dhrkkxr
kmrddmfpzsfmkthreeonefour1xxhshbxd8
gdthree3fivefour
sixsixj772four
eight53
sixfoursix333
one8twothreeseven766
bpnvgxjtwohmlgqpx3nineeightvnine
95one88six
4onefrlccksvfcc7
xbjh67
vzrgvrkzthreesix2
five8eighttjxphqzstx
fiveone3sixseven
nine44eight66
eighttwogndjkpdxqjvjmd7kgxvjfkltv
mdpxgkxvfheightt41onefoursix
vqnzsgmgbglqmjmhmqqlpjjhkszprjc184eightczzbrpxh
jncvmkbone7vttpdnone
bvsmnz7hctzgcfkk
bssqrbzsixqx7
nhtfvdnrtqqvjnzdgc4fvlzkm
zhvdbthreeeight61dp
24pv
onesjjdct1zcknmfjfjvmfivepxzfds7
3six7one5seventwo2
twosixonemjsc2vg8lzvjrpnnhq
rftwoneqjbq5hcssbxbtvcdsevenfournxhfkrrgjqmzmpmvrvnj
58five5
43nineseven3293three
48sixsevenmgsr23
eight1eight
5hkbzntwo1lplgmfsevengrnhbhg
1dqbbgjfvmfive7sevenninenhkspxbrxm
srtwoneeight1jeightoneeightthree
4cvhfbnine
vsm56
5onev2csngkll7
6six5fivefourzbjkdppp
gdjtp5onehqrngxqd
4fvltc7ninezmpnbzv4twoone
39sevenfxlcsfnkmjninesevennineoneseven
cvfqkvfzx887sgzdpvxvhoneseven
rvrhpssvkgzbbrgbgcvqbvdkfplsvk41bblsvtbqsk29
9ninervjgsjrrtwo1twonbxcvd
8g9one
njznrrcshcpn9rbvbsgpdpv13ninefour
8eightfflllbgkmdh44onenine
9onetwo9two6
hdfmvs6hjtjbzjth7ninefn
dfzgrfivesix67
7l9
onecjeight88hk
hgm2
qt5nine7d8fivevlqjmhsix
nqsix7onennmln2five
6sevensevenmnxnbpmprd6
five2seventhree2nineksczcl
twotwokcmkzgkf9vfcmfqhzvseven
4six2blsfjgmllblxnlfnspxbvvzjnninesevenfour
836
beightwosixonefxlthreepjddrthq9five
22zhppjvmbfszrkrqt
7ljpvtkrmgkfc5pxqpd
xqrtsbzpjxhfn58three362
2fiveqqdptvjxxnrnsrsixbeightfive
gsgfvsfp1mfbrt3dnzttnine44mgmsjmkgv
sixfive4sgxxgsix
3nv3dsevensixmsqfdc5
two66six
ptz4qhkzftvxp4bfnnone
five1five2rjftfiveseven
kvdttwozhzcjk685fourtwolrbmnknp
33srljnsfsxhfninensjh
lkc4
twotgnddfivefourcbfive35
eight4qgthmpptkn
7pqdkhhxqmtkcspmlc59991
lvpbhlpdnvbqdzfmfktvn552
fivefoursixdrscznhfivefive49
439nlvnine
qqxfoursix4xlslqdjvpx3l
bpknbhdtgst7
6four4fourddkk7cdhmdjx53
3sevenseven8two4eightfive9
zj6vmnq1pqrstfkznf6
7lxjzsevensixtddveightp
vbzrnzmcgvqkdrznhtblp8vjnxvs57five
six6eightzmhqvsjzseven
9three4nnhqsstptwo3
twofiverdjfc96dqzeight
six8bgmrplfeightonek93four
sevennine4vzmf
54five6gfour73jpkgt
eight9288threeeight
gjkrnbtseven6618vktqpmhmnine
onejmlgzhpzdfmmkkt3fourpjkjglsd
xqxkqjcsnine6eightxclnthree2
hmthhjbfivesix4gdxjbg
sevenkpjrscqhmfone3zjhxgptlgknine
onerzbfive354
9sldh38nine
twonine9vqdzneight
7one24
2fivesixtnhssqnrhbcxtchjbxspnvkcxbsfrf
kjpjqsnkrqnqpn99fpxfgmttxpxrd4twonebp
hhfrz8zbdjtjjjngcccctwo
mjhvbhrmpmmmbzcmr9four9dczbrfg
mnhbcdc99
11fivedpgmrxptconebdvhfbvfvxfive17
fivegthreesixtwo9k5
ninefourtwo7zjcsfhcfnine
652
five135eight4v
eight6hsjpkf13mhmkggqqvqdmrpcttvs
fourxndjxvpgpthree6vjs8pkt
lvkeight5nthreeskjqc24one
5vmqth
1lmjpflgsix91fourlfldlgmn7
jlpnxblthreebzztvrfg3done
rrnxmsnptwoeight24threedqssix
nfdcrtlb7eightsvhstfourcmrsix3
nbslbqkmmfonellrfpmvjnsix944
seven2pcstwoqfg
six9nineninedpsixpqcl
two53mgfcbhmlpr1bl1x
bdzvksix8mlhvvscvvc
seven1three9two
4ninegvzqzbhckptwo8
5zspmjkssghgtgpdpg3threeseven
6fournineeight
eight7jsxmdsix4jcnmzhxnrczslgclj
xjlmqfgd9sjvvhmxbnrpztrgtvgklzt3two
3gkfgrz71
sevenfsix4
one84532vkhbvfzpbthree4
46zhdmrrh3
eight7tdfbjnzqhs
rfqfl6nine7
nkpztmkbpqzn7
8mzprpmn6
2threebntdqxfdonettbgnbx7cp3
5two77
eight7three
rhcbnrfslm8dqdthddqckonerclsshqhxpjdmgnmvsixgmqxt
9five2
jkzntwo5fiveonetwonec
48oneseven
7fourlqptgfkone
six2hnlbhzxjjfpdeightwod
46onel
przvrp3ninethreenine2
tnine2chbvxbkbnq
sixjnbsrtrhg9twob
knkdb5852fourfiveone6
6onevndbhone
4thqp
xdnbtxgtjrgffourseven4threehzqxzqfourseven
cpkbtl2
three6psqmcxphvtfhn
two42ninevndsevenmljgncshctnjrvszhnkt
threefrvxonesqkcjdlk2mrztrlttjvs
knvgqtqvn22jkjnxbxpkdfourfour9
24oneqnnnztsshx6
eighttbxsheight2phksevenptwo8
seven8bvsnjhrl4hllmzbtlmone1
three1626jvfqthree
bspdn9rfgnztqgkrkk964
9kprlqsmxnine
6fourfourninethreesixfourfive1
vkkggjljfxthreeeightseven6
threefiverdvrtwo9tztjmghsz
65rpk2six7six3
bfgmtntc83
3four5gtdsnljslceightnmtfbktwojnvqfour
78ctscpstjtcdrqnskhrzsddhrsthreesix4btxv
lmrscztwoxsgphp2five9
eight4one
tktpzntsffnpptpgmbndxhxskjlltpvbsvjrpmgbmdvjlqklnl1
8hdhqmskvpdppnthvdlctthreelxvssgqzzcql
eight6bjd3jbscchfnpqnine1
r51three
dpgscvm8eight
6sbgzk
two5rflnshkn
zrplqqseven2ones
fiveeightsevenfive6onetwo
crjtrkcl8five592mkddrseven
fiveone1qgrdzkgnv
3svvtjmq8
fivethreeninenine1skhctbxcckztkq
threeppn71threelfourvpqfour
ninetwoseven9
5x6gqfsjqbrtr1slnlhhpq
1xb
xspkbeight9
9onesixthreexjlscbx
fj38vxpmlccfivemsmdqfour
6twonvpxtkhlcpfvsgjonethree
fivefiveninesixninethree3
26four2
d8hhbbgfoursixfour
hdkqlhzs9hqcffcnzgsmhninegzhxthfivev
onefourone9eight1sixdftmmzmj8
qpnxmtl125eightsix9four
ninefourvnxlmjp2fhdhzbcncs
ninerhqpddslsh22sevennine9
33vdj12
2vqeight
vbkfgbgflskxcfivefourzxvcbdj6
6gssbzzgvb1
6hmnkjfksrdmjhnqfv6five8
92fouronefivebs96
2twofive8
mkkplqtjmfive45ddh
fgtf933lgbxcnjv
tsmbtnst65fpcsxcljbc6
4dthreetpbqbjvlrnineseventwo
3334
85five
62twomcnnj6fourhj
fiveeight4
sevenstxmqfdlp9threeeight
55jnkhjh2hnqf
xvrrqtr7onefouroneeightseven
66btjrmvsfiveqpx
1jbzjcsevenninerpdhfvjrrg
1tsixsixdxqfdhpbsixthree
h9twobfmqltwo
eightrqlgqbmdcj7fourjbfourptdprg4
6c8gbxxdhtxcxxgdntgsfninetwoqm
67foursixgshpnxpsb
gxfnbbrrfour4hdnzznc6five1threermh
eight3fpqnbfbghshhkqmzmtkseven5
g5threenine
fivedseven3three469vjzmbklbm
gxpktrpseven9kqbgvgqnqs6
one64
5threerxbfive5
9ghdszvpbbldztqb1
1xkzdblrpcjtwo
smcnpxg3one58ttdsstwo8
fourjhqxgjrms9oneone78four1
9two6rxrrxlzc6tmzmxs5lq2
onebnfnc9fqgczzdxczheightfrvrsixjcxhntbmk
8twofivezmnssevenlfxzcqmqtt2
threepnp3hdvphnthree8seventhree
three441seven7fourthree
99rvhgrxfsixfive
zvtwone4three8
5nine84eight
crtztqjdmninesevennflskqgzrvsixqrthzhmnxsjzstj8
sevenntxmdvhb931sevenninethree
kxfk91fivehqgntfdhrj9897
seven5p
three1nh3
gjdv22two1twoq
2twonnjthree
dlhmbplgqthreeonergqmxbbzzlvvmn4
6twohldcs9
6fourpjnztmqt
threephjblksrhk1mzcfpvqx2mdlprtg52
fmg5
bgxd2dvlnstwo3six1
gg64onerksrfour7four
eight47ppeightsevengpzkn
92mzfive2jh
sevenjrnine8fivesixfivefour
zmzxq869
rjpgzqmsixninebvjkmb25seven
9dfxrrfbqpr
five2nine2rzps7twozkdjmbnc
hsrpc9
vsqfourgdkrzkf87four2seven
two9eighteight42four3
eight9threefive37
twobpdzktzm892
3lldqhone1six
six84nineseven7
nine7xtjqzqbxvx
48twoeightthreepbjdmblzt
5rzczxmeight
seven85seven1
threezfjzttheight9
7fourthreenine3qfchk7eightone
9h157ggstjh
lxmhllvjxzsevenntnzrnkdjfive2
64dzxxpgjcvhqkpzfivecjg
3hfllvslrdgfiveckxgkzstqseven2seven
four3fiveone
two9eight26
lsix9two
two8sjvpnn2dpqhpfzgmthree4sevenblsmlfppg
t9fdsgpmsghlp6ninesixsix
9twonezk
53fthcvkktx8eight1vkhrp
fmslbnseven53four
kjtwone486onefqdklnpdgone
5threeqvkz
ftwone5sthreegcdfivefour
nine5sixhjconesix
454eight5vsggjtjcxttndvg4
six83hk
5eightfourpzv8bjbbeightwopp
79nine5eight
1sixsqcpdmpqbg137ll3
fsdbv64sixlpdd
nine59
vvnmt32
eightsevennxcvvnqsix63four1eight
sixcgtlvnmvjmcqkkxxbtjv6
ninenine6
5fhrsbvdjggnine
twodkgtdghmjthree7
zqkgbnqsixlqlbbhpdkvfourfive71
nine5four3twoneg
lxdpz971nfdsevensevenkjrzf
2rkpbfphxjnnjkcpcphdpkkqbpjrbtqzmd5
pqftnsixjrxqf7six2threeone
six8d145twoqcgkllqmkxmqphoneightt
seven25
5sevenonednlhseven
nkkfsl58xpdbqtptponethreempcxbkqqfbbml
4fgk2
9bxtjskxkhfmz4seven
one78lpplzpbxcxseventwotwo3eight
fbmqtp8one1gqmc3tzdqlnn3eightwoddf
j2
5sixsixnineonesixddpvf
8xdnpczh
7nfmgjjlonesixbfpmxvvcvf2
4mnc
7qjbl8
c7fhtx
lntmsfrbxtbbg7threexrd6
fiveseven4two3
hmmdbzp3three4five
seven5rdkcdh3sixtwo6tql
nine1xglps5zzpztmcm6six
6fourfhxqkhqxeightonejcstpxklkbmk1two
jreightgbpl8mmglzxjz88ztfnlhgvrz
5dcfive1ninenine
twoxkgjbqrmzj8
one3kkxhrgskh6
seven1mhkseven1zdlvnnxxk
sevenonehpkqqxpshttrqcctsxp7
43hdvhgconethreetsbjrkf
xsmvfpnzpthreeqlpnf3
rjhpbsz21six6
onesix4271xgvsbd
4gqnine
516twoseven16vmbl
twosixnine8mnmdjthree
nine7twonine58
4hnslsrxnslrmvmlninethreejcjxn
knsnrdzbcmonetwo4nine8ghzndvjqdxgbzlq
dkpnfpnpp6pqfclgqhsq1rjmsjcbdxxxxvff9
pxnkbkvfiveltvnrpmdg5eightthree9
91vbnvfmdjjt
vpqxgzqlknttwo341
5jlpdhzronetwonevvh
6rhkxqjsznjhspm
nmzsevenkgtb2cptrfhjfd
ds75sixthreethree
bone49ddv
hhhnptkcx9bpvkjlzpm
ctptntzjfive84
cpxb94one3threeclrnsix
ninedtjmdsmcg5eight78
74rbrvt
2four41
sixgpqmtkfdhz7sevenkcnonetwonemcp
lshcphmjvcqdtzbh35rvvsphj7twok
clqbqvtdjpzgkqpfour4plkpsxkcnscnx2
nflseventhreembkbnclftn4ksdc
lljjndhone4
krcthreeseventwofour7oneone
dpjhm2three76
npqtwone31tsgfbbtjtnshhtjvvnfb7
5sixthreesix
6cjzsix17onehbgdftzmxc
tpmkqthreesxhzsfqfjv5five6
9eightkxkpqtoneffxseven8jfdbcsmclxjbr
threelz7zdcqlntmtlstbx
nine3mtwotvmsctzlhtgcgxrmxkseven
prtwone86seven
nb2eight62zff
fourfourmmlqjczfour6foureight
3gjjsppmmjrtrseven
3vcbjsmpbgfttczrseven6bsngjeightseventwo
1dbhsix5sixtbxccqqvsvjttm
csbsthreethreeone7
spt8
five521
eighttwo5three369eight9
53ck8
569fdxfvtninesdbnvtwo4
sevenvvctrsjpvgzphgxblm6sixfourfive
seven6xtcdkmqf15
twothree8233eightqhhpkrcjq
bpmmvdqtvqsfqqdzmjl8six7four
8twodktpzlvmqpgrfbbsix5
bqfmkthreeseventwo87125
qbdttlgc2onehtf749skzfslflbt
seven79jbrh8threefivetwovgqphzpq
skxcbtvbcll27fprcg
dtknkdx1
twozqjbmhmjoneeight2five
5mzscs4twonineeight8four4
698f
twothree3eightklssg
two1kchxfqsixdrc853
9one4dzpqnineonexnzsvpplqgmtclfqfour
hskt1twozqvkxeight
6fkpgsdchnrkgthreetwotwo8
hvnczltjleight4eight1mjsix
ltwo7bmbdjlmlpvjxlttmb
9sixninermdsjhg22
rtgnjpbxtfznt1
btdtnhtdkc4
87eight2htsvgvzxqvhsevenvk
6sixsix1dgszxseven9
1rljjnxckl9bdlptqnqcmnine92
three3two28fivevsevenb
6ksfhxqndcccg66nmmbnz
ktqskd4five
pcvlhhz6
three6three3onesfjvkrjt
fourfour74
txeightwo6gcc8seven44sixg
79hphfdplrsgonefour
nine9twothreeeight
5h2eightwosmd
8threeb7nine5cr
eight528two
fsfzrmlz2nine
8vspddjbhlfn
64ljd4rtnbtwo5vnine
onesixninezggthree4
one8sevenseven47
three238eight45
one251onextjqxztm
lsqrvsgnxh1bxxchgjeight
eight4gdfvltlmn1sixllsbcqpnx
five7smrlbtbk
djnshxnrcrtkk6two9
frcpffjkhp3
ninesix2f2smlspljlqseven8jtfml
1gsvrpkjl
5ninethreejpnbm
4vdmjth6735
eightmnlvzszqtjfour1rphtmntlk355
joneight6six8qgtlffcpbvrcf9xsnvgt9
gfqtnbbzrkfivelmmnmztdgeighthzfbzmpfnztwoxzzpjcsvfive3
threevpgmhleightsevenfive1
ninevmdknklvgbbmsdcmvjzcfcbeightrfmv14
98cb
8one85jpdlsmdpzskjz8two
6three6
fpnine1
5threelonemfbqvssxkbmglt
1zkxhjh5fournine
twoxbczzqhcthree3sixeight
4gdktpzlxzkxnine
ninefivenineplttv8seventwoggsmztd6
onepr3qpzf7seveneightfour7
tdfpsssrczgzgmxlpmqb2zjjllrqstnine3threemqtzz1
sevenninetwohsztwomvzdrdtsz4seventwo
2lgsljspp1kpjpjh6six
hz8four5lkcxzr
hgcmhgftpspbhcj8four
three2bdstsvsskx6hjhmxlhnonefour7eight
3175cxbsg9eight
one89twoone7
cjjztqb7two
7fzkbxrvseven6fbvgmckvjrlklqhlnsevenone8
dfctz4
cpbfshrsixhjnfcbfmd7gdhhzx
seven1pbrzmtflvh
fdchrzgzdsix63three7
three4dckqnone2two1eightwoq
two9khrvjmvg47hsn
cdgpvclmngsixfshzlm15jsnrths
jqztnseven6
seven55seveneightwodc
sevenff9onernhzsix9eightjdcc
threeeightps9
six9threevmgplqhzrncgkmqjnine1one
three6six
419zzsjzqvkkzrpnszbvg
8fourthree7two
sixfivefmhrttsqfz2eight6two
286
xvxhrfiveftnlkmcv2
fourfour6eightninedkgxbkninexgncmkfqp
ninekqjc1dvxtxdvzfgcph3
8hnnqm
gkzzmhbdqfour849
95fjtrfourseven
seven5rh
five2bbqmnkkq7sixchcgslsevenvkmpfg
knlfive1fpsevenmbcnqb
qpjxzbninejrgmvxpslk5rlfmrdmfbh2
9sixgqxdlcx
19sqlbrngnvfqmzd
tjdg3
cmkpfivekzfhone1hxpbb
fiveseven3
dxthreethreeninetwoeight4three2
6j
nine59
7seven8one22knqdsixone
sixtzbkscdt5
nine4gfxtrlzcd4twoone
2seven7nine7
fourpksdzztmll5
2dgqoneoneone
khzx1seven1cpkzvjtmv
fiveseven8three6
rrxkljtthreefoureight8hpxmmnjctthree
2sixzcchvknspqdjthree1
nnl1rnrhxprnlctwoone
qsbgz28nfive
clqtchqnvrvv11eight
tvhrpxkbvpfiveonesix5
qhjqmqpm37
1748
23sevenhnrvlvjhbfrxvhfthree
1sixdnrnkb88fbrndqcphxrzlgjvf4
8qlhmjsqzms9two1ffourcdlpssq
5573
eight76
7qxcrrldb
5zseven35
nxkqrsmth1tmrvszjcceightlnzgfdnine
fourqrkrsrzltnqcgnmnpptwo2zmgnlthreeeightxnxgmgd
gnlqqtwo16xsxhrxthdltpxssnvfjqtrkfm
njlpbqsixfour51eightpnzzfmfksevenvpgnmkqd
two7xbhhbjrrp
41two6
sevenseven9xnlrnzlrnxfourjzsjfds
frfdzkxhckdxtp8twokfour
42ctfq5
gxjmvxdprr5
sixsixeightvvplxddrdnngdxj1
989ffgvq4vpv
ninecgtlfts9g5onebssmzsbnf
3sixfourxltwopmdsrjscrh7dggvqhfour
5jktwo98jksfqbdbbt
fivemrrctsj7csqspbbnk2vtvlmnbdksfour
832nine1sixzbtkxzqthreetwo
1jbrv1rzhgtwo4c
eight79
3meightseventwo8one8
qtkzxf9gmdqkgqcc
vllkztxsjqsg8fivetwo
5twohjzgcrhgpkfour7zkpngbbpj3
7nggrljjllnineeight
sixone17nine84
5fourbnrpsnk5
eightnghj7threethreeeight9
956
eight2grdnqrvhlt5ptlqjqzbsixseven
4bgzdpbnmcone7rxdqjbmbsix
9ninenine195
cflqvgs4six9kjhkmqhnn3rqmpc
25sbdjjnphsr1112
two7jxxzxronesix
gnzzkvjcxzonen7
ninextxskkggr5nine3ckkfd
pmkxbttdbllqqxfeightsix6fmmbltphngpmzbtsbbcq2
4eightvthfour5
eightksbjldxg7sixfour
sixghvhqmthree7nine7
zzjblxhvmltjqs1
tslmgqfdt5eight53hmhlfzsvszthqmhxkmfhbxlm
5sixzbczjtjg4nine811
fourtgpmfourthree8ninecfd
hqnpxjtpnsxqpfzvgmshfmntwothreetwovzgphgfsix5
qjbdronetwo7five1hnf3
3xmvlpkvqcctwo
cgkninefoursixtwosix8eight
csvnsvtshrpdpkxqeightcsl4cmpn
hzoneightthreefour8threekppfivezl61
327onenineseventwosix6
eightone66
71oneddkhbdfourrjmskvdslx
dbv12ctlrgxbbmsix
one5five3fourtwozgnhseven
sz4kljvrjf3sixxfivefivefive
tlvl6jttfznmthree9ljbqfdgfdhd
gbdeightsevenninenine84ltblttwo
fourjrbs5fiveonejhvzsl9nsxnmlnmjt
4three2spkj
fourbvmblbpkqjsfbssevensixsgrqnfpmj9vtx
xgtzdmdgflmtdjvmqkbsvdxvbrcpdlmbptmljl2
fourlcbxq95sevenr
2sixfcqfgbtz3nine763
one14
l4six
3tjxghncvg9qcrzsbzccvfhsvzcseven4
seven9spzeightsix
xzbeightwozvp7six3sqsxdhnm8
75stwofivefvnjtktztwo
1msqj8ninepnsjbjxmzpdgcd8ttcnlzk
fvmxntfmxxf8fivepcqn9
fkjkszt1seven
3xkjvbjz8htrzhzkzmr
2jktmfjbzdkpvzkpcqv9cpprlghqzdfive2five2
ltmhdxkscptwo87
hxhkjeight5seven6c67rj
sbzvthree891ztc5four8
one4ngsvv7nfblcrjzjsgkknrx
jrb8one4qjjbvvcxrhfsslvq1
6two5one5
threesonecheightnine61
fzppx9sixgonefour
6fvnrr4five1fivejxxcmc
sseven5threesevenfourr
fcbnms5vctwo
829three8gvqknllg
qcmf9
sixthreeeight4dxmsbb4
two5fouronetwo
33foureight
sevenxjmkfgtseventhreefdtvn9two1
18qseven
8141mfxlzkgvonebhddp
3fnmdmvrjktseven
hgcnjmxchfive9
sfvcmptk81
vsfrpfzvdgxfjzxmpsdeight36four
hjglvnvcmnine7fourtnxllcdksixnm
4four912ctx
8nineeightsqfhsevenninezfseven
threemjq79tgzsevenone
twofktsbghzzmbfzfd1
5rsdninetwoneqp
nrfztxghtl8qx8one8sixnine
2lmhlkdvjjv4bbgnckvxpdtwothreebzqqdgmtfvsvqjj
63fivemzqvkbftqxtg
214three5fivedmskgjtdbbv
jvxh8two
kmnflrsfngone5zs6l7
pmcqtzdvqkcnfbzgtqscfour5one
sfcdttxpblbsevenseven2
355
5ninetctrhrqteight6three
ninesevenls6nqqtfninehjdb
hpdxptb9seventhree12
85vqbhpqrzpcsnfive2oneseven
79twothree
8eight3vzxsixoneeightzzcdkhgtpz
fivenine3hm3
fourfthree7
qkqgptwotvjkctgsbmsxvmssdpteightlxlkfqv46
84kqtnsjplhp1
3qk51
two7gjdrxxjlg6
7qbrhzdljnvthreefour8dc8qctqhnlfzdshvz
pfcninefourjzqnmmmxhqsix49
gfbzhslvjrl1sixsevenvnpcrlhfdttmfourzr
3fourtwo636three
qnxrzp7gxcfoursixoneightqmn
fourhfstrgmmdvvlnq5rrb7
348tdcztqxksixfiveseven3
ninetnkhspprkmtljdfcbtwo2three7
qgpfzngtntdsdjvlvmxnmgtbthree5bnkthree
9vhthree
six1four57sxcdzk97seven
6mnhhjtfbcpeightwozj
nploneight9
6kpzgz5mtq7
csflt33ninekmgc
jcpntrdsjnkzpmgtdxk4
plbvmzc3sixfourfoureightkrxbzsdnbj
seven7ql74
bknbt7eightcbpxzkhtfrgcvhksrr2kxhvqthtsg
tcdcvqkknhxp9fivenlphrppfivenine
8tgvvvsjl2ql5vjbsbrzvtjpkb
51vtffpfzk1two
58threellgc74three2
zrrlzzpcq2c31four
xcpksgthreerfdjldvfteightnine2npztqh
dtonefourqpss7
rzmx8
2eight47
nine593hsvgtghjqc
five6gnkcxrvkvpone742mxsdpnxqkrcqzrmglxq
onevtfour8eightfive
vhnhqvsfm8qqgmsjkhsqeight
2foureightsix8lhzplrtnpttznkt2
cztjsixsix96xljqqfhtmd
6four6mtvvxdbvninepjkfqlhhrhcqrddmghrlvkkphzvvb
clshpcdb7bthreenine821
lcbbcnn74xcpdspkqdphdvdtrkfqfoursix3
2ssgn7mjtzrblgr229seven
qtjzd5poneztdhvtdzt8svdfpv
91fivetwo
two41qctlttbcsevenjxczz5
fourbsklkgltwolvdgvjxcxpvclxqbqxjhbz7
vncsclbf8cbkmzone
dfn349six34five
one65kzsspzjhcsln
bmnfzmhptzgmgjk1sevenfive824
3zthjdsix9geightsixeightfour
jvhhrkrnhfivenineonethree3sixninegplzthbxj
boneightthreeqdglvf74
13dmktbhp
8ninetwo
8eight87l
six5xhrtbhdmhpbpqqsfjjninesix8seven
lznlvseventd819qkq9
55
onevqgp3six
8gc8
seveneight8fivesixczbqpjdhxnschd1
9hvpqtcsevenfctzrxtgj6rjzgfpm8
ppcmhlccprnmpndzkkjvbrptfour5fivefivefcdqvf6
sevenhsqnkhhcfonethreezdrjvqsmlvjrdbppjcj8eightwovn
3mxqxlqsvfjpbclmqdrg1one
zmxnftxklqqd8one
2k2onesixthree
1twofivetwozxqhjqjbzgzsslgd
3mblcpmlmg8seven
twoeight626snine
p8onegjssix
ninelkjbgsqtrx9fiveeighthljnlrdb
x21six2cqfqbsmhxsbngstp
2gcmhhtxpzsfive4sixmvrqzkfnv
8ninethree7bbjmcnm8
sixzqpl6three
b7zfivebmlfvcdg1
2fivetwo8
zdkznnkonetsstchvtxsvpfone1sjmqndvbhfg
ggrvbl2one
1m
7eightggfvfrsrfive77sxxrshdrfive
12lkgxnfqd
9znqtwo2three5three75
seven8six
four138six7six1four
8vmpqprxdgj
8zckvmtmbjtdqprvfxtkmgmmtgck
8vlzthree49
onesddbmbeightfive523sixtwo
9jcfjq3
5qlhxfour
3five4
2kvfourseven7vdh
seven1one7
7v
fourdnh568oneninehqftnfninetwonejjn
dpvcxz21seven
4threeslnfhfskntz8kqmh
58eight3
fivetwo16sixfour
fnxmrmcjsixninethreekbf5one
1seven6fourfournjsdvhlkhp1
five8339
1fgmrleighteightdzxh
eight5nine
eight4fdnx
sqfklfbkjvbghbgmszzzpeightfive2fiveonefive
xcveight6zlfkpxrzsnq3gzjseven
fkeightniner4fourfour2eight
nine87lphjt
3twombcfour
dpn7688eighteightdjl8
5tvplhtfrmlv3zjcgvfivenl
2fiveztwo4
fjbbtgone5
bjrgnzzpsixnine4three
kkqpcmvjnine18
zhzkslnd1twonpqxtwoninefiveone
fiveckknnzhdtm793
seven2cbtkqzs861cbfgssfqtd
sixvdtzsixthree4lchxtdkv
1vvssfvlfbg2eightmxbqbvgsixnine
nineeightjlngjz94t7
lpncsfkn7fsgvkl
583sevenhjxlqzjgbzxhkcl5
81s
2four3threesxxvlfqfive4
nine6eightsevenzx9twoxc
hmbfjdfnp989mfivefiverpzrjs
"""
solution01_1 = fn input ->
input
|> String.split()
|> Enum.map(fn line ->
matches = Regex.scan(~r/\d/, line)
[x, y] =
[matches |> List.first(), matches |> List.last()]
|> Enum.map(fn [s] -> s |> String.to_integer() end)
x * 10 + y
end)
|> Enum.sum()
end
solution01_1.(sample01_1)
solution01_1.(input01_1)
Day 1 - Part 2
sample01_2 = """
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
"""
input01_2 = input01_1
solution01_2 = fn input ->
digits =
~w(zero one two three four five six seven eight nine 0 1 2 3 4 5 6 7 8 9)
|> Enum.with_index()
|> Enum.map(fn {k, v} -> {k, rem(v, 10)} end)
input
|> String.split()
|> Enum.map(fn line ->
finder = fn
"", acc, _finder ->
acc
<<_, rest::binary>> = str, acc, finder ->
acc =
digits
|> Enum.find(fn {d, _v} -> str |> String.starts_with?(d) end)
|> case do
{_d, v} -> [v | acc]
nil -> acc
end
finder.(rest, acc, finder)
end
matches = finder.(line, [], finder) |> Enum.reverse()
[x, y] = [matches |> List.first(), matches |> List.last()]
x * 10 + y
end)
|> Enum.sum()
end
solution01_2.(sample01_2)
solution01_2.(input01_2)
Day 2 - Part 1
sample02_1 = """
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
"""
input02_1 = """
Game 1: 2 green, 6 blue, 7 red; 12 green, 6 blue, 3 red; 5 red, 18 green, 4 blue
Game 2: 10 green, 4 red; 2 red; 12 green, 11 red, 1 blue; 1 blue, 11 red, 5 green; 10 red, 9 green, 1 blue
Game 3: 3 green; 15 red, 7 blue, 1 green; 3 red, 6 blue, 1 green; 14 blue, 13 red, 2 green; 1 green, 6 blue, 6 red; 16 red, 13 blue, 2 green
Game 4: 5 blue; 8 blue, 7 red; 9 blue, 5 red, 4 green; 4 red, 1 green; 8 red, 6 blue; 2 blue, 4 red, 3 green
Game 5: 3 blue, 4 red, 10 green; 13 green, 8 blue, 2 red; 2 red, 4 green, 6 blue; 3 blue, 5 green, 2 red; 4 red, 13 blue, 8 green; 9 green, 2 red
Game 6: 3 red, 2 blue; 6 green, 13 blue; 11 blue, 1 red; 4 green, 3 red, 5 blue
Game 7: 14 green, 2 red, 5 blue; 4 blue, 8 green; 2 red, 2 green, 9 blue
Game 8: 10 green, 6 blue; 3 green, 4 red; 7 blue, 7 red, 5 green; 1 red, 11 green; 3 blue, 2 red, 11 green
Game 9: 4 blue, 1 green, 6 red; 5 red, 5 blue; 1 blue, 7 red; 4 red, 8 blue; 6 red
Game 10: 3 green, 7 blue, 6 red; 1 red, 5 blue; 6 red; 1 red, 5 green, 6 blue; 5 red, 2 blue; 6 red, 4 blue, 6 green
Game 11: 8 red, 6 blue, 6 green; 5 blue, 2 red, 5 green; 4 blue, 5 green; 4 blue, 3 red, 8 green
Game 12: 5 green, 1 red, 7 blue; 1 red, 10 green; 6 red, 3 green, 7 blue; 5 red, 6 blue, 7 green; 3 blue, 4 green; 1 red, 3 blue, 3 green
Game 13: 11 red, 9 blue, 16 green; 1 red, 3 green, 3 blue; 14 green, 2 red, 7 blue
Game 14: 4 red, 8 blue, 12 green; 7 blue, 4 red, 2 green; 4 blue, 7 green, 6 red; 3 red, 11 blue, 12 green
Game 15: 6 red; 3 red, 5 blue; 3 red, 10 blue, 1 green; 2 green, 8 red, 2 blue
Game 16: 2 green, 4 red, 6 blue; 2 green, 16 blue, 2 red; 13 blue, 7 green, 3 red
Game 17: 5 blue; 1 blue; 2 red, 2 green, 4 blue; 6 blue, 4 green, 2 red
Game 18: 3 red; 7 green, 11 red, 6 blue; 6 red, 3 blue, 12 green; 5 red, 3 blue; 7 green, 8 red, 9 blue
Game 19: 2 green, 13 blue; 11 blue, 16 red, 7 green; 13 blue, 10 green, 8 red; 18 red, 1 green, 14 blue
Game 20: 10 red, 6 green; 1 blue, 6 red, 15 green; 15 green, 9 red, 3 blue; 3 blue, 11 red, 9 green; 2 blue, 5 red, 10 green
Game 21: 1 green, 5 red, 8 blue; 4 red, 6 green, 7 blue; 13 blue, 10 green, 6 red; 9 blue, 2 red, 14 green; 16 green, 10 blue, 1 red; 9 blue, 3 red, 11 green
Game 22: 4 blue; 1 green, 1 red, 16 blue; 15 blue, 1 red
Game 23: 2 blue, 6 green; 15 green, 2 blue, 10 red; 1 green, 6 blue, 6 red; 8 red, 1 green; 4 green, 3 blue, 10 red; 7 red, 3 blue, 20 green
Game 24: 1 red, 13 blue, 8 green; 3 blue, 7 red, 8 green; 3 red, 11 green, 12 blue; 7 green, 6 blue, 2 red; 11 blue, 5 red, 10 green; 13 blue, 3 green, 8 red
Game 25: 4 red, 6 green, 8 blue; 4 red, 10 blue, 9 green; 5 red, 2 blue, 3 green; 2 green, 9 red, 4 blue
Game 26: 14 red, 4 green, 5 blue; 3 blue, 2 red, 3 green; 1 red, 9 blue, 1 green; 5 green, 15 red, 8 blue; 5 green, 6 red, 6 blue
Game 27: 1 blue, 1 green, 9 red; 4 green, 1 blue, 1 red; 4 green, 4 red; 5 green, 4 red; 1 green, 1 blue, 8 red; 9 red
Game 28: 11 red, 3 blue, 19 green; 3 green, 13 red, 5 blue; 8 blue, 16 red, 18 green; 13 red, 5 blue, 7 green; 8 red, 5 green, 4 blue; 16 green, 1 blue, 15 red
Game 29: 12 red, 15 blue, 1 green; 3 green, 10 red, 5 blue; 4 green, 5 blue, 17 red; 11 red, 2 blue; 6 blue, 3 green, 4 red; 1 blue, 13 red
Game 30: 2 blue, 2 green, 3 red; 1 green, 4 red; 1 red, 2 blue; 1 green, 1 blue, 2 red
Game 31: 3 green, 5 blue, 4 red; 3 red, 1 green; 3 blue, 4 red, 3 green; 8 blue, 8 red; 6 blue; 1 green, 6 blue, 1 red
Game 32: 3 blue, 12 green, 2 red; 13 red, 12 green, 4 blue; 9 green, 1 red; 10 red; 12 green, 9 red; 15 red, 3 blue, 10 green
Game 33: 1 green, 8 blue; 3 red, 7 green; 4 red, 3 green; 5 red, 9 green
Game 34: 12 blue, 3 red, 2 green; 12 blue, 12 green, 2 red; 10 blue, 8 green; 3 red, 3 green, 9 blue
Game 35: 4 red, 4 blue, 6 green; 3 blue, 8 green, 2 red; 5 green, 2 red, 2 blue
Game 36: 12 blue, 4 red, 5 green; 18 blue, 2 red, 5 green; 2 green, 2 red; 3 red, 9 green, 13 blue; 2 green, 12 blue, 1 red
Game 37: 8 red, 3 blue; 6 blue, 5 red; 9 red, 10 blue, 3 green; 4 green, 10 red
Game 38: 1 green, 3 blue, 7 red; 6 blue, 6 green, 9 red; 5 green
Game 39: 7 red, 1 blue, 1 green; 5 red, 2 blue, 3 green; 9 red, 9 blue; 5 red, 3 green, 1 blue; 1 green, 9 red, 1 blue
Game 40: 1 blue, 1 green, 3 red; 3 red, 2 green, 2 blue; 5 red, 1 blue, 8 green; 2 green, 4 red, 2 blue; 13 red, 2 green
Game 41: 17 blue, 5 red, 3 green; 10 green, 4 red, 5 blue; 3 red, 17 blue, 1 green; 11 blue, 10 red, 3 green
Game 42: 8 blue, 2 green, 7 red; 4 blue, 1 red; 9 red, 2 green, 6 blue; 4 blue, 9 red; 1 green, 9 blue, 8 red; 6 red, 1 green
Game 43: 1 green, 6 blue, 14 red; 7 green, 1 blue, 8 red; 3 green, 16 red, 7 blue
Game 44: 5 red, 5 blue; 1 green, 8 red, 9 blue; 6 red, 3 blue
Game 45: 4 green, 17 red, 14 blue; 14 red, 2 green, 2 blue; 9 blue, 1 green, 8 red
Game 46: 1 blue, 10 red, 7 green; 3 red, 4 blue; 2 blue, 1 green, 1 red
Game 47: 8 red, 2 green, 13 blue; 10 red, 9 blue; 4 green, 15 blue, 2 red; 1 blue, 1 green, 16 red
Game 48: 9 red, 8 green, 1 blue; 10 green, 5 red; 9 red, 3 green, 1 blue; 8 red, 1 green
Game 49: 11 blue, 18 green, 1 red; 13 red, 9 blue; 17 green, 18 red, 6 blue
Game 50: 2 green, 10 red, 6 blue; 6 red, 6 blue, 7 green; 7 red, 5 green, 3 blue; 5 green, 2 red, 1 blue
Game 51: 1 blue, 9 green, 7 red; 2 blue, 11 red, 10 green; 1 blue, 9 green, 12 red; 10 red, 5 green, 3 blue; 9 green, 3 blue, 14 red
Game 52: 4 green; 6 blue; 4 green, 7 blue; 1 blue; 1 red, 8 green, 1 blue
Game 53: 6 green, 3 blue, 13 red; 3 blue, 2 green, 16 red; 13 red, 9 green, 2 blue; 1 red, 1 blue, 7 green
Game 54: 1 green, 4 blue, 10 red; 2 red, 6 blue; 2 blue, 5 red; 3 blue, 7 red, 1 green
Game 55: 17 red; 18 red, 3 blue, 4 green; 5 blue, 14 red, 1 green; 4 green, 5 blue, 4 red; 2 green, 18 red
Game 56: 14 green, 2 red, 18 blue; 8 green, 12 blue, 2 red; 1 red, 13 blue, 12 green
Game 57: 2 green, 4 blue, 12 red; 1 green, 3 red, 4 blue; 4 green, 2 red, 3 blue; 3 green, 6 red; 3 red, 3 blue, 3 green
Game 58: 2 blue, 5 red, 2 green; 6 red, 6 green; 8 red, 11 green, 2 blue; 9 green, 1 blue, 11 red; 2 blue, 17 green, 11 red; 7 red, 8 green, 2 blue
Game 59: 4 blue, 1 red, 16 green; 2 blue, 5 green, 1 red; 2 green, 6 blue; 3 blue, 10 green; 14 green, 6 blue; 1 red, 11 green
Game 60: 4 red, 1 blue, 5 green; 2 green, 6 blue; 1 red, 17 green; 2 red, 11 blue, 14 green; 2 red, 8 blue, 14 green
Game 61: 6 red, 7 blue, 1 green; 2 red, 10 green, 16 blue; 14 blue, 10 green, 7 red; 12 red, 15 blue, 3 green; 5 blue, 1 red
Game 62: 9 blue, 4 red; 1 green, 2 blue, 4 red; 8 red, 9 blue; 6 red, 15 blue; 7 blue, 10 red
Game 63: 8 green, 2 red, 4 blue; 2 red, 1 green, 3 blue; 1 red, 3 green; 2 blue, 9 green
Game 64: 4 green, 13 red; 2 red, 6 green, 2 blue; 4 red, 6 green, 2 blue; 6 red, 2 blue; 5 red, 9 green; 3 red, 1 blue, 10 green
Game 65: 8 blue, 3 red, 3 green; 6 red, 8 green; 6 blue, 7 green, 7 red
Game 66: 6 red, 2 blue, 2 green; 15 green, 11 red, 1 blue; 1 red, 2 blue, 10 green; 2 blue, 17 green; 12 green, 2 blue, 4 red; 16 green, 10 red, 3 blue
Game 67: 1 green, 2 red, 12 blue; 2 red, 3 blue, 3 green; 8 blue, 4 green, 1 red; 12 blue, 2 red, 4 green; 2 red, 10 blue
Game 68: 6 red, 4 green, 16 blue; 9 red, 7 green, 11 blue; 7 blue, 16 green, 15 red; 2 red, 2 green; 16 red; 13 red, 15 green, 2 blue
Game 69: 14 red, 3 blue, 14 green; 4 blue, 18 green, 2 red; 4 green, 9 blue, 7 red; 15 green, 9 blue, 10 red
Game 70: 2 green, 5 red, 12 blue; 3 green, 5 red, 4 blue; 5 blue, 4 red; 6 red, 11 blue; 5 red, 2 blue; 5 blue, 1 green, 4 red
Game 71: 3 green, 3 red; 6 green, 11 blue, 2 red; 6 red, 4 blue
Game 72: 9 blue, 4 green, 4 red; 5 blue, 5 red, 3 green; 9 blue, 11 green, 3 red
Game 73: 1 blue, 13 red; 12 red; 5 red, 1 green, 6 blue; 5 blue, 7 red; 8 red, 9 blue
Game 74: 7 green, 17 red, 3 blue; 15 red, 2 green; 5 red, 3 blue, 1 green; 19 red, 1 blue; 3 red, 1 blue, 6 green; 7 red, 3 blue, 1 green
Game 75: 11 blue, 9 green, 4 red; 5 green, 2 red, 16 blue; 13 blue, 2 red; 3 red, 18 blue, 1 green
Game 76: 5 green, 13 red, 10 blue; 5 red, 11 green; 1 red, 5 green, 8 blue; 4 red, 14 green; 7 blue, 12 green, 2 red
Game 77: 5 blue, 2 green, 3 red; 2 red; 1 green, 6 blue; 5 blue, 1 red
Game 78: 9 red, 7 green; 10 red, 2 blue, 6 green; 13 red, 3 blue, 15 green; 9 blue, 10 green, 2 red; 1 blue, 4 red, 12 green
Game 79: 4 red, 3 green; 3 blue, 10 green, 4 red; 1 red, 12 green, 7 blue; 5 blue, 3 green, 6 red; 10 green, 1 blue, 5 red; 5 green, 5 red
Game 80: 3 blue, 18 green; 5 blue, 11 green, 3 red; 2 blue, 13 green, 7 red; 4 red, 1 blue, 8 green
Game 81: 9 green, 18 blue, 10 red; 6 red, 5 green, 13 blue; 8 red, 4 blue, 7 green
Game 82: 9 green, 2 red, 2 blue; 7 green, 2 red, 1 blue; 2 green, 2 red, 2 blue; 2 red, 14 green, 1 blue
Game 83: 10 red, 7 green, 3 blue; 4 green, 12 red, 12 blue; 13 blue, 1 green, 8 red
Game 84: 10 green, 3 blue; 8 green, 2 red; 3 blue, 5 green; 3 blue, 1 green; 5 blue, 7 green, 1 red; 8 green, 5 blue, 2 red
Game 85: 6 blue, 4 green, 5 red; 11 green, 1 blue, 13 red; 11 green, 1 red; 6 green, 2 red; 1 blue, 5 green, 4 red
Game 86: 1 blue, 10 red; 2 blue, 5 red; 1 red, 2 blue, 2 green
Game 87: 11 green, 13 red, 6 blue; 8 blue, 2 red, 6 green; 10 blue, 11 red, 1 green; 16 green, 16 blue, 6 red; 6 green, 12 red, 3 blue
Game 88: 15 green, 4 red, 2 blue; 6 red, 13 green, 4 blue; 3 green, 17 red, 4 blue; 4 blue, 14 green
Game 89: 6 green, 12 red, 7 blue; 3 blue, 6 green, 7 red; 6 green, 13 red, 5 blue; 6 red, 7 green
Game 90: 19 blue, 19 red; 6 blue, 12 red, 6 green; 2 green, 7 blue, 17 red; 3 green, 9 blue, 7 red; 8 red, 7 green, 18 blue
Game 91: 3 red, 1 green; 14 red, 2 blue, 2 green; 7 red, 3 blue; 1 blue, 6 red
Game 92: 2 green, 16 red, 15 blue; 3 green, 3 blue, 11 red; 7 blue, 6 red; 7 blue, 13 red
Game 93: 1 red, 1 blue, 9 green; 12 green, 3 red, 4 blue; 3 green, 3 red, 7 blue
Game 94: 12 green, 5 red, 9 blue; 3 blue, 3 green, 2 red; 5 green, 2 blue; 5 green, 7 red, 10 blue; 7 red, 10 blue, 10 green
Game 95: 3 blue, 15 red, 10 green; 3 blue, 16 red; 1 blue, 13 green, 6 red
Game 96: 11 blue, 2 green, 5 red; 2 green, 10 red, 15 blue; 11 blue, 19 red, 8 green
Game 97: 7 green, 2 red, 1 blue; 5 red, 3 blue, 12 green; 4 blue, 2 green, 3 red
Game 98: 2 green, 5 blue, 9 red; 4 green, 9 blue, 8 red; 7 green, 11 blue, 7 red
Game 99: 2 green, 15 blue, 2 red; 2 red, 6 green, 12 blue; 11 green, 18 blue, 2 red; 3 red, 9 blue, 3 green; 18 blue
Game 100: 13 red, 2 green; 15 red, 1 green; 4 green, 1 blue; 11 red, 5 green; 3 green, 8 red
"""
solution02_1 = fn input ->
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
["Game " <> id, reveals] = line |> String.split(":")
id = id |> String.to_integer()
possible =
reveals
|> String.split(";")
|> Enum.map(fn reveal ->
~w(red green blue)
|> Enum.map(fn color ->
Regex.run(~r/(\d+) #{color}/, reveal)
|> case do
nil -> 0
[_, n] -> n |> String.to_integer()
end
end)
end)
|> Enum.all?(fn [r, g, b] ->
r <= 12 and g <= 13 and b <= 14
end)
{id, possible}
end)
|> Enum.filter(fn {_, possible} -> possible end)
|> Enum.map(fn {id, true} -> id end)
|> Enum.sum()
end
solution02_1.(sample02_1)
solution02_1.(input02_1)
Day 2 - Part 2
sample02_2 = """
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
"""
input02_2 = input02_1
solution02_2 = fn input ->
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
["Game " <> _id, reveals] = line |> String.split(":")
reveals
|> String.split(";")
|> Enum.map(fn reveal ->
~w(red green blue)
|> Enum.map(fn color ->
Regex.run(~r/(\d+) #{color}/, reveal)
|> case do
nil -> 0
[_, n] -> n |> String.to_integer()
end
end)
end)
|> Enum.zip_with(fn counts ->
counts |> Enum.max()
end)
|> Enum.reduce(1, &Kernel.*/2)
end)
|> Enum.sum()
end
solution02_2.(sample02_2)
solution02_2.(input02_2)
Day 3 - Part 1
sample03_1 = """
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..
"""
input03_1 = """
.........................3.......................................94...............806....................596.........793...........186......
.../..........*574.587..*........161......904.......412.........*.................*.................................=.....637.%......*......
..614..831..33.....*...........@....*398..&.....690*............183.........503..916..790................................*.....256....632...
.........*.................332..374......................%184...........467..........*....969.632.......26....457......440.........@........
..........535...541=........*.......696..@..323..................93=.......*.......30......*....*......-........+.222$.......458.817....66..
....*.......................885.....*...123.=...641...&188..577.......339..688.........287.684..219.........................+...........*...
...61........397...#386...=........313........-...&............*......*................@.............../.........621+....................169
..............*.........34..................934..........17..168..320..263.........412.......$......966.....................303.....554.....
...............353.447.......@.....251............54....*........#.............149....*...871..964.................714.....*....403...*.....
...805......$......*.......632.....#...+514.944.....*....48..........*133.959.*....814...........-.521...........................*.....398..
..../.......906.289...238.....................*................772........*...591......260.122......*........309...677...357.....790........
........#................/.........450.....594.................*.......705............*....&.....676...@954.%....@....&.*...................
.....310..928...+.............488.*.............790.........286..982.........416*944..103.........................351...519...705...........
..............872.....+........*..820.....5....*.....529.........*...........................@..884......356*449................*..596......
...................780......507.........$..*...936.............406...........*560..704....931...+....618..................%243.817...*......
.386.....937.+904......*.............540...320............702.............118.........*............../.....445.....291.............899......
........*...........930............*......................&......204...............243....*948.....*..........*...*.......512$..............
......956....................$..788.487...........894.955..............................479.......709.........57....374................930...
............/534..260*33..680...............324...*....*......574......219................................................../934.......-....
..261...........................*813....=...*..........378......&....-..%...198............................885.........666..................
...*....../........905$......706......281...314...642......701....736.......*.................................*..........*...532............
..235..400....670.........-........................../......................849...204...197..646...............548.......61.*.........538...
.............*.............927....340...........641..............................&......*...*.........137..144...............513............
..400./285...16.......704............*896..836.....*..........738......102.&190..........89.137............*...$582....................&....
...*.............763...#....541....................629...........*646.............295............368@....&..62........990...@428........955.
....218...650.....*.........%................269............669...........709.......+..810.............52........447...@.........784........
.............=.....313.............*........+..........444....*.%.........................-.....225.......684...*.........../107...*........
..66...643.......................87...770.........=.......@.122.495.......177.....226.974.........*.580..*......921....216*.........724.....
...*..*....................328.........../...460.325.....................+...........*.........198.....-.316...............912..............
..882..421.......%766.........*..............................978*..........124.110.......$.....................467..............780.........
...........732.........531.....439...%...........................230..........*....396..126........................508...........*..........
............/..........*.............401..69.........$.................630............*.....114.......959...81.............515..664......43.
......-............491..929.363*.............178..686.....546...................628...4.......%......+..............106...*.........*.......
...456....154..659...+..........111.*...........-.........*...............66.%...*......%...................583../1.*.....206.......439.....
...........&...$..........548.......560................431......752......@...574.534....303...843../.................844....................
.........%.....................320%.......871*.....647..........*....................89.............981.....................................
.92....832.....194.804.270.992................388..................%..583*..........*......255..730.............................138..121....
.../................%..../..*.........58.106......*..373.........107......964...52.910.465..*..*........15...@.....*14.=847...........#.....
......850...503......................*......*....411....*....674...............*...........532.124.......*.471..380.........................
......*........*...390..641......99...997..688..............-......403...6.....156.....................320................*721..............
.......471....555..*.....*......*.../................749...........*......*..........92*756................336.....241.581..................
...................904..762..681..695.&639..903&......*.........753........936...................683-..........921..*......654....7.470.....
.........16*494.....................................395..112...........=..................601..........+..........*.901.......*....*........
................45...........77............$..636.........*...@593...670.........*796.270..*.......%..835.501...190......369.618.%..........
......918..@....*....597...........758..550...$...895...688...................952.....*...761...176........%..............*......261........
.....*......957.108.....+.....788................&..........221..........-308.....$..567..............562-.............963...833............
....431.484...............35.+.....476.902.....................$.....495.......137...........880.199.......306+................*..725.......
..........*..............*.....312...=.....50-...687...274..........................-........%.....*.................*......930...*....349..
.....197...748.........639........=................*..*.........601*.......19....995..............470.....81.954..684....82......872...*....
....=................................996........457..208.403........379...=...............193..........61...*...........*....37.........248.
........155...................%........*.......................................689.211...+..........52*..................969..*....922......
......*.........151......698.723.....175..10...........&............................*......852.486......442...900....934......60.....+......
...103.896..142*.................430.....*..........-...743.........346&.................#..*...&........*.............*.........197........
......................811........*..................813........802.............#333...167...916...856.....590..........658....-....-...563..
..............838.275...-......529.............718.......502....*.................................*................284.....967..............
...8....64.......*............................*....870......*.901......606.226...................534........773....*...............*43......
....*.........57............338*142.......589.525....*...563...................745#......152..............%..*..298..206....................
.....311.....=............................&.........309........630.....238................*.....345......701............*.....235....541....
..................288...596...45...............953.............%.................@....379.746......-..%.........937....571...........=......
161@................&......*.....47.=.........#......586.....&...281............764....*...............903.=810..-............837...........
............................944..&...650.............&....918.......*..74...............369....437&............................*........777.
......146...*..................................772*.................52...@......*895.@.......................371.......*76.....282..........
......*.....278...696...........365....=334........786........879.=..........983.....877......@38........784..*.....255....&................
.....132.............*.849........*........................%......783...553.................................&..663......297........419.440..
.977...........839&.......=.393&.77....895*770............636..........................-803..353+......-.......................406*.....*...
...*.=....376......................................69..........&.....116*949.......................186..295............%.................833
261...853...*...81........993.191.810...731..........*575......636..................306...........*............129....691....999*.+712......
...........319...&..........*..*....*....-..903*187....................890....875......@........557............&............................
...........................840..403.255.............*.......138.........*......../.841..................257........499.........*........%...
....430.....283.........................897......566.74..11...........705.641...................71*104.*...........*........197.782......290
.....................605..........401..../....................690....................633...............957........739.......................
.280*135...706...........709.........*................388..............813............*.....906....%..................606...................
..............*.=965...............669.......944$..............................288.131.........-.183..594...............*..852..819.........
.......#513.676......667...............93..........#.....$.......984.............#.....511.....................172.283.323............+426..
......................%....826........$...........709..91...........*....919..........*......................./....*..........%.............
....................$.......*....829........656......................400.*....................995.798.203..........107.994.....598.543......
.........88.../..568.......194......*931.......*654..............*........533....................*.....*................+...................
............844................491.......642..................839.603.125.....777...96..24.312.........272................671.394.....532...
........85............/...@........*339..%......914...601.............+........*.....-....*......251.......29.....962.......+........@......
...969...............916.265....630........791&....*.*..........$.........-166..307.................*........*543.&.............445.........
..........811.457...................942.........755..944.......108..254...................322.....695....250................86..*........290
..........+....@............-871.......*....602......................*.......................*........15.=...........274.......637..........
.....................&810........894-..130...*..........................................315...76.....+...............*.....55...............
..........................261.................894..582.....................................*............14....%...737.....*.........+.......
..375.987........803..69.*........&....80#................685.....386.....................602....10.....%......65........932./..742.24......
.........@.608..*......*........563........630..947.................*..........234...728..........*..........................92..*..........
.....89.......+.550....43........................*....471......286..517.510....../......*..........966...795............$.........813.......
.....*...651...............#.../573..569..........239.*..................*...........591.....935..........*...........536...536.............
.....344.*.............681..90........*........./......43.........../...473.....................=.....679..545.................*843.........
..........610.72.952..................850.......81.........733......895.....975..........132..........*........+898.......583.........656...
790=.@179...........*........$...............................&..............@....935.......#...270..621...................#.............*...
...................618....366...776..................143.......115.../..............*....*.......=...........306.........................369
..............258................*...97........./967.-........*.....281...%............32.65........43.721.....*...........738...462*.......
..606........*................713.....*..................513............114..746...............................86.............*......507....
......402.....200...983...............746...335......938........488.........*......$.649.............................214.......493..........
........*..............*32.....................*381..*....46.......*..205..16...100....*.444#....&..522........896..*...............411.....
.......583........./................734..19..........795..*.....219...*.............804.......391......*............881................&....
..............93....228............%.......*...985........936.......%..........=..+........................361.692................784.......
.....219.................808..........755..........233............348.......463....147..............162.....*.......464$....................
.......+....&...876...+....*..461$...$.............*.....550...........456.............826.330.........*997..657.................763........
..../......143....%...87...............225..160*8.66.......+.....#623..*..................*.......612............709...679*........$........
.....271..................#.....610.....................................799......*....866.....965...=.456........*.........530......./......
.........10...#495..508.521.......+......746.........165.........-978.........638.145...*.576*...........*......926.............468...267...
...........*........*.................&....$...........*...294..............$.........822.................535.........727.351...............
...671..233.......903....541.....421..760..............299.*..............570..............540.......947.............*....*...802...........
.....#........920.........*..455*...............942.........953..390..................365.....+.........*..........779...55.......293*......
.................*........40......50..827........*..............*......................*..&.....-....374..............................80....
......#...........636.274...............=.......72.............785...+596.............36..59...843............206..+625....%................
......767.......*......*..........948..............*.345..................#..........................927..861....%........701...........64..
.242.........476.363...936....347.*.........@.....41...............31...362.447...+902.....538........*.....*......+...........262&.........
......#.........................&.517..*911..791...................*......................=....187.....926.800...54......108................
.593..829..............................................166.524=.....................+381........+..*.................468*.............&.....
..........766*......273...347.........347..........$...............836......436............843=....473..@.....=344...............573.675....
..............279...%........*...786..........-..100.860..........*........*....421.....................414.................616...#.........
...322....496............334.648..*....75...520......*......881....87....120....$..............*.............79.............*..........*....
.....*......*.....................367.............704.............................&..........59.542.........*.......-992..53...811..192.556.
...308....485...948.......................383*559........282.......15.........298.774.......................377...................*.........
...............+.......348........................&.809.-.....249.......699../............740..650...584...............801*563..721..470....
.........343..........................970...324.782................324..*...........380...*...*......*....-.........................*.......
...627$....*...713#.....799...420........*....*......................*...24..........$..131.......148......245....94*781...%.......302......
........698.........635.+...............644..593.%......784.....-....644......................409........&.....*...........952..............
.999.................*............................627.........866..........418..........483*.....$....227...248.665...265.......222...&.....
...*...............320...396......%......................77........186........*991..................*.................*...232....*....255...
..363..35...=39............*.......831.......892.........@...=..+........268..................513..373.....875.......48....../....680.......
.........................259.............374*...............137..482.432...&...276....132........*.....798...&.................16...........
..669*246.......................491.............+...+..492...........................*.........=..603.@..........849........................
...............429.220......-......*..........928..304...*......177................741...482.204.........*.........+....=........36.........
...218..449.......*..........214...620.................827.252..@...689...................*......598..460.473...........341.704../...434....
......*....*548.....-679.149.................................%......*...371..........998..815...*...................................&.......
.......403................=.........166............................741.....&........%...........329.............62..............*...........
..706*......991*738..347.....571...*....983..........+..208...319...............406..................175#......*.................891........
......392...........*...........*.409.....*........72......*.-.........233.......*...........................478.............256............
...................559..................-.540..734........6....*.......-......771............398.729.............928#..+....................
.....603.......472................%...892..............=....314.684.......712............206......+.....657.%..........844.584.456...=......
......*..........*..#..........801...............738...524.................*........817.......+........*....57.............*..........749...
648..799........517.999...............#...........$..+.....................742..516*....939=..694...945..................863...480..........
..........700........................994....314......214....105.............................................#....137............*...522.....
...153.....*.........685..283................*...151........*....#....232......$.......99.92...863....*.....567.....*.285.....69.....*......
............205.........*..*..............275....*.........220...644...*....293.........$..%..*....337.91...............*.............963...
.......................844.32......449..........932....................869....................77......................288...................
"""
solution03_1 = fn input ->
lines = input |> String.split("\n", trim: true)
w = lines |> Enum.at(0) |> String.length()
h = lines |> Enum.count()
lines
|> Enum.with_index()
|> Enum.map(fn {line, y} ->
Regex.scan(~r/\d+/, line, return: :index)
|> Enum.map(fn [{x, len}] -> {x, y, len} end)
end)
|> List.flatten()
|> Enum.filter(fn {x, y, len} ->
top = x..(x + len) |> Enum.map(fn x -> {x, y - 1} end)
right = y..(y + 1) |> Enum.map(fn y -> {x + len, y} end)
bottom = (x + len - 1)..(x - 1)//-1 |> Enum.map(fn x -> {x, y + 1} end)
left = y..(y - 1)//-1 |> Enum.map(fn y -> {x - 1, y} end)
[top, right, bottom, left]
|> List.flatten()
|> Enum.any?(fn {x, y} ->
cond do
x < 0 or x >= w -> false
y < 0 or y >= h -> false
true -> lines |> Enum.at(y) |> String.at(x) != "."
end
end)
end)
|> Enum.map(fn {x, y, len} ->
lines |> Enum.at(y) |> String.slice(x, len) |> String.to_integer()
end)
|> Enum.sum()
end
solution03_1.(sample03_1)
solution03_1.(input03_1)
Day 3 - Part 2
sample03_2 = """
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..
"""
input03_2 = input03_1
solution03_2 = fn input ->
lines = input |> String.split("\n", trim: true)
w = lines |> Enum.at(0) |> String.length()
h = lines |> Enum.count()
lines
|> Enum.with_index()
|> Enum.map(fn {line, y} ->
Regex.scan(~r/\d+/, line, return: :index)
|> Enum.map(fn [{x, len}] -> {x, y, len} end)
end)
|> List.flatten()
|> Enum.flat_map(fn {x, y, len} = number ->
top = x..(x + len) |> Enum.map(fn x -> {x, y - 1} end)
right = y..(y + 1) |> Enum.map(fn y -> {x + len, y} end)
bottom = (x + len - 1)..(x - 1)//-1 |> Enum.map(fn x -> {x, y + 1} end)
left = y..(y - 1)//-1 |> Enum.map(fn y -> {x - 1, y} end)
[top, right, bottom, left]
|> List.flatten()
|> Enum.flat_map(fn {x, y} ->
cond do
x < 0 or x >= w -> []
y < 0 or y >= h -> []
lines |> Enum.at(y) |> String.at(x) == "*" -> [{number, {x, y}}]
true -> []
end
end)
end)
|> Enum.group_by(fn {_, star} -> star end, fn {number, _} -> number end)
|> Enum.filter(fn {_, numbers} -> numbers |> Enum.count() == 2 end)
|> Enum.map(fn {_, numbers} ->
numbers
|> Enum.reduce(1, fn {x, y, len}, acc ->
acc * (lines |> Enum.at(y) |> String.slice(x, len) |> String.to_integer())
end)
end)
|> Enum.sum()
end
solution03_2.(sample03_2)
solution03_2.(input03_2)
Day 4 - Part 1
sample04_1 = """
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
"""
input04_1 = """
Card 1: 24 76 32 40 51 61 89 6 30 60 | 30 69 24 86 6 8 92 61 51 88 63 67 32 62 15 49 22 77 40 27 89 60 76 58 79
Card 2: 97 3 51 52 79 8 89 76 10 59 | 59 48 52 76 97 16 92 81 62 25 89 51 54 3 79 18 94 78 8 32 99 66 10 70 38
Card 3: 8 67 56 82 96 2 21 47 41 38 | 6 83 17 36 8 21 82 27 68 67 7 38 56 42 66 3 47 87 41 71 88 96 2 98 72
Card 4: 41 83 77 61 91 13 84 63 81 79 | 29 28 85 84 19 83 37 55 7 97 8 11 12 50 72 42 48 92 30 2 27 18 38 89 59
Card 5: 31 96 75 87 56 8 79 80 49 89 | 32 75 80 56 77 48 59 89 6 67 87 33 14 44 50 49 28 82 79 40 9 31 99 8 96
Card 6: 32 94 17 27 59 63 7 87 68 53 | 2 37 31 69 17 7 75 53 87 26 51 96 19 63 59 68 34 56 35 30 93 79 89 61 71
Card 7: 19 40 50 67 3 2 79 33 14 98 | 51 30 70 72 2 20 35 50 94 37 40 74 14 91 33 98 67 92 3 59 79 19 97 75 31
Card 8: 67 12 63 96 61 48 95 40 73 46 | 67 12 40 63 15 46 33 16 43 92 78 74 95 73 4 53 14 9 90 94 72 13 96 54 61
Card 9: 47 23 84 63 95 98 26 90 99 64 | 98 95 4 47 1 23 26 11 74 84 36 82 63 60 53 44 6 59 64 99 17 42 90 85 19
Card 10: 70 82 46 43 38 21 2 98 33 64 | 93 3 64 21 96 80 32 70 79 58 34 42 2 19 39 61 46 31 88 43 87 54 67 69 9
Card 11: 44 79 34 75 85 94 2 81 55 66 | 55 85 6 58 72 51 37 44 29 79 39 66 49 48 75 15 83 81 2 24 94 99 34 59 33
Card 12: 74 34 8 69 16 83 80 97 22 29 | 96 97 5 87 50 84 94 19 93 52 40 46 15 7 41 37 98 12 16 56 65 95 27 90 54
Card 13: 2 56 8 43 13 72 33 11 36 29 | 57 40 14 35 18 65 78 87 58 84 51 2 43 61 37 66 30 10 39 60 64 54 48 9 15
Card 14: 43 84 95 53 44 69 9 94 5 17 | 65 74 88 75 81 10 62 83 33 51 76 26 89 94 80 17 56 42 21 6 87 1 46 95 9
Card 15: 57 7 28 1 5 11 81 43 69 34 | 52 49 8 91 34 2 29 74 94 81 77 58 11 83 96 43 40 55 89 27 10 30 7 57 28
Card 16: 6 14 70 53 54 52 26 72 59 42 | 37 52 60 53 86 49 91 33 4 77 64 51 23 85 89 10 42 8 29 66 61 74 99 26 87
Card 17: 10 86 55 81 40 23 25 67 93 59 | 68 62 15 32 54 85 99 5 10 2 56 38 64 11 55 84 50 67 34 12 52 59 76 1 36
Card 18: 32 90 99 60 31 54 58 78 88 61 | 63 93 58 47 80 60 46 88 21 48 83 31 35 64 23 24 55 91 1 73 45 20 29 77 66
Card 19: 80 1 28 63 37 42 24 81 99 94 | 15 10 33 88 28 2 16 62 81 72 42 67 49 38 65 95 63 61 24 52 11 6 26 39 70
Card 20: 44 26 16 4 55 63 33 36 82 86 | 70 3 46 58 41 95 96 73 15 13 99 69 91 75 87 57 92 65 51 38 53 80 14 52 48
Card 21: 48 36 78 7 17 2 61 54 49 11 | 56 41 84 37 45 62 40 18 35 33 43 57 80 9 32 13 25 46 61 58 55 48 30 11 74
Card 22: 83 30 3 9 31 13 82 81 15 74 | 64 47 66 39 14 17 10 79 84 62 27 81 73 96 43 42 36 40 70 80 90 41 50 55 16
Card 23: 84 6 52 97 89 48 62 20 15 53 | 41 66 12 56 86 61 45 38 1 51 31 92 14 96 16 37 67 98 64 57 77 10 73 39 80
Card 24: 90 8 46 94 95 43 31 74 80 66 | 49 91 47 1 37 48 72 45 29 26 76 58 44 97 20 70 55 77 13 86 19 87 59 4 34
Card 25: 80 52 16 86 65 84 31 36 49 59 | 95 72 65 80 52 97 59 9 81 2 96 36 86 31 16 8 48 6 50 66 84 49 78 18 56
Card 26: 32 56 87 82 62 97 42 22 61 83 | 85 29 58 59 48 20 69 50 98 46 60 25 40 52 73 28 66 63 1 6 74 12 88 37 64
Card 27: 46 65 51 32 83 91 67 52 43 71 | 98 83 43 46 36 71 38 14 30 26 5 47 3 85 61 51 4 91 35 28 67 48 60 52 74
Card 28: 26 60 29 89 24 28 95 92 78 97 | 39 95 41 34 16 25 62 60 53 97 24 92 77 78 29 68 35 86 71 58 89 12 28 9 11
Card 29: 66 6 93 49 51 2 48 96 62 89 | 2 17 62 39 6 51 93 18 95 54 72 1 97 66 84 96 60 89 90 69 13 48 49 36 16
Card 30: 53 95 92 75 76 56 48 87 79 15 | 1 4 97 3 6 79 11 76 88 7 56 75 48 95 60 94 59 36 46 86 70 69 91 2 73
Card 31: 80 63 37 67 35 98 97 72 87 52 | 67 77 58 66 54 19 87 75 76 51 29 80 53 26 24 49 88 91 52 72 86 81 4 39 37
Card 32: 67 23 77 16 4 31 24 13 76 86 | 16 6 69 31 51 4 28 83 1 89 79 24 46 38 99 77 43 50 19 87 90 73 85 56 70
Card 33: 38 41 64 25 96 99 68 58 92 40 | 84 59 5 94 49 6 2 40 73 96 38 23 43 91 47 88 24 17 9 25 35 52 13 92 64
Card 34: 24 52 69 59 55 8 43 15 45 92 | 56 47 84 62 4 81 88 92 54 96 52 89 42 46 49 33 69 10 51 12 5 82 85 65 20
Card 35: 19 82 84 29 58 44 65 87 26 32 | 95 63 13 56 77 3 57 17 32 20 81 2 82 76 48 39 71 93 84 8 15 88 89 74 11
Card 36: 41 13 70 23 65 66 47 75 24 98 | 17 94 89 42 47 9 55 54 48 57 71 69 63 33 35 97 90 20 43 24 18 6 76 82 29
Card 37: 23 39 77 90 56 47 2 82 66 72 | 2 61 16 48 65 62 77 5 49 35 72 93 22 83 18 3 38 1 14 31 99 54 52 8 13
Card 38: 99 18 59 51 94 52 44 71 30 7 | 95 31 1 58 94 8 28 18 50 81 59 26 57 82 67 30 17 86 87 79 37 23 10 83 3
Card 39: 98 3 38 42 18 71 66 80 39 79 | 51 88 43 25 90 27 9 35 29 4 21 10 79 13 54 42 11 61 36 30 24 15 6 65 26
Card 40: 6 27 58 3 67 72 45 12 63 61 | 36 39 75 2 78 95 64 22 41 93 54 91 50 11 55 74 17 56 92 88 87 89 85 6 40
Card 41: 37 76 61 43 25 29 89 11 35 93 | 27 30 81 38 62 4 33 92 71 77 6 22 75 76 97 67 70 13 65 96 15 17 36 56 78
Card 42: 42 7 79 61 98 92 2 95 14 44 | 62 88 67 48 82 59 27 34 6 39 25 97 87 81 37 50 65 10 41 56 12 32 68 30 38
Card 43: 12 9 34 93 71 99 95 86 87 40 | 6 24 93 79 85 25 90 72 71 13 66 86 9 8 12 50 57 30 39 59 29 34 26 17 51
Card 44: 24 96 61 97 83 98 10 1 29 81 | 74 43 92 5 1 56 15 60 83 96 50 72 81 98 29 52 49 24 97 90 95 10 84 12 61
Card 45: 12 29 82 5 83 92 86 51 98 32 | 61 14 28 80 48 55 17 5 19 12 62 27 51 18 86 91 49 58 11 65 13 79 68 98 36
Card 46: 67 47 77 25 15 64 90 76 16 88 | 64 86 26 25 77 78 56 84 87 76 15 88 36 90 93 96 8 13 67 47 10 16 42 27 6
Card 47: 97 25 76 83 35 90 53 16 34 18 | 5 26 77 53 36 90 43 61 94 89 41 99 93 92 56 2 10 29 1 47 55 38 66 13 15
Card 48: 3 75 52 55 41 86 9 54 26 98 | 93 30 12 72 36 62 79 25 61 90 31 87 59 88 27 56 99 6 5 11 58 80 78 77 43
Card 49: 34 44 25 93 74 5 15 37 14 30 | 8 15 89 36 38 60 9 48 93 74 96 20 44 67 30 97 5 70 86 80 31 25 14 51 66
Card 50: 93 78 49 98 76 74 58 7 60 46 | 44 15 1 78 67 28 13 36 46 64 49 98 56 12 97 60 18 55 91 32 89 94 99 66 76
Card 51: 36 78 35 85 27 17 18 42 75 92 | 63 5 62 52 65 71 28 3 15 97 22 99 23 44 16 10 88 4 67 34 80 38 27 83 69
Card 52: 70 74 14 71 11 83 86 18 99 77 | 26 49 98 94 35 67 31 66 46 36 73 87 10 43 92 7 25 81 62 82 55 39 64 78 4
Card 53: 14 83 11 94 46 63 42 29 34 56 | 25 71 3 39 2 64 70 5 68 90 32 75 36 14 74 79 10 58 16 60 83 19 54 35 52
Card 54: 35 77 49 19 41 94 36 83 73 75 | 62 17 8 13 20 98 21 31 88 6 14 30 42 53 59 61 57 22 54 27 74 66 50 58 7
Card 55: 25 6 23 81 19 51 17 58 29 72 | 12 67 61 97 85 76 2 66 27 1 41 73 78 90 22 10 82 79 39 60 42 72 96 17 24
Card 56: 23 13 16 27 17 15 9 66 89 93 | 48 67 53 22 96 33 5 25 94 24 43 68 49 77 63 42 73 97 86 83 56 62 36 31 76
Card 57: 36 67 99 41 58 76 8 72 70 35 | 62 47 69 27 9 48 34 83 50 7 98 78 94 93 15 52 25 84 4 80 24 10 40 91 11
Card 58: 14 6 7 21 88 32 54 42 56 33 | 55 62 54 7 14 21 88 25 11 80 58 5 93 12 23 86 6 42 33 96 67 61 49 56 32
Card 59: 61 60 16 27 13 15 17 49 3 19 | 49 94 17 19 15 1 18 37 4 77 55 12 8 13 9 89 64 60 69 22 16 43 27 3 61
Card 60: 14 95 23 48 96 36 16 77 13 17 | 24 77 53 16 11 36 52 13 26 23 85 50 14 83 96 71 41 48 45 81 95 44 31 17 21
Card 61: 72 13 69 70 52 8 16 76 3 65 | 27 96 13 37 49 79 70 57 23 86 9 18 65 21 1 72 85 22 16 68 31 24 81 73 55
Card 62: 28 94 10 97 71 42 89 53 27 75 | 28 97 12 89 2 54 21 42 48 43 91 82 63 10 71 90 38 3 75 27 46 53 94 66 77
Card 63: 1 36 27 90 97 33 87 9 89 44 | 12 30 97 7 33 5 39 47 14 16 28 83 74 3 38 80 99 20 69 27 85 72 31 18 2
Card 64: 59 52 91 93 90 38 36 9 98 3 | 98 90 52 92 78 36 87 75 9 76 59 39 53 63 86 29 5 64 3 32 93 80 65 38 91
Card 65: 78 61 30 58 32 23 1 28 37 39 | 5 35 32 37 1 20 21 70 30 61 93 34 76 40 58 89 27 26 36 28 39 71 78 56 23
Card 66: 88 68 34 6 60 23 14 94 91 33 | 11 31 50 58 14 33 80 82 99 79 87 40 75 93 88 24 23 6 94 91 63 34 39 38 16
Card 67: 93 88 20 45 69 97 54 80 43 79 | 2 34 18 85 60 63 30 28 90 77 80 65 41 37 69 94 1 71 59 38 40 50 73 96 64
Card 68: 20 7 49 18 56 86 8 43 35 42 | 95 86 35 93 94 6 18 84 42 3 20 14 5 54 17 41 88 82 71 24 87 27 43 16 53
Card 69: 69 46 23 15 97 36 34 24 4 31 | 34 43 6 36 46 4 69 17 97 79 96 67 54 64 23 89 45 76 60 15 2 31 94 24 70
Card 70: 88 55 97 13 26 68 28 25 92 39 | 55 54 80 5 40 39 84 13 60 14 70 90 92 27 26 31 62 91 23 59 28 97 68 88 25
Card 71: 76 78 20 57 1 26 42 50 92 65 | 5 88 16 65 92 17 97 42 74 50 71 76 46 57 26 47 25 9 90 77 78 56 98 20 1
Card 72: 1 49 13 29 14 84 38 73 2 80 | 28 13 92 86 65 89 87 50 98 25 10 30 52 33 40 44 75 21 88 57 5 8 34 70 91
Card 73: 60 30 20 5 76 59 58 77 44 24 | 43 18 77 24 44 76 41 51 53 4 59 5 84 46 45 35 82 1 78 65 58 95 86 30 73
Card 74: 32 92 95 62 46 1 12 53 31 6 | 59 35 65 91 39 40 72 61 45 60 98 51 6 66 43 81 89 47 75 19 85 16 69 96 25
Card 75: 9 2 82 57 36 17 91 11 54 5 | 7 97 11 27 2 36 98 88 45 44 80 34 17 39 31 57 77 73 47 68 62 78 61 91 67
Card 76: 79 36 67 27 35 90 14 1 43 31 | 26 96 48 32 28 11 87 45 81 71 58 5 86 57 34 78 91 12 51 56 40 84 9 64 39
Card 77: 82 36 42 46 40 13 76 51 49 34 | 84 88 68 76 11 56 66 17 96 7 72 31 65 13 97 90 9 39 23 93 28 46 78 44 34
Card 78: 91 20 12 28 84 50 14 94 93 86 | 97 72 58 82 87 67 12 71 50 61 9 35 29 55 39 92 54 7 24 18 41 38 22 49 51
Card 79: 31 6 69 83 94 47 34 33 23 21 | 11 10 61 35 59 90 7 12 54 45 92 52 19 4 64 24 50 71 73 30 65 36 39 79 15
Card 80: 70 39 43 66 31 90 27 88 78 97 | 5 76 31 21 80 11 71 53 15 79 55 93 3 64 14 1 96 41 8 4 44 73 91 77 45
Card 81: 46 69 21 40 35 16 74 50 17 86 | 45 96 48 15 11 20 73 1 59 38 98 55 4 39 24 44 85 13 63 94 92 68 37 10 78
Card 82: 20 42 3 4 71 63 38 83 51 41 | 66 70 34 61 89 96 91 15 62 87 43 23 28 55 67 82 1 53 35 60 16 29 56 95 54
Card 83: 78 1 65 82 90 45 55 67 37 15 | 50 40 46 79 1 80 86 94 85 53 84 13 90 17 16 32 21 19 7 58 44 77 57 81 74
Card 84: 59 82 8 99 1 24 16 48 51 6 | 8 3 22 35 36 58 97 55 73 95 51 48 70 57 84 69 40 66 13 78 5 63 94 49 18
Card 85: 76 83 7 37 28 79 44 39 92 18 | 65 97 61 68 92 40 80 95 29 91 81 6 62 73 44 21 4 17 28 48 36 37 19 25 42
Card 86: 72 77 6 23 42 93 19 87 45 56 | 78 21 18 86 73 2 22 9 98 65 87 89 40 7 69 71 79 37 67 20 74 10 34 15 28
Card 87: 92 72 98 30 24 74 86 52 69 87 | 94 15 60 6 3 5 4 69 33 74 49 51 72 41 76 10 52 67 86 35 34 22 98 92 66
Card 88: 48 96 2 25 95 28 37 94 45 30 | 38 39 56 22 71 21 18 87 46 14 79 77 43 72 10 89 34 57 58 92 31 5 91 54 66
Card 89: 63 31 84 20 99 21 30 67 60 38 | 50 29 21 5 1 8 9 14 76 16 24 17 33 42 99 62 96 39 83 32 44 51 23 88 63
Card 90: 90 96 82 28 20 8 79 94 84 17 | 74 45 12 55 24 94 28 35 4 7 79 57 82 63 84 73 20 10 96 89 69 90 22 16 17
Card 91: 99 44 27 28 15 66 61 41 54 81 | 77 50 8 26 33 28 61 81 41 15 92 2 66 36 62 43 27 11 58 30 88 65 53 57 82
Card 92: 35 99 38 22 33 70 65 14 51 91 | 68 35 65 77 78 33 53 99 38 96 87 34 69 6 83 17 30 91 70 20 85 75 82 14 15
Card 93: 77 42 61 83 98 28 5 34 23 88 | 88 61 20 98 13 36 68 44 5 14 52 80 55 37 25 32 96 58 77 46 28 26 21 83 75
Card 94: 57 17 27 35 62 85 92 7 65 67 | 93 68 79 95 59 64 10 97 96 35 90 6 5 80 73 85 70 62 19 13 52 74 72 17 81
Card 95: 38 96 40 36 44 78 28 47 70 90 | 82 47 32 78 9 84 42 62 6 37 68 7 31 97 93 22 11 58 23 63 79 35 98 36 70
Card 96: 37 66 81 97 23 51 40 31 86 17 | 63 39 23 12 97 55 31 11 47 24 43 8 79 61 49 14 88 53 92 30 94 93 35 60 9
Card 97: 76 97 35 85 90 70 53 54 40 91 | 22 12 33 32 56 23 59 62 6 48 67 17 65 84 94 96 9 41 68 21 10 61 91 52 51
Card 98: 99 14 64 51 61 40 30 59 87 4 | 57 53 36 26 78 37 86 7 43 74 44 33 34 58 3 85 67 82 2 94 38 32 65 80 45
Card 99: 69 79 90 36 45 71 94 43 50 70 | 11 67 31 25 84 57 39 89 34 78 51 68 9 35 54 70 95 29 56 83 63 47 20 58 23
Card 100: 39 35 5 66 47 37 2 90 20 4 | 56 61 1 57 48 14 96 11 42 98 6 24 45 19 31 49 21 74 53 41 25 95 69 40 79
Card 101: 89 50 4 33 80 44 14 92 51 28 | 11 51 95 73 80 44 50 89 93 72 33 29 23 60 59 28 54 49 14 75 92 82 7 24 78
Card 102: 96 88 16 82 75 33 44 72 6 85 | 7 42 68 56 98 30 44 20 62 6 91 95 16 40 18 11 83 13 52 50 61 45 80 74 4
Card 103: 37 42 77 46 8 41 30 62 90 82 | 70 90 72 8 46 9 35 45 37 41 4 93 99 81 42 14 20 57 85 83 82 30 62 43 77
Card 104: 59 43 8 48 32 69 58 40 44 60 | 50 17 95 27 44 89 53 34 59 11 72 48 43 64 40 88 3 58 32 60 37 8 91 69 92
Card 105: 5 63 74 79 60 89 78 95 54 6 | 97 47 24 70 22 92 63 41 67 33 84 16 62 6 52 90 57 82 74 86 46 50 5 32 78
Card 106: 81 64 44 37 41 36 59 50 20 22 | 25 22 39 11 15 36 90 88 16 59 19 84 20 44 58 63 53 71 29 40 94 56 61 81 6
Card 107: 69 39 95 35 82 15 84 49 74 31 | 95 76 61 38 64 58 33 28 97 23 35 78 8 5 34 43 59 65 4 26 30 87 96 50 11
Card 108: 16 36 75 64 66 29 77 12 40 10 | 66 10 83 15 49 40 37 86 9 52 24 50 29 20 23 41 16 25 64 76 56 36 19 34 77
Card 109: 70 41 35 15 46 74 40 77 42 93 | 82 99 30 12 49 64 70 41 56 38 5 6 87 68 80 26 39 35 63 22 27 23 74 93 46
Card 110: 6 77 75 51 74 66 45 80 48 73 | 48 87 5 62 70 56 9 96 12 21 83 49 25 99 3 38 44 18 13 2 28 88 58 78 65
Card 111: 78 28 72 47 41 44 90 74 68 87 | 80 95 90 26 54 48 56 29 96 67 8 98 62 59 63 53 68 5 72 12 18 41 51 14 93
Card 112: 28 91 33 83 81 73 15 24 21 75 | 39 92 21 52 71 85 89 53 62 33 28 95 43 65 88 78 40 55 34 66 20 12 32 91 29
Card 113: 55 40 8 1 7 35 70 65 42 41 | 12 80 19 62 48 39 87 89 96 13 16 88 54 63 9 28 73 43 86 33 26 72 35 17 1
Card 114: 61 15 3 7 35 76 9 66 33 74 | 16 7 38 20 79 70 56 27 99 5 95 39 43 49 73 78 25 11 96 84 85 55 67 91 29
Card 115: 87 99 8 31 43 82 67 74 76 49 | 91 77 49 41 6 45 81 34 24 72 79 1 60 59 12 10 9 22 96 5 83 70 7 93 63
Card 116: 27 96 16 90 61 72 73 9 64 35 | 89 55 44 2 11 7 74 76 85 13 48 15 50 40 63 73 31 58 46 8 38 37 10 97 98
Card 117: 28 83 58 84 81 23 76 41 69 46 | 73 55 87 71 3 20 43 26 7 24 23 92 97 27 88 22 11 6 45 10 38 68 65 5 82
Card 118: 84 47 70 88 25 20 58 82 7 87 | 52 91 53 26 79 73 85 2 12 86 69 49 67 13 92 63 36 62 23 46 35 95 90 40 64
Card 119: 12 28 10 43 44 49 38 36 7 30 | 63 84 43 30 10 44 73 98 49 66 86 82 38 36 76 60 20 28 12 3 26 74 7 79 72
Card 120: 64 47 61 68 90 84 54 10 81 12 | 47 64 10 34 85 7 98 73 68 12 92 42 31 81 54 2 49 4 61 90 84 5 74 93 25
Card 121: 47 50 44 35 40 60 28 80 23 99 | 15 22 16 93 60 40 88 83 34 89 46 69 57 33 3 98 5 81 28 2 44 54 87 71 4
Card 122: 46 53 63 32 87 37 49 25 99 73 | 95 65 7 80 35 74 98 30 8 52 84 40 64 36 23 45 67 33 76 96 90 31 39 78 22
Card 123: 92 37 35 10 89 84 85 16 3 9 | 10 28 15 60 6 21 58 95 75 84 35 99 44 59 37 9 51 91 1 61 3 92 69 85 89
Card 124: 94 67 68 3 39 78 76 79 36 74 | 17 73 75 29 86 89 72 70 12 6 66 85 13 83 37 42 28 2 84 30 10 95 20 65 44
Card 125: 28 64 58 33 90 97 7 98 66 16 | 7 66 46 9 86 56 16 33 47 90 65 87 15 32 31 67 64 28 49 17 25 84 97 55 57
Card 126: 14 22 7 83 85 89 27 39 78 69 | 66 45 2 20 62 38 51 90 11 43 60 57 27 3 18 94 54 59 46 58 37 73 87 12 67
Card 127: 14 39 77 20 29 55 94 38 88 11 | 55 38 51 87 72 4 69 27 41 68 9 94 37 29 58 59 48 20 17 39 92 19 53 14 16
Card 128: 43 1 85 87 45 51 64 91 93 73 | 21 13 55 72 14 57 46 43 2 83 62 36 59 33 86 48 68 19 40 54 50 35 39 81 41
Card 129: 61 90 20 1 76 79 66 18 94 99 | 92 30 20 8 73 28 38 15 13 36 79 1 64 76 33 3 26 88 18 23 93 12 58 91 37
Card 130: 31 34 13 96 55 85 51 95 54 78 | 6 21 47 48 94 27 86 46 8 25 84 15 43 13 23 76 60 32 58 11 99 1 79 88 55
Card 131: 71 52 74 6 43 37 73 89 9 16 | 22 24 12 11 76 40 99 87 17 78 61 63 53 75 1 77 25 58 31 23 86 20 97 49 38
Card 132: 75 27 99 16 5 17 60 1 28 34 | 44 3 82 47 97 30 4 69 23 11 98 46 29 96 81 31 51 7 94 67 83 38 32 73 60
Card 133: 21 46 70 93 7 66 60 51 63 35 | 4 24 17 62 61 15 9 95 72 43 67 83 6 75 88 12 8 22 40 68 54 76 20 37 32
Card 134: 55 33 24 47 9 6 86 43 89 30 | 49 23 59 98 72 90 13 93 1 26 78 44 83 82 40 41 71 79 68 57 96 92 48 17 10
Card 135: 18 88 45 34 65 8 92 37 98 30 | 72 34 88 65 50 30 9 64 8 13 10 36 69 3 22 18 78 35 98 97 81 83 57 92 37
Card 136: 62 13 33 30 58 9 21 68 54 48 | 55 49 81 38 48 39 75 17 54 84 47 24 71 44 91 37 4 3 10 64 86 92 30 51 40
Card 137: 49 8 77 76 25 88 39 17 63 22 | 56 71 8 7 17 41 76 74 77 15 88 3 97 25 48 98 64 39 55 49 33 83 63 22 2
Card 138: 11 36 77 55 53 47 37 76 66 8 | 37 13 24 66 96 35 4 22 53 98 70 50 76 77 97 11 38 8 75 47 51 43 15 36 55
Card 139: 61 9 64 99 47 50 6 75 45 65 | 9 99 31 10 72 66 45 75 14 47 60 2 64 6 50 65 8 52 58 61 25 38 29 90 19
Card 140: 79 41 61 71 96 11 60 24 74 95 | 40 71 11 96 75 33 41 64 49 55 61 76 95 34 24 20 9 60 26 69 1 97 86 29 74
Card 141: 64 44 35 96 32 78 94 53 68 97 | 9 78 40 97 56 83 48 64 95 69 35 68 59 43 17 32 4 60 53 52 98 61 96 94 44
Card 142: 73 34 61 17 49 3 35 66 85 58 | 28 13 21 45 85 19 67 29 49 5 30 61 38 52 2 3 48 31 17 99 58 34 80 9 14
Card 143: 99 8 50 43 75 69 88 40 13 91 | 85 43 67 24 91 62 99 38 18 16 2 34 26 82 98 6 53 37 77 33 30 42 3 31 36
Card 144: 90 86 40 96 44 43 91 93 20 80 | 66 64 19 79 18 10 95 52 72 31 89 92 62 68 23 75 78 84 37 15 13 36 38 26 81
Card 145: 2 92 97 59 98 96 34 41 25 72 | 10 20 43 6 42 22 92 61 73 99 21 46 41 25 34 96 63 50 59 13 91 38 79 57 72
Card 146: 50 81 51 16 9 34 30 65 60 53 | 55 6 75 29 96 42 86 11 18 45 46 77 87 54 25 91 43 94 23 24 99 82 31 72 93
Card 147: 84 27 17 26 33 98 36 58 5 13 | 90 65 96 28 31 10 14 95 46 94 22 16 68 50 77 73 9 42 59 64 91 19 67 63 99
Card 148: 67 62 86 8 87 92 94 80 93 25 | 9 3 60 66 47 23 20 72 28 75 11 37 50 13 34 58 2 64 16 98 88 56 81 7 38
Card 149: 20 93 31 26 11 42 53 37 3 84 | 22 79 34 17 42 94 32 55 33 2 13 36 80 63 14 11 59 12 98 8 50 93 20 53 84
Card 150: 1 75 15 7 80 59 99 86 71 58 | 31 72 14 67 85 18 96 15 8 13 80 47 45 64 60 24 46 98 6 97 39 49 69 4 54
Card 151: 56 46 61 40 86 85 74 79 94 36 | 10 9 2 32 22 43 87 40 68 20 36 94 89 86 45 27 42 71 92 59 16 6 24 81 73
Card 152: 65 40 13 51 60 42 1 99 19 73 | 74 72 39 50 49 27 37 78 51 38 7 41 23 95 81 43 97 19 73 28 89 17 91 6 62
Card 153: 28 76 9 48 94 45 23 32 26 21 | 4 63 33 28 36 81 98 14 50 55 3 31 1 71 62 17 70 80 46 59 51 20 38 22 12
Card 154: 11 53 34 58 30 8 86 71 2 96 | 85 92 62 82 90 75 51 15 41 19 70 55 67 74 77 27 64 6 14 48 76 88 25 83 42
Card 155: 19 83 27 70 46 16 57 48 18 86 | 13 4 73 2 75 36 53 69 15 21 9 10 64 95 78 61 43 71 12 99 92 56 6 42 28
Card 156: 87 63 55 52 11 78 15 42 83 38 | 70 40 42 97 41 48 87 78 83 73 72 99 63 66 11 22 6 69 76 3 61 1 91 16 51
Card 157: 63 87 28 40 56 50 64 73 43 51 | 16 21 7 50 44 88 35 9 32 80 51 30 95 82 5 46 76 65 37 25 29 61 26 4 56
Card 158: 47 63 14 74 88 90 71 87 95 32 | 14 30 47 88 15 29 41 11 59 90 92 64 77 94 68 89 12 19 85 28 62 87 33 71 95
Card 159: 21 46 50 45 92 35 73 33 25 81 | 17 38 72 94 29 6 49 7 71 21 9 80 99 39 58 25 44 45 35 57 20 33 61 50 73
Card 160: 18 1 12 75 88 32 59 51 73 9 | 94 83 70 5 1 73 18 75 9 92 76 45 7 36 30 65 60 32 25 12 33 51 88 59 23
Card 161: 6 15 69 39 76 73 99 84 21 32 | 82 5 64 79 92 91 2 48 6 12 45 43 80 95 33 21 55 15 66 34 73 16 58 39 54
Card 162: 74 67 93 73 40 6 54 81 30 99 | 89 4 36 18 6 17 31 71 96 70 77 83 20 99 11 26 93 62 85 74 24 30 8 84 3
Card 163: 74 58 30 34 37 66 28 22 88 25 | 82 47 88 36 93 81 35 20 12 79 54 24 40 68 41 51 86 30 11 65 34 1 8 69 76
Card 164: 71 77 50 90 5 56 92 80 34 22 | 82 31 50 70 69 90 5 85 39 80 73 77 54 56 75 34 15 92 26 32 22 42 17 71 23
Card 165: 21 41 33 75 19 88 18 40 86 64 | 35 53 99 80 86 30 63 19 50 74 4 41 8 32 21 64 75 51 27 6 23 18 90 72 40
Card 166: 76 73 55 71 90 22 12 81 34 9 | 66 63 23 30 87 62 59 7 67 89 78 24 64 68 27 97 19 25 94 53 48 56 45 70 33
Card 167: 98 60 45 13 8 9 66 82 41 95 | 86 19 46 44 78 23 41 83 84 13 54 12 10 5 98 22 57 21 59 80 58 1 69 82 93
Card 168: 40 36 18 3 44 29 86 23 13 75 | 18 44 3 9 40 62 55 1 78 49 27 13 87 48 12 36 86 17 29 76 34 20 32 50 94
Card 169: 64 4 61 79 17 20 84 37 70 99 | 73 5 90 54 55 96 60 36 28 74 64 99 68 61 4 33 29 70 27 42 8 67 15 17 34
Card 170: 12 91 87 50 84 14 38 93 43 78 | 95 46 66 64 47 60 36 70 97 73 56 93 83 65 11 1 15 7 42 41 59 40 84 82 62
Card 171: 3 6 81 89 27 88 46 37 69 14 | 60 31 64 61 65 25 83 43 19 20 74 75 17 92 4 53 1 91 97 16 26 22 95 50 84
Card 172: 40 35 87 27 3 58 81 45 59 80 | 90 21 88 64 66 52 5 63 65 40 13 79 82 62 85 34 78 37 33 27 87 26 58 95 75
Card 173: 8 45 37 66 63 7 97 42 95 28 | 56 45 24 78 82 57 83 51 18 95 5 79 59 50 30 11 19 43 88 90 49 62 17 68 22
Card 174: 8 56 80 50 6 12 36 32 24 98 | 53 22 70 13 62 58 15 79 78 7 9 38 26 63 75 44 17 82 67 59 71 86 39 46 93
Card 175: 43 47 46 35 94 39 67 3 2 24 | 86 23 52 91 66 45 81 75 61 80 10 17 60 16 44 57 83 62 32 37 38 12 48 93 84
Card 176: 82 97 11 25 15 68 7 24 77 46 | 18 35 2 80 48 75 19 47 70 39 99 43 28 62 33 50 13 17 10 58 86 45 16 88 60
Card 177: 95 59 14 68 13 22 4 75 2 70 | 64 45 12 31 99 77 59 28 91 42 21 89 67 9 90 78 37 14 46 75 52 15 22 79 96
Card 178: 83 17 81 96 9 2 80 70 57 53 | 85 80 62 9 29 25 8 83 2 66 17 68 84 3 81 42 57 23 15 72 96 53 70 7 73
Card 179: 48 84 29 81 88 3 10 27 21 16 | 74 21 97 28 18 81 84 6 42 76 29 89 48 83 50 3 88 73 22 10 2 55 16 27 36
Card 180: 30 77 49 58 39 1 97 13 25 34 | 75 53 61 99 34 62 48 1 51 77 84 25 49 26 79 59 13 11 30 60 21 39 97 93 58
Card 181: 73 52 53 23 83 74 1 87 86 54 | 23 53 54 5 11 1 55 73 74 44 46 82 34 41 60 67 31 96 35 52 86 15 18 87 83
Card 182: 90 48 22 80 52 41 78 11 55 32 | 60 9 2 21 87 42 68 16 15 50 95 51 99 40 30 52 20 12 26 49 92 19 84 36 76
Card 183: 33 63 2 19 24 61 10 14 37 1 | 59 20 32 69 98 55 85 36 29 71 61 68 14 2 7 88 39 16 94 92 74 45 90 38 35
Card 184: 85 65 43 1 75 27 17 10 91 18 | 27 42 55 89 38 66 82 75 64 43 50 39 52 10 59 93 18 3 91 1 85 40 26 8 65
Card 185: 74 7 10 70 95 76 27 50 13 36 | 70 15 58 18 13 74 4 64 50 44 54 27 56 35 87 28 76 92 85 36 66 95 90 96 78
Card 186: 45 59 16 99 43 79 89 90 40 49 | 18 97 56 67 61 29 80 34 91 88 33 95 41 76 78 68 28 46 51 93 98 72 54 74 8
Card 187: 87 69 84 72 92 86 13 76 40 38 | 38 8 37 71 30 49 50 21 51 39 34 90 84 16 11 10 4 63 7 42 36 77 48 85 20
Card 188: 96 18 79 50 81 65 84 74 76 58 | 21 48 35 12 83 70 23 88 58 3 74 84 72 76 43 71 8 27 2 37 46 89 5 54 81
Card 189: 22 90 97 45 19 70 36 23 81 2 | 6 60 40 57 41 16 91 42 58 38 92 31 15 76 35 73 11 33 24 30 32 85 18 51 93
Card 190: 72 69 52 65 14 74 64 57 70 33 | 41 99 32 49 96 34 82 80 42 1 69 40 64 44 88 86 14 31 28 22 38 46 45 54 29
Card 191: 86 70 76 64 97 6 56 34 87 41 | 96 81 52 89 28 16 29 90 41 32 70 68 9 88 30 5 60 92 61 49 56 50 46 37 11
Card 192: 14 42 66 20 48 94 55 51 23 75 | 83 74 97 43 28 72 18 26 13 59 93 19 10 60 89 82 63 50 3 21 4 79 91 98 36
Card 193: 13 33 98 37 19 86 32 15 95 96 | 56 90 5 60 24 21 46 73 29 3 58 75 77 66 41 48 82 84 10 53 43 15 18 2 89
Card 194: 77 6 10 48 14 79 73 51 49 25 | 86 12 37 23 43 34 5 89 97 27 53 70 75 19 15 79 45 26 1 73 68 36 2 78 18
Card 195: 94 57 24 37 46 75 73 10 29 5 | 78 25 21 48 22 46 38 76 19 17 64 32 88 99 63 12 20 41 16 7 14 54 81 97 89
Card 196: 76 48 15 89 44 50 79 80 52 78 | 93 55 21 18 73 31 47 20 97 83 87 30 6 24 77 74 67 45 76 65 37 43 42 98 38
Card 197: 67 21 75 10 9 6 47 88 45 70 | 91 95 58 82 52 50 87 81 78 13 64 53 57 14 55 25 36 76 19 86 56 2 16 54 1
"""
solution04_1 = fn input ->
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
["Card " <> _, line] = line |> String.split(":")
line
|> String.split("|")
|> Enum.map(fn nums ->
Regex.scan(~r/\d+/, nums)
|> Enum.map(fn [s] -> s |> String.to_integer() end)
end)
end)
|> Enum.map(fn [win, scratch] ->
scratch
|> Enum.reduce(0, fn num, acc ->
if num in win do
if acc == 0 do
1
else
acc * 2
end
else
acc
end
end)
end)
|> Enum.sum()
end
solution04_1.(sample04_1)
solution04_1.(input04_1)
Day 4 - Part 2
sample04_2 = sample04_1
input04_2 = input04_1
solution04_2 = fn input ->
[[win, _] | _] =
cards =
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
["Card " <> _, line] = line |> String.split(":")
line
|> String.split("|")
|> Enum.map(fn nums ->
Regex.scan(~r/\d+/, nums)
|> Enum.map(fn [s] -> s |> String.to_integer() end)
end)
end)
acc = 1..(win |> Enum.count()) |> Enum.map(fn _ -> 1 end)
cards
|> Enum.map(fn [win, scratch] ->
scratch
|> Enum.filter(fn num -> num in win end)
|> Enum.count()
end)
|> Enum.reduce({[], acc}, fn match, {total, [copy | next_copies]} ->
total = total ++ [copy]
next_copies =
(next_copies ++ [1])
|> Enum.with_index()
|> Enum.map(fn {c, i} ->
if i < match do
c + copy
else
c
end
end)
{total, next_copies}
end)
|> elem(0)
|> Enum.sum()
end
solution04_2.(sample04_2)
solution04_2.(input04_2)
Day 5 - Part 1
sample05_1 = """
seeds: 79 14 55 13
seed-to-soil map:
50 98 2
52 50 48
soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15
fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4
water-to-light map:
88 18 7
18 25 70
light-to-temperature map:
45 77 23
81 45 19
68 64 13
temperature-to-humidity map:
0 69 1
1 0 69
humidity-to-location map:
60 56 37
"""
input05_1 = """
seeds: 768975 36881621 56868281 55386784 1828225758 1084205557 2956956868 127170752 1117192172 332560644 357791695 129980646 819363529 9145257 993170544 70644734 3213715789 312116873 3107544690 59359615
seed-to-soil map:
2797638787 1764015146 26675178
3378130613 0 34101494
388521182 772535426 141493697
1148410839 174832460 323494173
4259440029 4076987921 35527267
1664835130 2610603190 214355271
530014879 1680432282 83582864
1471905012 758583825 13951601
3909335908 4187323696 107643600
3834527400 4173068203 14255493
2824313965 136499996 38332464
191321127 498326633 7266716
1562436628 34101494 102398502
3224943851 3320680296 153186762
4058150677 3747050674 42920787
2360258758 2578478063 32125127
1485856613 682003810 76580015
613597743 1875739628 457683244
4016979508 3789971461 35854425
3412232107 562825709 61634951
4101071464 3825825886 158368565
3848782893 4112515188 60553015
3119382417 1629353314 51078968
1879190401 1555705358 58037106
2169686033 2387905338 190572725
2900098047 914029123 217063885
1071280987 2824958461 77129852
3770924949 3984194451 63602451
2449927035 2902088313 205430088
2740406427 505593349 57232360
198587843 1365772019 189933339
0 3107518401 191321127
3741733930 4047796902 29191019
2655357123 1790690324 85049304
1937227507 1133313493 232458526
2392383885 624460660 57543150
2862646429 3298839528 8221502
3170461385 2333422872 54482466
3117161932 1131093008 2220485
2870867931 3307061030 13619266
2884487197 1613742464 15610850
4052833933 3741733930 5316744
soil-to-fertilizer map:
4028970075 3670916442 62323047
2369466456 2039626615 114411480
1849958430 857955699 318236064
3393877313 4090328901 50115157
2483877936 2154038095 163115765
1589335864 2448679033 50786994
378911477 2812908636 641955
1562596120 1971627164 26739744
2168194494 224261755 114905540
2837233268 2508892349 45204280
3094415439 2813550591 72281454
3166696893 1619734477 89254096
0 2317153860 40391789
1131679423 1771284034 40991112
1765319835 1708988573 9045883
1365410346 1420078500 197185774
2305946785 794436028 63519671
2882437548 2691241517 119296423
3001733971 3046337498 45651876
3643083526 3393877313 47307752
379553432 1812275146 28890919
1172670535 1206862634 190369115
2807083959 1741134725 30149309
2694347611 467149827 112736348
2646993701 579886175 47353910
4091293122 3733239489 203674174
1763025041 1718034456 2294794
40391789 1998366908 41259707
808535136 1176191763 22037784
799902049 1198229547 8633087
632706106 627240085 167195943
3598515708 3936913663 44567818
408444351 0 224261755
3799238698 3441185065 229731377
3443992470 4140444058 154523238
376441274 1617264274 2470203
1795171193 339167295 54787237
830572920 3091989374 301106503
81651496 1841166065 130461099
212112595 393954532 73195295
3255950989 2554096629 137144888
3690391278 3981481481 108847420
1363039650 2810537940 2370696
3047385847 2499466027 9426322
285307890 2357545649 91133384
2283100034 1397231749 22846751
1640122858 2923435315 122902183
3056812169 2885832045 37603270
1774365718 1720329250 20805475
fertilizer-to-water map:
4242763083 2459563591 52204213
2506579022 1704611330 53532973
268946243 855055502 34908994
1704611330 3860653042 434314254
2640952334 3547869528 81626644
1436013703 728008388 21784904
0 680695205 47313183
140858905 749793292 69300705
686187385 489152830 141379201
3612022528 2522034035 498682726
827566586 959642930 428042082
260322784 12467526 8623459
2435545592 3789619612 71033430
47313183 1387685012 93545722
303855237 21090985 382332148
2425279361 2511767804 10266231
2947118206 2257396248 202167343
1457798607 403423133 23432127
2138925584 1890202132 286353777
1366335269 889964496 69678434
1255608668 819093997 35961505
210159610 630532031 50163174
1291570173 0 12467526
2560111995 2176555909 80840339
3419426199 3416054902 131814626
3149285549 3159639578 110017210
2868977092 3081498464 78141114
4110705254 1758144303 132057829
3551240825 3020716761 60781703
2722578978 3269656788 146398114
3259302759 3629496172 160123440
1304037699 426855260 62297570
water-to-light map:
1712728062 165708071 30118229
994660402 322543075 139832356
2666749758 3184731531 182834316
3535613929 2585377632 130318231
1589771501 643255284 6486180
3665932160 773195884 193821728
2655704544 2479239619 11045214
2970686930 195826300 21859186
1596257681 2345480344 116470381
2648218599 765709939 7485945
267433833 0 38915982
701913980 2301280038 4624639
2130796669 1543842466 272797567
57533669 1275520329 209900164
1756207753 3442698892 374588916
3859753888 2305904677 39575667
1134492758 2809419770 26839161
309521113 217685486 8494012
433983600 1485420493 20638459
1742846291 522451528 13361462
1161331919 2715695863 90552609
1251884528 967017612 308502717
3052622213 2490284833 95092799
454622059 2461950725 17288894
2472852656 535812990 24122952
318015125 649741464 115968475
2496975608 3367565847 75133045
553952700 3070057156 114674375
668627075 1959120081 31105212
2992546116 462375431 60076097
3147715012 299507329 20253631
2574890768 226179498 73327831
0 108174402 57533669
306349815 2806248472 3171298
2887367588 559935942 83319342
760862177 2836258931 233798225
1560387245 1990225293 29384256
3167968643 1816640033 140298355
2572108653 319760960 2782115
4260952033 4113795026 34015263
2849584074 1506058952 37783514
2403594236 38915982 69258420
706538619 2246956480 54323558
4113795026 4147810289 147157007
3308266998 2019609549 227346931
471910953 3817287808 82041747
699732287 1956938388 2181693
light-to-temperature map:
1642970452 2619648642 320925092
871949201 797630676 97655745
655931949 2008010966 216017252
3785141775 4061613243 12865567
4215077801 4197959319 79889495
2563411697 1252642831 573187176
1254390764 4601171 388579688
0 1980893220 27117746
3136598873 895286421 241010052
3798007342 3785141775 276471468
467378984 1136296473 116346358
62929167 393180859 404449817
583725342 2257865135 72206607
58327996 0 4601171
1220553847 2224028218 33836917
1065490634 1825830007 155063213
2157586756 2971783984 405824941
1963895544 2330071742 193691212
4197959319 4277848814 17118482
969604946 2523762954 95885688
27117746 2940573734 31210250
temperature-to-humidity map:
3204530368 2689103462 122673126
1097831066 741139709 15277662
2587190266 2506197062 28166734
2972900803 2149468273 231629565
2754733708 3879909767 93747273
1118529763 1007376005 639297716
591529103 1795771252 224967444
1113108728 305315251 5421035
2266839735 3973657040 65644628
3425464071 2534363796 64415445
2332484363 2811776588 254705903
3353763689 3525362348 71700382
411622859 756417371 179906244
2629634484 2381097838 125099224
0 1646673721 149097531
1912202739 439529310 384078
1828879869 221992381 83322870
1038488928 310736286 59342138
2149468273 3597062730 22900616
3731081879 3337447905 173636959
2172368889 2598779241 90324221
218548417 439913388 193074442
3489879516 4053764933 212174931
3327203494 3090464996 12096930
149097531 370078424 69450886
2615357000 3511084864 14277484
4064227942 3102561926 230739354
3702054447 4265939864 29027432
838437176 21940629 200051752
3339300424 4039301668 14463265
2262693110 3333301280 4146625
3904718838 3619963346 159509104
2948918298 3066482491 23982505
1757827479 936323615 71052390
1912586817 632987830 108151879
2848480981 3779472450 100437317
816496547 0 21940629
humidity-to-location map:
3394148556 2925849667 56813934
4223178672 3844939961 29088809
3743018622 3753904164 91035797
6295169 0 111018407
3175071902 3531111280 47991613
4252267481 2883149852 42699815
129982843 693964199 99494334
229477177 272742930 300412252
798562242 793458533 315959887
1114522129 680103472 13860727
3223063515 3050521430 171085041
1574260097 2117833331 253788822
691613952 573155182 106948290
2250567596 1223353243 43558595
2851928754 4027938301 267028995
3887810914 1266911838 1671681
3725220028 3431759743 17798594
1828048919 3449558337 77343652
2479857123 3329899124 101860619
3889482595 3526901989 4209291
3604872021 2982663601 7751828
3834054419 2371622153 53756495
1905392571 2537974827 345175025
2581717742 1324697672 270211012
1145914964 1689488198 428345133
2294126191 3221606471 108292653
3612623849 2425378648 112596179
117313576 1109418420 12669267
4163072671 2990415429 60106001
3893691886 1594908684 94579514
0 1122087687 6295169
3450962490 3874028770 153909531
2402418844 1145914964 77438279
3988271400 3579102893 174801271
3118957749 1268583519 56114153
529889429 111018407 161724523
"""
solution05_1 = fn input ->
lines = input |> String.split("\n", trim: true)
maps =
[
"seed-to-soil map:",
"soil-to-fertilizer map:",
"fertilizer-to-water map:",
"water-to-light map:",
"light-to-temperature map:",
"temperature-to-humidity map:",
"humidity-to-location map:"
]
|> Enum.map(fn s -> lines |> Enum.find_index(&(&1 == s)) end)
|> then(&(&1 ++ [lines |> Enum.count()]))
|> Enum.chunk_every(2, 1, :discard)
|> Enum.map(fn [first, last] ->
lines
|> Enum.drop(first + 1)
|> Enum.take(last - first - 1)
|> Enum.map(fn line ->
Regex.scan(~r/\d+/, line) |> Enum.map(fn [s] -> String.to_integer(s) end)
end)
end)
Regex.scan(~r/\d+/, lines |> List.first())
|> Enum.map(fn [s] -> String.to_integer(s) end)
|> Enum.map(fn seed ->
maps
|> Enum.reduce(seed, fn map, key ->
map
|> Enum.find(fn [_d, s, l] ->
key >= s and key < s + l
end)
|> case do
[d, s, _l] -> d + (key - s)
nil -> key
end
end)
end)
|> Enum.min()
end
solution05_1.(sample05_1)
solution05_1.(input05_1)
Day 5 - Part 2
sample05_2 = sample05_1
input05_2 = input05_1
solution05_2 = fn input ->
lines = input |> String.split("\n", trim: true)
maps =
[
"seed-to-soil map:",
"soil-to-fertilizer map:",
"fertilizer-to-water map:",
"water-to-light map:",
"light-to-temperature map:",
"temperature-to-humidity map:",
"humidity-to-location map:"
]
|> Enum.map(fn s -> lines |> Enum.find_index(&(&1 == s)) end)
|> then(&(&1 ++ [lines |> Enum.count()]))
|> Enum.chunk_every(2, 1, :discard)
|> Enum.map(fn [first, last] ->
lines
|> Enum.drop(first + 1)
|> Enum.take(last - first - 1)
|> Enum.map(fn line ->
[d, s, l] = Regex.scan(~r/\d+/, line) |> Enum.map(fn [s] -> String.to_integer(s) end)
{s, s + l, d - s}
end)
|> Enum.sort_by(fn {_, s, _} -> s end)
end)
Regex.scan(~r/\d+/, lines |> List.first())
|> Enum.map(fn [s] -> String.to_integer(s) end)
|> Enum.chunk_every(2, 2, :discard)
|> Enum.map(fn [first, length] -> {first, first + length} end)
|> Enum.flat_map(fn seed ->
maps
|> Enum.reduce([seed], fn map, ranges ->
ranges
|> Enum.flat_map(fn {rf, rl} = _range ->
map
|> Enum.reduce({rf, []}, fn {sf, sl, offset}, {acc_f, acc_d} ->
interval =
if acc_f < sf and sf <= rl do
[{acc_f, sf, 0}]
else
[]
end
f = max(sf, acc_f)
l = min(sl, rl)
{acc_f, overlapped} =
if f < l do
{l, [{f, l, offset}]}
else
{acc_f, []}
end
{acc_f, acc_d ++ interval ++ overlapped}
end)
|> elem(1)
|> then(fn
[] ->
[{rf, rl, 0}]
list ->
{f, _, _} = list |> List.first()
before_list =
if rf < f do
[{rf, f, 0}]
else
[]
end
{_, l, _} = list |> List.last()
after_list =
if l < rl do
[{l, rl, 0}]
else
[]
end
before_list ++ list ++ after_list
end)
|> Enum.map(fn {f, l, offset} -> {f + offset, l + offset} end)
end)
end)
end)
|> Enum.min()
|> elem(0)
end
solution05_2.(sample05_2)
solution05_2.(input05_2)
Day 6 - Part 1
sample06_1 = """
Time: 7 15 30
Distance: 9 40 200
"""
input06_1 = """
Time: 45 98 83 73
Distance: 295 1734 1278 1210
"""
solution06_1 = fn input ->
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
line
|> String.split(":")
|> List.last()
|> then(fn line -> Regex.scan(~r/\d+/, line) end)
|> Enum.map(fn [s] -> s |> String.to_integer() end)
end)
|> Enum.zip()
|> Enum.map(fn {time, distance} ->
0..time
|> Enum.filter(fn speed ->
speed * (time - speed) > distance
end)
|> Enum.count()
end)
|> Enum.reduce(1, &Kernel.*/2)
end
solution06_1.(sample06_1)
solution06_1.(input06_1)
sample06_2 = sample06_1
input06_2 = input06_1
solution06_2 = fn input ->
[time, distance] =
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
line
|> String.split(":")
|> List.last()
|> then(fn line -> Regex.scan(~r/\d+/, line) end)
|> List.flatten()
|> Enum.join()
|> String.to_integer()
end)
win? = fn t -> t * (time - t) > distance end
find_boundary = fn {a, b}, find_boundary ->
if a + 1 == b do
{a, b}
else
half = div(a + b, 2)
if win?.(half) == win?.(b) do
find_boundary.({a, half}, find_boundary)
else
find_boundary.({half, b}, find_boundary)
end
end
end
{_, min} = find_boundary.({0, div(time, 2)}, find_boundary)
{max, _} = find_boundary.({div(time, 2), time}, find_boundary)
max - min + 1
end
solution06_2.(sample06_2)
solution06_2.(input06_2)
Day 7 - Part 1
sample07_1 = """
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
"""
input07_1 = """
94J8A 16
JK59A 722
Q5QQQ 681
T99T2 39
595JQ 533
98299 550
T596T 971
JQ999 831
J3K39 340
K93T5 107
2999T 750
KQ4K4 603
TT6TT 778
QAQJQ 731
K2444 109
T87J4 984
72272 70
555QJ 266
44384 872
67768 140
555A9 322
Q9A52 14
6JTTT 994
66J7Q 360
6J966 170
74335 288
Q7QK7 318
T63K8 355
88Q38 612
TKKKK 291
8T295 608
77A77 312
3ATTA 861
6JJ66 866
82367 229
J86TQ 457
AJAAA 521
JTTTT 380
555K5 223
4Q688 398
84K8Q 302
TQ478 514
A2229 604
69JA4 536
T5555 815
6877T 287
4333J 617
74Q23 688
A5T5J 21
TT884 945
98J32 22
K7JK7 464
55466 484
J8A78 175
4A586 307
326T9 834
J7883 678
J9TJ2 798
49999 366
2KK9J 436
T7A5K 35
K8A23 172
4TA36 445
33T3T 843
8QA86 397
43QQQ 523
72J99 364
JAATT 9
KTTTT 620
92JT9 389
25552 825
23A58 676
TJ4K6 167
T55J8 636
Q75J5 433
47387 121
TTK33 226
K5786 532
Q88AJ 767
T6725 975
76776 108
KQKK5 753
9T699 73
56AJA 89
KTKK9 947
JQQQJ 998
7Q8J7 600
2A42A 605
Q2K74 566
TATAA 134
227K7 712
K5K7Q 139
4844A 233
44AQA 91
AA888 885
872JK 734
32329 764
5KA54 475
28888 62
K9K88 463
A4AAA 565
9JJ49 117
2685Q 210
KT2T2 594
9TK8T 690
625J8 607
AQQQ9 571
56A6A 916
A4AJ7 935
9J68A 967
5T899 479
T5836 853
88443 404
K5K5K 77
66A65 501
3A3J7 127
66K68 336
KQAKA 391
864QQ 153
Q97QQ 224
74T63 52
6T555 981
4444A 543
8J558 111
5656J 810
89484 439
9A7K3 444
3Q443 306
ATAAA 253
7T934 33
K9582 645
66K26 344
9A9AA 535
J8KQ2 695
AA2AA 491
78777 891
AAQ9A 12
AQJ93 490
KKAKK 913
333TJ 643
Q96J6 826
66767 937
88757 769
584Q6 334
TA29T 162
K33K9 506
T5A5A 836
333Q3 152
6T7KA 31
T6834 572
2TTTJ 959
6AA6A 95
Q4A3A 216
QQ3JJ 471
AT4TT 817
49628 400
388A4 144
TJ75T 86
JQ4Q2 250
8T8JQ 835
TJTT8 56
8T4K9 705
A9JTA 81
36646 420
5KKK2 345
QA965 823
J34K4 85
82288 797
829Q5 488
A699J 399
6642J 1000
K9KK6 267
5JA5A 17
K6TJT 884
7A667 869
KQATT 929
88884 468
K495T 141
6573A 827
KK354 979
JTTT5 335
T5398 182
AAJ9A 157
JQ935 897
J999J 251
T6T5T 702
5TAAA 381
TJT22 960
AJQ57 883
99T9J 234
KKKKJ 495
9K99K 961
QQ777 589
337J2 652
9T269 813
22Q8J 165
98659 847
32TT2 542
2273Q 718
39399 455
9KKQ3 856
64T4T 795
777T8 694
22AJ2 274
69966 706
7K533 860
2TQK9 756
T225T 246
2KK8J 664
QJQ6Q 540
5TTT7 625
799K5 740
KKK2K 6
553J3 431
QAQAQ 454
777JT 970
72492 955
7777T 18
3KA94 496
3J3J3 707
7JJ4Q 746
36463 780
7A42K 545
KTAJA 203
45443 761
95A5J 8
58833 438
66Q23 814
466KK 576
2TT2T 113
426KQ 595
72J49 69
QJKQK 757
J5J5K 667
5522Q 132
QTQ9T 494
T2222 450
3242J 717
66766 968
984J8 372
986QK 739
242TT 902
K46KK 659
3TA5J 644
QA92K 901
QQQ59 933
QJ666 504
JQ2Q8 461
94J49 42
78888 850
T64QT 812
QQQ25 918
855AJ 316
88J28 528
78Q46 672
29999 44
9K96K 13
2KAKK 204
QAQAJ 806
AKKKA 79
22KJ2 27
J89Q6 294
T66JT 640
4J4Q9 208
6Q54Q 297
88777 737
J825A 537
K4K44 498
QQQTQ 493
4J749 434
5Q868 324
99437 243
J9829 425
J2222 720
T5372 37
447TT 437
26292 145
86866 361
Q6T32 771
KKKA7 553
774K7 958
2KJ2K 375
8T34K 60
KTK9T 164
36333 547
55Q55 191
8K37A 123
8945J 704
AA75K 71
TTTT3 280
Q2Q4Q 977
J3936 259
55877 725
4424A 409
97799 46
43422 174
33443 269
AAQ3K 873
69699 395
T8942 824
JT993 105
T44T4 319
9863K 190
A9236 953
2K62K 931
A7TKA 559
32323 41
T2T22 422
2QQ2Q 279
QT3QJ 519
6Q4K5 573
3JA93 7
KJ777 275
A7JTQ 930
AA8Q7 531
2QQ6A 219
6JA9A 136
Q2369 530
99998 830
5788K 218
AQQQQ 683
K33K3 879
K83A9 949
K9J99 356
25J22 657
53AJ7 782
99QQQ 412
63969 821
23455 489
2JAA3 3
77TTT 631
6975A 367
44K7Q 520
J3Q3K 310
AA4AJ 660
5A3A6 833
Q7Q7Q 755
9TQ44 424
878A8 515
T8TTT 323
7TKT7 209
KTTJ5 563
2KQQ3 469
2T45J 808
25AA5 293
6K76J 255
2J53T 807
899J9 507
48448 805
JQ272 849
T9999 794
J2282 992
66588 691
3T273 137
T78T3 453
TA2J6 221
J4J77 647
77762 940
6TKT4 551
48478 941
9K49K 295
4T844 516
5524J 460
4KJ2K 788
2J22J 330
Q5JAQ 87
T3338 168
42JT4 235
77333 646
8JTT6 878
48444 315
TT888 429
48774 385
25732 650
AAA96 684
55J55 103
444Q4 196
77J37 342
765T8 747
TKKJT 4
45842 122
9T3KJ 889
458QA 184
JQQQQ 982
5T492 282
25QJ2 228
Q28TA 899
6T34T 286
A4AA9 579
74444 10
K52K2 689
6K663 343
996J6 875
222QQ 245
73JJT 742
4K466 502
59Q99 5
K43JK 300
2922K 900
AAA3A 938
T5TTT 996
Q7797 560
35767 321
89998 964
TAJ78 539
5552T 254
4J848 675
22932 762
66J44 283
6T66K 371
965J6 415
45TK5 48
4AJT2 943
2232J 687
9KTA3 373
TT44T 602
2975A 596
6683J 862
6TJ54 193
TT3QT 582
3TT3J 567
9585J 554
8A5T8 72
Q8888 124
Q84JK 272
8K882 115
454T3 449
46886 239
63633 692
Q2KQK 622
662AA 714
TQTJ8 858
39699 829
TKT8K 379
8JKTT 854
99Q9Q 264
K52J2 828
QQ223 632
833QT 188
74778 393
3J33A 347
JQAAA 575
4975T 189
AA8AA 98
88588 474
KKKJ5 58
77757 249
6J666 2
88Q8Q 895
KT4T3 924
7A757 20
852A5 838
92479 818
45J55 556
777J7 443
622TT 907
A55J4 236
J94T7 194
TK239 887
T2359 892
3T67K 730
9595Q 480
362J2 912
J33K5 915
999TQ 735
6J555 383
35555 261
7J374 403
77776 200
46226 908
A5A55 627
6466K 999
33433 789
4QQJQ 635
K857T 326
46844 611
55K4J 247
9TTTT 411
K5999 270
3333J 598
9TT9T 615
TKT88 653
7AQJK 629
7A294 863
9JQ4J 427
K7K7K 738
55338 304
55659 120
AA22Q 768
KKK88 886
K7K4A 983
9T449 715
6AA55 956
66556 777
Q4K36 736
78Q77 207
8J778 917
4AJQT 435
9KJQQ 716
422JK 406
62A9J 205
25A25 11
K8888 985
KTTKK 19
76KQT 877
5A555 217
97933 995
4K4KT 135
QQ4J4 546
TATA6 946
KAJ2A 837
8333J 238
47666 376
Q5QA5 839
8Q64T 951
QA23Q 240
T6T7T 972
648T7 92
6T33T 271
25528 948
JAAJA 50
45455 578
AA8J4 588
A6QT2 867
2T392 765
32Q3Q 950
KA8KT 816
59J28 973
883A2 237
J555J 864
62222 325
Q543T 637
338TJ 290
T58J6 198
5QAJ8 583
T4K6Q 476
K3333 888
24443 421
29629 776
J88J7 116
66K33 119
JA7A7 214
J3353 920
45442 616
7Q36T 963
A22JK 719
QAJA6 791
55J44 65
3TQ79 351
8JKK8 642
79999 292
974JK 94
JJJJ8 151
K7JA5 903
JKK4J 932
66755 405
AJ647 146
Q2T29 202
JA6A2 591
55635 374
J6J53 896
75575 621
TTQTJ 852
74Q33 989
9357J 555
T75J5 801
J6KT5 974
T6667 910
3KA6A 597
3TTT3 505
Q2442 423
977Q3 624
28622 442
33338 670
K3KK3 677
7Q995 296
747J4 88
8KKKA 128
6AQJ5 130
7K362 171
4KT35 353
A94A9 561
TT7JQ 388
886A8 441
899Q5 15
AKAAA 529
J6T9T 447
5TQ29 811
TTTAQ 685
56556 359
JKK38 698
75QQJ 440
9TK8J 786
6Q442 54
5KK75 320
47QTQ 623
Q496Q 257
97TTJ 260
A96K2 61
959A5 783
5T55K 256
JJJJ9 570
724T2 197
A4JA2 574
22J29 201
929J3 759
888T6 585
662JK 212
KQ53K 954
99J99 472
424J2 587
566KJ 149
K693T 609
44794 751
7A3TQ 728
5J2J8 666
AAK99 365
KQ378 481
57Q29 865
797AA 842
AAA33 180
5AK55 820
KK5AK 299
77773 378
8K899 944
44994 976
A6AJ6 96
53533 354
45JK4 154
99399 176
22424 518
7AAKK 377
J4KA5 772
Q3QQ8 179
585T5 881
59969 928
2K2K3 710
ATKTA 499
56466 34
44242 308
7J275 741
588T6 317
QKA79 369
JA546 1
4T447 927
A33A3 641
T7T77 301
36366 185
399A7 51
AJ33J 743
T7J7T 59
6KJ7J 426
5J586 32
K8KKK 654
K62K9 341
824K7 133
6AJAA 29
63AJA 993
4K44T 401
67A92 697
A5592 845
AK578 30
QT4TQ 894
3373J 456
35TT3 500
45A48 803
44454 222
54445 628
A6696 527
88AA7 211
344AA 68
6J3TK 248
7557J 701
45T98 394
49TTT 868
448J4 93
A45TQ 682
2A2AA 599
77Q77 78
88585 339
J3QQ3 726
74JK7 980
9454T 327
TTT7T 534
TJK95 370
T2T79 314
2A333 822
J9765 562
9T6T9 36
J2J35 313
789QQ 396
KJ3Q4 362
J5999 166
TQKT3 90
J6T53 413
99655 186
J455T 305
K95A5 601
37377 749
JTKAT 252
J8275 508
QK296 766
AJKK6 610
TTAAT 926
T5T4T 939
QQ8Q8 195
28J2J 593
KKK9K 703
5T5TT 905
88988 101
697JJ 538
6266T 510
2878T 333
T8J26 773
83773 763
T9J33 384
2AK92 656
22JJ3 169
K2T9T 649
QQ8QQ 428
QKJKK 770
T64A5 410
6T7T2 748
T3J55 890
55557 74
AAJ7A 467
22K22 155
TK27J 988
9T64A 309
77AAA 804
QQQ7Q 503
78837 138
6A785 792
6Q4QQ 76
8AT69 721
TKKKJ 680
73555 407
4Q999 114
45K55 242
J4742 390
AA8A8 626
47T3T 898
TA9J8 231
9T9A9 809
4K799 619
8K99K 727
J7KJK 338
AQ4K9 485
QQ2QQ 129
7T45A 473
2T7T2 785
7J749 84
AJ7Q7 733
386AJ 911
59A68 104
335K6 723
KK979 289
898QA 466
9TTKT 648
66933 512
Q7A77 686
24QQT 564
2J2T4 150
JK4K4 386
AAJAK 544
727TJ 526
QJT2T 183
96A6T 244
979T9 876
2239Q 465
8K69J 613
57J54 258
J843J 760
JK333 99
K2K8T 477
T9983 75
A222A 298
22523 800
9999K 840
Q2KA8 511
TTATT 368
83584 793
66966 787
79949 158
73722 711
A36T6 987
Q976J 541
Q4J78 311
AQJJ3 225
888J6 893
QJT44 922
JAJKA 263
5QQ7Q 962
27277 581
JKKJK 358
88877 923
4K3T4 45
A8495 577
A89J5 446
6A355 952
8AA8J 633
32KJ2 163
48282 497
44JJ4 874
KJ93A 674
24444 848
888J8 118
99JA8 181
58J57 66
QKQKQ 143
99JQK 125
84KJ7 178
J95KK 241
6666T 284
K9555 106
7KQKK 513
5Q4QQ 213
88KK8 665
7272J 100
97Q34 492
8569K 262
222KK 925
23J4A 55
9868A 331
2222Q 758
2J553 754
7727A 25
K3QKQ 673
9J292 796
45K44 363
888JK 639
8K43A 851
AQ6J2 517
K4K4K 352
2K224 802
2T44A 934
595J5 63
5Q6QQ 126
QA59J 432
5A55J 357
J738A 80
K666K 278
9QQ6A 978
93242 614
7KK77 661
JA9KK 855
33T53 634
6T2AK 882
2K64T 586
5AT68 584
Q36A7 846
22228 382
444J4 402
27AA7 24
KKAJA 230
8JA5T 663
A2828 131
7AAAQ 914
3345K 997
275TQ 606
9KJ58 569
JTTT7 416
993J9 408
84J55 28
KTKK2 784
98K24 206
J5KJK 841
33944 651
6K7KA 392
T2T92 346
33323 187
JQT59 729
TT2TT 590
2A67K 790
QKAQJ 159
T3TQJ 303
QQ227 478
J2852 708
83834 458
67Q6T 524
26262 552
T4J45 452
2Q5T6 966
QKKT6 160
KQK9Q 273
8Q333 192
4656A 557
64444 83
59434 781
357KK 558
T4QJJ 655
3625T 142
29992 752
A7AAA 220
24KKK 448
J89Q8 40
9569A 328
K7TK7 921
5T777 859
7474T 699
39A7J 49
9QTJQ 880
Q844Q 819
JJKKJ 112
8Q88J 177
K3T89 779
Q365Q 277
8488A 522
J3A3K 199
5AAA5 147
96586 568
88Q48 709
Q85Q8 414
37QAQ 102
K33K2 281
7676J 387
26666 348
AA868 744
9K9TT 658
22233 942
6Q6K8 745
A4AA7 459
66J76 110
J282T 173
23A24 732
KK7K2 580
43344 509
54Q8T 906
96967 57
525J8 417
628Q7 919
2775T 487
A5T67 337
7T887 662
K944K 470
289AJ 592
A6AAA 97
52Q49 482
7AK7J 904
688JJ 462
6Q335 724
23342 47
5KKKK 276
62665 548
4KJ63 67
TTA6Q 332
AQ5AQ 156
J33JJ 232
J88J8 483
JT5A9 936
62ATA 549
J6T33 486
6Q46Q 679
27J2T 693
2A9QT 775
KJ524 638
93JQ2 969
7JJ77 991
55552 53
88868 148
3TJT4 349
7QJ77 990
77797 957
JJ464 350
J68K8 82
2522A 451
49AA4 329
AAQQA 23
J4K44 870
57J55 700
3AA64 832
746JK 525
25522 986
TK333 38
Q44QQ 268
Q3KA3 857
55T57 844
9K57Q 430
KKAA8 671
6J546 669
9K779 909
588J8 630
26266 668
J6999 26
AATAQ 227
7994T 871
47466 419
A4929 713
QKKKK 618
T9Q83 265
55595 799
JJJJJ 64
29A84 696
5AAAA 285
5T6KQ 215
42447 161
33337 418
JJTTT 774
88388 965
22J75 43
"""
solution07_1 = fn input ->
calc_type = fn hand ->
hand
|> Enum.frequencies()
|> Map.values()
|> Enum.sort()
|> Enum.reverse()
|> case do
[5] -> 6
[4, 1] -> 5
[3, 2] -> 4
[3, 1, 1] -> 3
[2, 2, 1] -> 2
[2, 1, 1, 1] -> 1
[1, 1, 1, 1, 1] -> 0
end
end
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
[hand, bid] = line |> String.split(" ")
hand =
hand
|> String.to_charlist()
|> Enum.map(fn c ->
case c do
c when c >= ?2 and c <= ?9 -> c - ?0
?A -> 14
?K -> 13
?Q -> 12
?J -> 11
?T -> 10
end
end)
type = calc_type.(hand)
bid = bid |> String.to_integer()
{type, hand, bid}
end)
|> Enum.sort(fn {lt, lh, _}, {rt, rh, _} -> lt < rt || (lt == rt and lh < rh) end)
|> Enum.with_index(1)
|> Enum.map(fn {{_, _, bid}, rank} -> bid * rank end)
|> Enum.sum()
end
solution07_1.(sample07_1)
solution07_1.(input07_1)
Day 7 - Part 2
sample07_2 = sample07_1
input07_2 = input07_1
solution07_2 = fn input ->
joker_number = 1
calc_type = fn hand ->
jokers = hand |> Enum.count(fn c -> c == joker_number end)
except_joker = hand |> Enum.filter(fn c -> c != joker_number end)
except_joker
|> Enum.frequencies()
|> Map.values()
|> Enum.sort()
|> Enum.reverse()
|> then(fn
[] ->
[jokers]
[h | t] ->
[h + jokers | t]
end)
|> case do
[5] -> 6
[4, 1] -> 5
[3, 2] -> 4
[3, 1, 1] -> 3
[2, 2, 1] -> 2
[2, 1, 1, 1] -> 1
[1, 1, 1, 1, 1] -> 0
end
end
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
[hand, bid] = line |> String.split(" ")
hand =
hand
|> String.to_charlist()
|> Enum.map(fn c ->
case c do
c when c >= ?2 and c <= ?9 -> c - ?0
?A -> 14
?K -> 13
?Q -> 12
?T -> 10
?J -> joker_number
end
end)
type = calc_type.(hand)
bid = bid |> String.to_integer()
{type, hand, bid}
end)
|> Enum.sort(fn {lt, lh, _}, {rt, rh, _} -> lt < rt || (lt == rt and lh < rh) end)
|> Enum.with_index(1)
|> Enum.map(fn {{_, _, bid}, rank} -> bid * rank end)
|> Enum.sum()
end
solution07_2.(sample07_2)
solution07_2.(input07_2)
Day 8 - Part 1
sample81_1 = """
RL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)
"""
sample81_2 = """
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)
"""
input08_1 = """
LRLLRRRLRRLRRRLRLRRLLRRLRRLRRLRRRLLRRLRRLLLRRLLRRRLRRRLRRRLRLRRRLRRRLRLRLRRLRLRRRLRLRLRRRLLRRRLRLRRLLLRRRLLRRLLLRRRLRRLLRLRLRRRLRRLLRRLRRRLRRRLLRRRLLRRRLRRLRRLRLRRRLLLRRRLRRRLRLRRLRRLRRLRRLRRLRRRLRRRLRRLLRRLRRRLRLLRLLRRLLRRLRRRLRRRLRRRLRRRLRRLRRRLLRRLRRRLRRLRRRLRRLRRLRRLRRLRRLRLRRRR
QRX = (XNN, TCJ)
GSM = (PNH, BVG)
VDX = (VSG, ZZZ)
TGV = (SHD, FVB)
PPH = (MLX, CBT)
GRP = (FGH, VLK)
NCT = (TRH, GJX)
TLD = (QHH, RXL)
XMB = (XXT, XSF)
HQP = (GMB, JGX)
NTH = (BRV, GKL)
RHM = (HJH, BGS)
DPC = (VRX, XTK)
SBD = (GBD, CCG)
NBB = (CGT, DHB)
GXR = (PPM, PSD)
FNR = (KNV, STN)
FRM = (SBD, LPJ)
JMB = (SPN, VPX)
RMJ = (CBT, MLX)
XXD = (HPP, TML)
LJQ = (LTQ, HKH)
LJP = (SSL, SSL)
CFM = (TMR, SJX)
MLX = (TLV, BTH)
LLJ = (SPB, JPL)
VRX = (VLJ, MFX)
XHM = (GSJ, SMV)
CDQ = (MSF, BKM)
LJT = (VMB, XND)
DNF = (QVQ, TTG)
BLB = (VGV, FJC)
FXK = (HBS, DTS)
VDT = (PGC, GSB)
GFS = (QXK, GFC)
LGT = (LVX, LKD)
XRJ = (RXB, XXR)
GRT = (RFK, TMX)
HLK = (QBQ, HPH)
SCK = (LBL, XXD)
LMR = (TLD, RJD)
BRP = (XNX, MXV)
CVV = (NRD, JRP)
VPH = (BRV, GKL)
XSD = (NQC, QNV)
BPT = (QPQ, PJJ)
SQG = (GPB, RQG)
SXL = (VTV, HXR)
FMG = (DVX, DGL)
JQF = (LTJ, LTJ)
HHC = (BPC, VBM)
TFJ = (DLL, KRC)
QTM = (XDK, HXS)
HBV = (GHX, CSL)
HXS = (PJS, JNQ)
TTG = (JGQ, NHL)
FQN = (LDJ, KSP)
NND = (CFK, TCL)
DGP = (NGP, XMP)
FSN = (QKR, HFM)
FDG = (SRF, PBL)
PFN = (LRX, CLT)
VSX = (TCV, SPP)
GRB = (CVR, SJM)
JXP = (JRJ, SCX)
DTF = (BGR, DRD)
JPL = (DFQ, LVC)
HKJ = (RKH, BKZ)
TRQ = (PMT, PMT)
KTG = (TVL, HRP)
LFM = (PSG, FXX)
FHK = (FHT, NVG)
FTD = (QFB, GHT)
SKX = (NGD, LDC)
XTB = (GMB, JGX)
CQK = (TVL, HRP)
NRD = (GDF, SCN)
GBD = (SFQ, VLX)
GTP = (SNQ, MDX)
PDT = (JVS, XSK)
QRJ = (GFS, NSS)
SXD = (JDV, THC)
TCR = (NPR, BGX)
DGL = (LPL, HGH)
SHQ = (JSB, FMG)
BKZ = (VBJ, RFJ)
LVX = (BQV, QGT)
SRH = (PGC, GSB)
KJR = (FQX, DCN)
PGV = (JVB, BDB)
BVG = (LFM, CSX)
KDJ = (BMV, LLS)
JNX = (DSF, CDL)
QGT = (TKL, TQX)
PKK = (VDM, VND)
DHS = (TGG, XCD)
LKD = (QGT, BQV)
HGH = (JQF, RXQ)
GCK = (SHQ, RGG)
JCQ = (HNF, NMR)
XMT = (TRK, KPK)
CJC = (HKV, HKV)
XFM = (QBQ, HPH)
BRQ = (LKT, SCK)
VSG = (XHV, KDJ)
GSJ = (BDR, JNC)
CXJ = (TSD, BGM)
RJX = (PKH, SQB)
HMN = (DJF, RRR)
TKL = (GXV, SQG)
QVJ = (FKN, XPL)
CLT = (TLR, CGG)
HPP = (NXB, KPC)
RGG = (JSB, FMG)
VQC = (LPJ, SBD)
FQL = (PJJ, QPQ)
QKR = (KJR, HMS)
RFK = (PKN, KLG)
QDH = (HRG, HRG)
KKG = (LHV, PCM)
PBF = (NDM, XXM)
XVG = (NDM, XXM)
BGX = (HMN, RLL)
DKL = (XXR, RXB)
MFK = (CJM, GSM)
JLP = (CKC, VKB)
TSD = (TCR, BBD)
KLG = (CQK, KTG)
XCD = (NQG, CDF)
HXR = (JXH, BTG)
FQH = (PQL, MBC)
HBS = (TXL, LCP)
DCV = (TFJ, JDN)
QDK = (PCV, MBQ)
LDJ = (QDK, XHH)
HHB = (NXX, BNL)
SCH = (MDJ, HDC)
BBJ = (MDN, HTD)
BGL = (QVJ, KLR)
VBF = (MTQ, LPH)
CQG = (VLK, FGH)
PQH = (JRN, JPB)
VGV = (HHR, LFH)
CRK = (XFQ, GCK)
VVX = (RKX, VBF)
GDF = (FHF, BJP)
LHF = (MSF, BKM)
MBQ = (VMX, RCD)
JRJ = (NMC, RRN)
CFD = (NVQ, RJX)
MPB = (MPD, VNN)
JPQ = (SJB, CFM)
NCB = (KLR, QVJ)
CVR = (PDT, VNP)
QGF = (JKG, BBS)
KCG = (FSN, KJZ)
DRD = (QXX, JSG)
TCV = (SRH, VDT)
QRM = (KKG, TFR)
GNX = (KDG, PNT)
KBM = (LJQ, RNN)
GDT = (QSG, DGN)
HJH = (VVX, LXP)
GSB = (MKQ, GRF)
CVG = (PLD, CXJ)
QJK = (DNX, DBM)
DDX = (XVG, PBF)
DBM = (XSD, TJF)
NGP = (GJM, VFJ)
FFF = (RQX, BSG)
VXH = (BNL, NXX)
GTQ = (PCL, NBK)
NDM = (XPK, RTX)
BPC = (KCM, FTD)
GVJ = (CMS, HTJ)
TML = (NXB, KPC)
SPB = (DFQ, LVC)
SMV = (JNC, BDR)
PBG = (KGB, JRC)
JGF = (HHC, LXT)
VXF = (GVQ, BXG)
PRL = (XKB, XDL)
TXL = (QTM, MPN)
FHP = (JVB, BDB)
FXX = (PGV, FHP)
QPD = (XFQ, GCK)
PKH = (VSX, MCT)
VLX = (GBR, MBR)
MXV = (LJT, DKB)
QPQ = (FTM, XGT)
PMB = (QRJ, SGV)
DJF = (CQR, CRB)
MRV = (RHM, HGD)
SBT = (GRB, NSJ)
PRT = (QPS, KSG)
HMS = (FQX, DCN)
QFF = (XMT, TDJ)
KVB = (CMS, HTJ)
GJM = (MHV, GDT)
BRX = (MXN, DRG)
CFL = (DNX, DBM)
VGA = (QGF, MRL)
GFQ = (RLF, MBT)
LVJ = (MLL, RDP)
QSM = (PFN, LND)
KQX = (XLH, FNM)
XVB = (GLL, NNP)
JRN = (FPP, QTD)
NMR = (PKM, XMG)
PPM = (CJJ, JPQ)
QLF = (CJC, XMX)
CGJ = (KBG, BRP)
QPT = (MTM, VMQ)
FMV = (BRP, KBG)
GHP = (BGF, TDF)
TPL = (KKV, JHV)
KLR = (FKN, XPL)
KSP = (QDK, XHH)
JVB = (TDC, JLG)
BMV = (XJR, KMK)
VRH = (GTQ, QCS)
KLT = (KQK, VRH)
PLM = (HXG, XRS)
DVX = (LPL, HGH)
LPG = (FMV, CGJ)
XHH = (MBQ, PCV)
LHJ = (MHD, FFF)
FGH = (DVT, NTJ)
BRJ = (PXV, FXK)
DTL = (VBV, FDG)
JDV = (KGL, MFB)
TDC = (PNM, QLF)
PSG = (FHP, PGV)
VMQ = (DBR, BBJ)
CCK = (SKN, NNQ)
GGM = (KKV, JHV)
VXG = (GTP, TMK)
CFK = (QRX, XNV)
BBS = (LVJ, QTB)
XND = (CDQ, LHF)
PKR = (DTX, STT)
LXP = (RKX, VBF)
JBN = (SSL, DRH)
HTD = (BGL, NCB)
BXG = (JMB, NXS)
NQG = (XGF, GHQ)
DHL = (BMK, LST)
JGT = (LKD, LVX)
VLJ = (HBV, FQM)
THB = (RHR, PBG)
NLQ = (XQN, VSC)
MTQ = (VMJ, CRS)
SCT = (MRK, CFD)
MFX = (HBV, FQM)
BGM = (BBD, TCR)
CJJ = (SJB, CFM)
FTM = (XCT, JFV)
VVV = (MFT, NLQ)
DSF = (FQN, PJR)
DTS = (TXL, LCP)
JHM = (RLF, MBT)
NJD = (VTV, HXR)
KPC = (RPS, KBB)
QVQ = (NHL, JGQ)
PSD = (JPQ, CJJ)
LJF = (MFK, LQQ)
LMS = (CGT, DHB)
QTB = (MLL, RDP)
NSS = (QXK, GFC)
CDL = (FQN, PJR)
BMK = (TGD, FFS)
RCR = (JXG, QPT)
XDQ = (QRJ, SGV)
RXF = (SGK, NLK)
PKM = (LSH, JNX)
MFB = (XTB, HQP)
VKB = (LCR, GXR)
HNQ = (THC, JDV)
TCJ = (PDF, KVM)
BPP = (PTN, GJB)
XNN = (KVM, PDF)
TVT = (TJB, CPN)
CRS = (LPP, GRT)
BGS = (VVX, LXP)
TGG = (NQG, CDF)
SPN = (LMS, NBB)
FKN = (QKT, TNS)
XVF = (LHM, JFN)
PDF = (XJP, XPM)
CQR = (GHG, JRG)
NDF = (BHX, KHM)
KQP = (MRK, CFD)
MGP = (KHM, BHX)
TBR = (NGK, GQC)
PCL = (JPV, MMH)
HXG = (QFF, DPJ)
FRN = (TTG, QVQ)
NLG = (MHD, FFF)
GLD = (LJP, JBN)
RCD = (CFJ, PST)
BQV = (TKL, TQX)
SJX = (NFB, XCN)
DGQ = (FMV, CGJ)
XPM = (NFM, VVM)
BBN = (KKG, TFR)
MRX = (CBM, FBS)
VBJ = (GTL, NCT)
QMJ = (DTX, STT)
BFD = (BMR, CNH)
VVM = (PKR, QMJ)
VNP = (XSK, JVS)
HKP = (BRX, BBQ)
TMK = (SNQ, MDX)
GNV = (PFN, LND)
NQC = (SXL, NJD)
NGD = (DGR, BLX)
MPN = (XDK, HXS)
MCT = (TCV, SPP)
XPL = (QKT, TNS)
HQV = (XHT, DCC)
NSJ = (CVR, SJM)
XHV = (LLS, BMV)
HMF = (RNN, LJQ)
TDF = (HMF, KBM)
MHV = (DGN, QSG)
JXG = (MTM, VMQ)
DTX = (CRK, QPD)
RQD = (NQD, TNQ)
RFJ = (GTL, NCT)
CGH = (FHT, NVG)
RJD = (QHH, RXL)
PCV = (VMX, RCD)
LPH = (VMJ, CRS)
QTN = (VNN, MPD)
DFQ = (VRT, SPT)
LPP = (TMX, RFK)
VHJ = (VPD, JCQ)
XSF = (BRF, TSF)
GMB = (PRL, TPH)
VGR = (BMR, CNH)
JGQ = (GHP, PVG)
CFJ = (JHM, GFQ)
FQX = (QTN, MPB)
LJV = (NMH, HKB)
SVJ = (KVB, GVJ)
QCC = (XMP, NGP)
JLG = (PNM, QLF)
MHD = (BSG, RQX)
RNN = (LTQ, HKH)
MPD = (DQF, FTF)
RKH = (RFJ, VBJ)
QBQ = (QCC, DGP)
RKR = (LSB, GNX)
HRP = (RSD, HKP)
NXX = (TNL, TJD)
CHG = (CMC, LLJ)
JVS = (SCH, GMQ)
STT = (CRK, QPD)
LRX = (CGG, TLR)
SSL = (TRQ, TRQ)
SSM = (NND, KLF)
XPK = (FQL, BPT)
QXX = (DPC, QLD)
QCS = (NBK, PCL)
TSF = (VGR, BFD)
LBL = (HPP, TML)
XQN = (BRJ, RJK)
NGX = (KXN, SKX)
DKS = (JFK, XVP)
TGD = (KHF, GXM)
JRX = (PBG, RHR)
CPC = (XQM, FCB)
JSG = (QLD, DPC)
QTD = (FPJ, CVG)
DBR = (HTD, MDN)
DQF = (XSG, GCM)
DTB = (SNF, SVJ)
QFB = (PJQ, KQX)
FCP = (RSC, BFH)
BSG = (QMT, DTB)
JJF = (TMK, GTP)
CCG = (SFQ, VLX)
XSG = (GMS, HGC)
VTN = (BJV, SLG)
TRH = (MQT, FMJ)
TPH = (XDL, XKB)
GXC = (BDM, SBT)
DGN = (MHC, XMB)
XCN = (XPS, TVT)
XLM = (MFT, NLQ)
LVC = (VRT, SPT)
TDX = (HKB, NMH)
XNX = (LJT, DKB)
DGR = (BSC, PRT)
TJF = (NQC, QNV)
QNV = (NJD, SXL)
RDP = (DHL, PDV)
CLX = (LKT, SCK)
LKT = (LBL, XXD)
FMS = (JXP, FFX)
FHB = (CBM, FBS)
CRB = (GHG, JRG)
GHX = (LPG, DGQ)
FPJ = (PLD, CXJ)
RLJ = (KQP, SCT)
LTQ = (KPS, NQM)
VFJ = (MHV, GDT)
KLF = (CFK, TCL)
LTJ = (VTN, VTN)
JRP = (GDF, SCN)
SCX = (RRN, NMC)
CMS = (JJF, VXG)
KJZ = (HFM, QKR)
VNN = (FTF, DQF)
MXN = (RNP, SFL)
LDC = (DGR, BLX)
BBQ = (DRG, MXN)
KBJ = (KNH, NFN)
KQG = (FDG, VBV)
CBT = (BTH, TLV)
RCF = (LQQ, MFK)
CNH = (LGT, JGT)
XRS = (DPJ, QFF)
LPJ = (CCG, GBD)
SCN = (FHF, BJP)
NVG = (BHM, SSM)
DVL = (CLX, BRQ)
CPN = (DKS, HQT)
SPC = (FRM, VQC)
KQH = (JXP, FFX)
VRT = (HQV, BLR)
HDX = (LJF, RCF)
XXR = (CVD, HNC)
GVQ = (NXS, JMB)
SNQ = (CHG, CKK)
FPH = (PQL, MBC)
PBK = (SSB, DTF)
LPL = (JQF, JQF)
VQL = (KXN, SKX)
VMB = (LHF, CDQ)
FNM = (RQD, DFT)
BLX = (BSC, PRT)
PVG = (BGF, TDF)
HPH = (DGP, QCC)
PKT = (FJC, VGV)
KNV = (VBP, KDQ)
PJS = (NBP, XHM)
XNZ = (JLP, NQP)
BJV = (SRJ, QNM)
CBM = (PBK, LXX)
QSX = (SFS, JSV)
VFR = (RSC, BFH)
QSG = (MHC, XMB)
KQK = (QCS, GTQ)
XXM = (RTX, XPK)
JPB = (FPP, QTD)
DRH = (TRQ, BRB)
MSJ = (RKH, RKH)
MRK = (RJX, NVQ)
RSD = (BRX, BBQ)
FBS = (PBK, LXX)
FMB = (MSJ, MSJ)
BJP = (RQQ, TBR)
GTL = (GJX, TRH)
GMQ = (HDC, MDJ)
GCM = (HGC, GMS)
PJJ = (FTM, XGT)
AAA = (XHV, KDJ)
VBP = (MVX, DDX)
SQB = (VSX, MCT)
XFQ = (RGG, SHQ)
RQG = (JVH, LMR)
GXM = (FHB, MRX)
QKT = (JRX, THB)
RLF = (QSX, QKN)
PMT = (NQP, JLP)
PNM = (CJC, XMX)
SNF = (GVJ, KVB)
XJP = (VVM, NFM)
NFN = (FQH, FPH)
BJG = (QPT, JXG)
PST = (JHM, GFQ)
RXB = (HNC, CVD)
XNH = (KKB, PQZ)
DRG = (SFL, RNP)
MRB = (DSM, JVQ)
SJB = (SJX, TMR)
BMR = (JGT, LGT)
LND = (LRX, CLT)
MBC = (KPV, RLJ)
XHT = (CGH, FHK)
XPS = (CPN, TJB)
RRR = (CQR, CRB)
GPB = (JVH, LMR)
PTN = (GNV, QSM)
DHB = (CCK, NJF)
XGV = (RCF, LJF)
THC = (KGL, MFB)
JSV = (MGP, NDF)
XLH = (RQD, DFT)
PXV = (HBS, DTS)
FMJ = (SKG, XVB)
SKG = (GLL, NNP)
VBM = (KCM, FTD)
BHX = (STC, GLD)
RPS = (HNQ, SXD)
TNS = (THB, JRX)
PJR = (KSP, LDJ)
PGJ = (DSM, JVQ)
BHM = (NND, KLF)
BDR = (VXH, HHB)
JVQ = (PNV, JGF)
NQM = (FMB, QKV)
VDM = (XGV, HDX)
XNV = (XNN, TCJ)
SRF = (CVV, JSJ)
FHF = (RQQ, TBR)
TMX = (PKN, KLG)
HNF = (PKM, XMG)
HKH = (KPS, NQM)
JFN = (VXM, GXC)
TMR = (XCN, NFB)
CDF = (XGF, GHQ)
DCN = (QTN, MPB)
HKV = (DNM, DNM)
XRT = (LHM, JFN)
JGX = (PRL, TPH)
LFH = (RPX, PQH)
RLL = (DJF, RRR)
NLK = (PPH, RMJ)
JNQ = (XHM, NBP)
RXL = (HCB, KLT)
FFX = (JRJ, SCX)
JVH = (TLD, RJD)
JRC = (FNR, TSV)
KHF = (MRX, FHB)
HPT = (BXG, GVQ)
PLD = (TSD, BGM)
VND = (XGV, HDX)
GKL = (XFF, BTT)
VSC = (BRJ, RJK)
KTM = (GJB, PTN)
NMH = (XBG, VHJ)
KPS = (FMB, FMB)
XTK = (VLJ, MFX)
HDC = (HQS, MNP)
TRK = (FCP, VFR)
MKQ = (GJT, DVL)
CGG = (FMS, KQH)
XSK = (GMQ, SCH)
JJX = (TGG, XCD)
QKN = (SFS, JSV)
RPX = (JPB, JRN)
JXH = (QDH, QDH)
GHT = (KQX, PJQ)
XCT = (TGV, QNN)
BDM = (NSJ, GRB)
MMH = (NGX, VQL)
FVB = (PMB, XDQ)
NGK = (TDX, LJV)
QNM = (VVV, XLM)
TLR = (FMS, KQH)
VPX = (LMS, NBB)
PJQ = (FNM, XLH)
FHT = (BHM, SSM)
TJQ = (LSB, GNX)
LLS = (XJR, KMK)
JFV = (QNN, TGV)
LHA = (RFJ, VBJ)
LHM = (GXC, VXM)
RHA = (NQP, JLP)
JHV = (LVK, DCV)
XGF = (SPC, SNP)
LSH = (CDL, DSF)
KXN = (LDC, NGD)
XMP = (VFJ, GJM)
BDB = (TDC, JLG)
DVT = (PKT, BLB)
KPV = (SCT, KQP)
GLL = (BJG, RCR)
LSK = (DNM, XNH)
KRC = (DNF, FRN)
TQX = (SQG, GXV)
GQC = (LJV, TDX)
FFS = (KHF, GXM)
SRJ = (VVV, XLM)
TJD = (NTH, VPH)
LHV = (DHS, JJX)
FQM = (CSL, GHX)
CSL = (DGQ, LPG)
PCM = (DHS, JJX)
GJX = (FMJ, MQT)
DTV = (KQG, DTL)
RHC = (PVR, PKK)
RKX = (LPH, MTQ)
KGB = (FNR, TSV)
XQM = (HPT, VXF)
MGV = (KNH, NFN)
KSG = (KCL, KCG)
TSV = (STN, KNV)
SLG = (SRJ, QNM)
MBT = (QSX, QKN)
BTG = (QDH, LXB)
GXV = (RQG, GPB)
BTH = (BPP, KTM)
NVQ = (PKH, SQB)
MDN = (NCB, BGL)
PKN = (KTG, CQK)
LXB = (HRG, VDX)
NVT = (HXG, XRS)
QNN = (FVB, SHD)
KVM = (XJP, XPM)
VPD = (HNF, NMR)
MRL = (JKG, BBS)
SGV = (GFS, NSS)
KGL = (XTB, HQP)
XGT = (JFV, XCT)
HKB = (XBG, VHJ)
CMC = (JPL, SPB)
TDJ = (TRK, KPK)
XLZ = (SLG, BJV)
CHX = (GGM, TPL)
KDQ = (DDX, MVX)
HFM = (KJR, HMS)
RQX = (QMT, DTB)
KQR = (HGD, RHM)
XBG = (JCQ, VPD)
JPV = (NGX, VQL)
VMX = (PST, CFJ)
XXT = (TSF, BRF)
TLV = (KTM, BPP)
DCC = (FHK, CGH)
XVP = (XRJ, DKL)
HCB = (VRH, KQK)
LCP = (MPN, QTM)
CSX = (FXX, PSG)
QKV = (MSJ, HKJ)
KCL = (FSN, FSN)
JNC = (HHB, VXH)
SGK = (RMJ, PPH)
CJM = (BVG, PNH)
MGN = (VTN, XLZ)
HGD = (HJH, BGS)
STN = (VBP, KDQ)
NPR = (RLL, HMN)
RRN = (QRM, BBN)
SHD = (PMB, XDQ)
HQT = (JFK, XVP)
JSB = (DVX, DGL)
TVL = (RSD, HKP)
PBL = (JSJ, CVV)
KBG = (XNX, MXV)
HGN = (NVT, PLM)
BRB = (PMT, XNZ)
XMX = (HKV, LSK)
XMG = (LSH, JNX)
BTT = (LHJ, NLG)
TFR = (LHV, PCM)
MVX = (XVG, PBF)
NBP = (SMV, GSJ)
JDN = (KRC, DLL)
QLD = (VRX, XTK)
MSF = (GHB, RXF)
DPJ = (XMT, TDJ)
SPP = (SRH, VDT)
LQQ = (GSM, CJM)
NBK = (JPV, MMH)
VBV = (SRF, PBL)
GHQ = (SNP, SPC)
SSB = (DRD, BGR)
CVD = (PGJ, MRB)
FPP = (CVG, FPJ)
DFT = (TNQ, NQD)
PQZ = (MRL, QGF)
SKN = (RKR, TJQ)
GMS = (HGN, RPM)
DLL = (FRN, DNF)
LXT = (VBM, BPC)
CVA = (QKR, HFM)
HNC = (PGJ, MRB)
BRV = (XFF, BTT)
RTX = (BPT, FQL)
NQD = (SVS, DTV)
TNQ = (DTV, SVS)
GBR = (RHC, LLN)
XKB = (DRJ, MHF)
NFM = (QMJ, PKR)
XFF = (LHJ, NLG)
TCL = (XNV, QRX)
DRJ = (CFL, QJK)
GJB = (GNV, QSM)
LSB = (PNT, KDG)
PNH = (CSX, LFM)
HRG = (VSG, VSG)
DNX = (TJF, XSD)
KKV = (DCV, LVK)
QHH = (HCB, KLT)
FTF = (XSG, GCM)
NDH = (XQM, FCB)
VXM = (SBT, BDM)
PNV = (LXT, HHC)
KNH = (FPH, FQH)
CKK = (CMC, LLJ)
BBD = (NPR, BGX)
CKC = (LCR, GXR)
PDV = (BMK, LST)
PQL = (RLJ, KPV)
MDX = (CHG, CKK)
BSC = (QPS, QPS)
VLK = (NTJ, DVT)
KDG = (MRV, KQR)
PNT = (MRV, KQR)
TNL = (VPH, NTH)
LLN = (PVR, PKK)
MHC = (XXT, XSF)
QPS = (KCL, KCL)
NNQ = (TJQ, RKR)
NHL = (PVG, GHP)
VMJ = (GRT, LPP)
SFS = (NDF, MGP)
BGR = (QXX, JSG)
QXK = (FQJ, CHX)
DSM = (JGF, PNV)
MBR = (LLN, RHC)
BRF = (VGR, BFD)
NNP = (RCR, BJG)
KKB = (QGF, MRL)
MHF = (QJK, CFL)
MQT = (SKG, XVB)
HTJ = (VXG, JJF)
JRG = (XVF, XRT)
LST = (FFS, TGD)
KPK = (FCP, VFR)
MLL = (DHL, PDV)
NMC = (BBN, QRM)
LDA = (BJV, SLG)
RHR = (JRC, KGB)
PVR = (VND, VDM)
NXS = (VPX, SPN)
RSC = (CQG, GRP)
PGC = (MKQ, GRF)
FQJ = (GGM, TPL)
HHR = (RPX, PQH)
RPM = (PLM, NVT)
STC = (LJP, JBN)
QMT = (SVJ, SNF)
NXB = (RPS, KBB)
GJT = (BRQ, CLX)
DKB = (VMB, XND)
BNL = (TNL, TJD)
SVS = (DTL, KQG)
GFC = (FQJ, CHX)
SNP = (FRM, VQC)
KCM = (GHT, QFB)
JSJ = (JRP, NRD)
MNP = (HLK, XFM)
BGF = (HMF, KBM)
HQS = (XFM, HLK)
GRF = (DVL, GJT)
HGC = (HGN, RPM)
SFQ = (MBR, GBR)
CGT = (NJF, CCK)
GHG = (XVF, XRT)
NTJ = (PKT, BLB)
NJF = (NNQ, SKN)
SPT = (BLR, HQV)
XJR = (CPC, NDH)
RQQ = (GQC, NGK)
XDL = (DRJ, MHF)
JKG = (QTB, LVJ)
GHB = (SGK, NLK)
KHM = (STC, GLD)
BKM = (GHB, RXF)
BLR = (DCC, XHT)
VTV = (JXH, BTG)
TJB = (DKS, HQT)
FCB = (VXF, HPT)
BFH = (CQG, GRP)
LVK = (TFJ, JDN)
RNP = (MGV, KBJ)
SJM = (VNP, PDT)
NQP = (CKC, VKB)
MDJ = (MNP, HQS)
MFT = (VSC, XQN)
LXX = (SSB, DTF)
JFK = (DKL, XRJ)
LCR = (PSD, PPM)
SFL = (MGV, KBJ)
DNM = (KKB, KKB)
RJK = (FXK, PXV)
KBB = (SXD, HNQ)
MTM = (BBJ, DBR)
NFB = (TVT, XPS)
XDK = (JNQ, PJS)
RXQ = (LTJ, MGN)
ZZZ = (KDJ, XHV)
KMK = (CPC, NDH)
FJC = (HHR, LFH)
"""
solution08_1 = fn input ->
[directions | nodes] = input |> String.split("\n", trim: true)
nodes =
nodes
|> Enum.map(fn line ->
[[node], [left], [right]] = Regex.scan(~r/\w{3}/, line)
{node, %{?L => left, ?R => right}}
end)
|> Enum.into(%{})
directions
|> String.to_charlist()
|> Stream.cycle()
|> Enum.reduce_while({"AAA", 0}, fn dir, {cur_node, steps} ->
cur_node = nodes[cur_node][dir]
steps = steps + 1
if cur_node == "ZZZ" do
{:halt, steps}
else
{:cont, {cur_node, steps}}
end
end)
end
solution08_1.(sample81_1)
solution08_1.(sample81_2)
solution08_1.(input08_1)
Day 8 - Part 2
sample08_2 = """
LR
11A = (11B, XXX)
11B = (XXX, 11Z)
11Z = (11B, XXX)
22A = (22B, XXX)
22B = (22C, 22C)
22C = (22Z, 22Z)
22Z = (22B, 22B)
XXX = (XXX, XXX)
"""
input08_2 = input08_1
solution08_2 = fn input ->
[directions | nodes] = input |> String.split("\n", trim: true)
directions = directions |> String.to_charlist()
dir_len = directions |> Enum.count()
nodes =
nodes
|> Enum.map(fn line ->
[[node], [left], [right]] = Regex.scan(~r/\w{3}/, line)
{node, %{?L => left, ?R => right}}
end)
|> Enum.into(%{})
start_nodes = nodes |> Map.keys() |> Enum.filter(&String.ends_with?(&1, "A"))
find_cycle = fn start ->
Stream.iterate(1, &(&1 + 1))
|> Enum.reduce_while({start, []}, fn i, {start, exit_loops} ->
last =
directions
|> Enum.reduce(start, fn dir, cur ->
nodes[cur][dir]
end)
if last |> String.ends_with?("Z") do
{:halt, i}
else
{:cont, {last, exit_loops}}
end
end)
end
start_nodes
|> Enum.map(find_cycle)
|> Enum.reduce(fn n, lcm ->
div(n * lcm, Integer.gcd(n, lcm))
end)
|> Kernel.*(dir_len)
end
solution08_2.(sample08_2)
solution08_2.(input08_2)
Day 9 - Part 1
sample09_1 = """
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
"""
input09_1 = """
8 10 9 -2 -17 8 190 771 2208 5345 11753 24409 49063 97014 190779 375658 743112 1477240 2945141 5868120 11637263
-9 -16 -26 -42 -67 -89 -41 278 1345 4163 10710 24787 53710 111805 227699 459451 925644 1868703 3782952 7672020 15562542
28 51 96 170 284 469 798 1415 2573 4692 8485 15300 28049 53554 108059 229471 503402 1116673 2463878 5353430 11394522
10 16 22 28 34 40 46 52 58 64 70 76 82 88 94 100 106 112 118 124 130
8 24 56 121 238 431 742 1256 2137 3671 6309 10700 17701 28348 43769 65017 92798 127066 166454 207507 243680
3 13 33 61 105 197 418 951 2204 5084 11556 25688 55464 115742 232843 451380 844073 1525447 2670475 4539407 7510219
15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55
4 5 21 57 125 255 506 977 1818 3241 5531 9057 14283 21779 32232 46457 65408 90189 122065 162473 213033
5 12 36 95 219 453 862 1541 2644 4472 7720 14109 27863 58876 128976 283411 610443 1272472 2551916 4913291 9078231
2 19 48 88 142 226 378 659 1139 1866 2825 3907 4925 5735 6545 8524 14856 32421 74326 163554 338048
3 2 -4 -12 -13 15 119 394 1027 2386 5231 11268 24599 55319 127898 299662 699808 1609223 3620339 7952681 17068804
9 19 41 88 184 362 655 1088 1698 2633 4409 8432 17912 39299 84354 172945 336675 623603 1104781 1884372 3117140
11 10 7 2 -5 -14 -25 -38 -53 -70 -89 -110 -133 -158 -185 -214 -245 -278 -313 -350 -389
19 24 24 19 9 -6 -26 -51 -81 -116 -156 -201 -251 -306 -366 -431 -501 -576 -656 -741 -831
9 32 76 155 293 539 990 1835 3446 6555 12569 24088 45704 85172 155057 274974 474551 797258 1305258 2085449 3256879
4 22 61 126 216 323 429 496 442 104 -778 -2444 -4602 -5001 3844 41336 151368 424562 1035747 2304666 4791100
0 0 9 40 118 299 697 1509 3030 5661 9946 16758 27950 48215 89776 183216 400828 904162 2036175 4492208 9625134
13 25 39 60 106 222 501 1112 2341 4666 8915 16616 30800 57904 112321 227047 477565 1032763 2257999 4913736 10521598
6 22 40 69 146 357 871 2004 4337 8920 17613 33667 62784 115219 210184 385179 715340 1352050 2596670 5035253 9774610
2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142
-1 -2 -8 -29 -74 -137 -160 57 1057 4150 12265 31578 74476 164761 346652 700523 1371301 2621840 4937055 9232612 17279510
7 3 -1 -5 -9 -13 -17 -21 -25 -29 -33 -37 -41 -45 -49 -53 -57 -61 -65 -69 -73
18 35 77 152 275 474 797 1337 2301 4165 8004 16198 33941 72398 155095 330403 695128 1437759 2915603 5788900 11248491
7 28 76 166 310 512 772 1122 1725 3072 6312 13746 29508 60444 117184 215382 377075 632084 1019348 1588046 2398322
-3 10 34 68 126 257 565 1229 2528 4882 8928 15661 26685 44639 73889 121610 199423 325802 529526 854522 1366528
6 4 15 51 125 266 551 1157 2441 5079 10347 20719 41097 81174 159640 311114 596708 1118810 2039715 3601703 6142457
12 35 71 120 182 257 345 446 560 687 827 980 1146 1325 1517 1722 1940 2171 2415 2672 2942
-2 4 33 113 285 614 1209 2261 4127 7519 13909 26350 51070 100480 198753 392053 767092 1484370 2836777 5350987 9959291
-6 -2 3 9 20 44 93 183 334 570 919 1413 2088 2984 4145 5619 7458 9718 12459 15745 19644
12 25 49 95 174 290 437 612 857 1353 2630 6055 14955 37103 90000 211717 482514 1066813 2292543 4797075 9788236
-4 4 16 26 29 26 31 88 318 1047 3127 8672 22628 55944 131699 296469 640572 1332626 2675974 5196610 9773547
14 20 26 42 100 265 654 1485 3185 6596 13338 26437 51445 98542 186642 351540 662034 1251569 2380155 4556366 8781478
17 28 52 116 263 555 1079 1958 3381 5702 9728 17440 33609 69151 147721 318136 676961 1408280 2851676 5615220 10758379
27 38 47 50 36 -21 -161 -409 -683 -567 1192 7716 25976 70370 168856 372991 773719 1525352 2880909 5242830 9234076
9 24 52 89 130 174 242 430 1026 2727 7008 16735 37199 77905 155712 300326 563743 1036074 1871316 3328125 5832568
18 30 58 130 290 604 1169 2128 3710 6351 11024 20036 38775 79266 167002 353463 738166 1506184 2990058 5769178 10825356
23 37 62 108 193 352 660 1280 2553 5166 10476 21162 42594 85792 173866 355862 735855 1532471 3197482 6646280 13695427
-7 -9 1 33 93 192 372 760 1668 3760 8302 17494 34850 65539 116523 196223 313307 474021 677271 906407 1116355
4 13 35 70 118 179 253 340 440 553 679 818 970 1135 1313 1504 1708 1925 2155 2398 2654
13 32 68 135 266 535 1087 2173 4187 7702 13502 22607 36288 56069 83713 121189 170617 234188 314056 412199 530246
15 39 72 119 196 333 580 1029 1874 3542 6945 13932 28069 55954 109395 208956 389625 709697 1264414 2206485 3776346
23 48 100 198 372 668 1150 1905 3070 4928 8170 14508 27993 57733 123378 265976 568880 1196482 2462432 4942379 9645683
22 37 58 84 123 216 478 1175 2866 6656 14639 30679 61822 120915 231510 436964 817030 1517731 2805360 5166426 9499429
9 38 78 125 175 224 268 303 325 330 314 273 203 100 -40 -221 -447 -722 -1050 -1435 -1881
10 28 69 152 306 570 993 1634 2562 3856 5605 7908 10874 14622 19281 24990 31898 40164 49957 61456 74850
10 30 66 140 289 566 1040 1795 2928 4546 6762 9690 13439 18106 23768 30473 38230 46998 56674 67080 77949
10 33 71 120 172 215 233 206 110 -83 -405 -892 -1584 -2525 -3763 -5350 -7342 -9799 -12785 -16368 -20620
10 22 42 79 147 285 585 1232 2574 5271 10644 21490 43883 90886 189731 395088 813105 1645355 3271757 6413156 12459158
10 22 42 75 127 213 369 668 1240 2296 4156 7281 12309 20095 31755 48714 72758 106090 151390 211879 291387
-4 -11 -10 7 44 101 174 255 332 389 406 359 220 -43 -466 -1089 -1956 -3115 -4618 -6521 -8884
6 13 27 55 126 305 707 1511 2974 5445 9379 15351 24070 36393 53339 76103 106070 144829 194187 256183 333102
20 33 58 101 165 248 350 501 838 1791 4500 11709 29625 71674 165847 368562 789903 1638140 3296401 6452952 12322160
23 39 62 92 129 173 224 282 347 419 498 584 677 777 884 998 1119 1247 1382 1524 1673
8 23 43 75 141 283 577 1166 2326 4597 9059 17933 35875 72670 148631 305041 623716 1262615 2518947 4938203 9498009
5 6 14 50 148 354 723 1323 2267 3805 6514 11618 21442 39941 73131 129065 216721 342776 504702 677906 793712
17 39 77 145 271 506 944 1760 3284 6161 11714 22748 45250 91860 188860 390266 806371 1661427 3408743 6955423 14089337
8 11 17 19 16 30 134 493 1416 3421 7337 14514 27296 50072 91574 169956 324336 641639 1319313 2809709 6143224
20 40 82 157 276 450 690 1007 1412 1916 2530 3265 4132 5142 6306 7635 9140 10832 12722 14821 17140
26 51 92 152 243 410 767 1551 3215 6604 13286 26131 50219 94068 170936 299469 502108 798261 1187076 1611454 1890399
5 4 -3 -16 -37 -71 -118 -146 -26 614 2709 8433 22564 55138 126495 276803 584082 1198534 2408270 4765262 9325584
16 24 24 20 20 33 68 136 256 466 840 1512 2708 4787 8292 14012 23056 36940 57688 87948 131124
2 4 17 50 116 232 419 702 1110 1676 2437 3434 4712 6320 8311 10742 13674 17172 21305 26146 31772
9 21 50 100 171 262 381 562 889 1527 2760 5036 9019 15648 26203 42378 66361 100921 149502 216324 306491
13 19 47 108 224 444 870 1714 3432 7027 14700 31188 66405 140452 292753 598086 1193703 2323675 4409173 8156732 14720782
9 14 24 54 143 367 864 1895 3980 8163 16475 32679 63396 119726 219493 390258 673259 1128452 1840842 2928308 4551141
2 1 4 10 10 -19 -107 -262 -420 -378 302 2477 7844 19892 45891 100715 213678 440047 879496 1704492 3202470
23 51 106 201 353 596 998 1681 2859 4937 8750 16060 30476 59057 115120 223470 430907 828331 1597490 3107587 6107791
20 41 78 134 207 294 404 583 954 1767 3431 6461 11241 17567 24329 30972 45742 113631 394186 1354910 4215913
24 44 85 162 305 572 1065 1962 3594 6612 12299 23081 43291 80299 146385 262490 466732 834112 1520337 2853824 5518005
13 25 53 116 249 517 1041 2041 3906 7306 13366 23927 41924 71916 120808 198810 320683 507327 787771 1201630 1802099
21 36 51 65 78 93 132 286 825 2400 6393 15550 35227 75980 158961 326806 664625 1338584 2663715 5218371 10030592
-2 10 41 111 263 574 1177 2302 4346 7998 14498 26240 48213 91352 180004 367865 770694 1631114 3442799 7181181 14719595
18 37 69 128 236 416 695 1128 1861 3265 6203 12558 26282 55463 116296 240439 488096 970361 1885949 3579504 6631284
16 22 39 87 214 510 1121 2263 4236 7438 12379 19695 30162 44710 64437 90623 124744 168486 223759 292711 377742
9 12 25 49 89 160 301 608 1312 2951 6717 15102 33027 69744 142059 280147 539226 1025523 1957432 3810972 7658912
20 23 28 51 127 324 759 1624 3256 6337 12400 24960 51801 109240 229543 473023 946556 1830019 3410988 6125145 10594043
13 41 81 141 250 464 868 1574 2715 4435 6875 10155 14352 19474 25430 31996 38777 45165 50293 52985 51702
9 25 60 119 218 394 712 1273 2236 3882 6772 12095 22397 43107 85819 175561 367114 781429 1685305 3661271 7960379
4 -3 -16 -36 -64 -101 -148 -206 -276 -359 -456 -568 -696 -841 -1004 -1186 -1388 -1611 -1856 -2124 -2416
12 22 40 66 101 159 289 616 1428 3364 7800 17594 38458 81425 167274 334550 654272 1257026 2382572 4469306 8312199
16 36 62 92 124 156 186 212 232 244 246 236 212 172 114 36 -64 -188 -338 -516 -724
-7 -6 1 14 33 58 89 126 169 218 273 334 401 474 553 638 729 826 929 1038 1153
21 41 85 171 323 570 943 1470 2169 3039 4049 5125 6135 6872 7035 6208 3837 -795 -8595 -20689 -38453
0 2 3 7 42 189 631 1728 4124 8892 17723 33165 58918 100191 164127 260302 401304 603398 887283 1278947 1810626
6 27 66 133 252 474 900 1733 3392 6747 13590 27567 55991 113275 227215 450074 877438 1679215 3149022 5780661 10383546
9 31 60 105 196 390 771 1445 2548 4325 7416 13619 27615 60490 136517 305923 669051 1423011 2953492 6016853 12099022
10 10 21 57 143 333 754 1693 3747 8052 16589 32520 60419 106134 175917 274623 403748 562914 764993 1088463 1815555
0 11 47 123 250 438 717 1186 2100 4005 7931 15653 30030 55432 98265 167604 275944 440079 682119 1030655 1522082
4 2 5 13 19 5 -59 -207 -444 -647 -311 2028 9979 31542 83085 196006 427388 876388 1708621 3191415 5743531
21 28 30 24 16 36 154 489 1199 2436 4246 6390 8058 7444 1146 -16649 -55239 -128788 -258066 -472604 -813324
2 1 3 8 31 126 434 1265 3232 7490 16224 33728 68807 139949 285947 586660 1201702 2439383 4874513 9541916 18242623
11 15 11 0 -8 20 173 655 1882 4654 10510 22528 47110 97732 202274 416411 846705 1688621 3286965 6229712 11491728
22 34 53 83 132 217 384 759 1656 3781 8578 18756 39018 77011 144606 259984 452078 771652 1319659 2317357 4271044
-1 10 40 92 174 315 592 1169 2349 4640 8836 16114 28148 47241 76476 119887 182651 271302 393968 560632 783418
11 27 70 166 357 711 1348 2493 4581 8479 15978 30885 61394 125101 259370 542362 1135062 2364307 4885498 10000015 20273388
16 34 71 142 262 448 727 1148 1805 2912 5045 9795 21275 49208 114707 260357 566838 1179102 2346051 4478772 8233684
-1 3 10 20 33 49 68 90 115 143 174 208 245 285 328 374 423 475 530 588 649
8 19 45 96 187 347 635 1155 2072 3652 6373 11169 19859 35758 64343 113626 193536 313097 473469 653950 786771
16 27 57 113 198 323 534 953 1841 3719 7634 15727 32332 65876 131823 256818 484209 881806 1555374 2678560 4566449
6 15 32 61 113 206 365 622 1016 1593 2406 3515 4987 6896 9323 12356 16090 20627 26076 32553 40181
12 22 41 78 161 360 818 1788 3675 7089 12934 22598 38391 64551 109515 190999 347381 663416 1328773 2771447 5959410
20 37 57 82 120 202 409 905 1974 4070 7921 14798 27191 50372 95791 188266 381292 790377 1667237 3566548 7718806
13 31 51 84 169 384 851 1731 3207 5457 8622 12766 17791 23206 27605 27891 19281 389 -3571 134438 850205
12 30 69 155 343 727 1450 2720 4851 8376 14327 24862 44585 83254 161329 321456 652505 1340181 2773452 5766664 12017378
7 33 73 127 195 277 373 483 607 745 897 1063 1243 1437 1645 1867 2103 2353 2617 2895 3187
14 28 57 126 266 511 910 1580 2847 5550 11627 25187 54445 115233 237408 476507 934644 1797152 3395149 6309420 11538196
12 20 31 64 149 337 730 1545 3236 6713 13717 27432 53431 101047 185216 328782 565363 943750 1538049 2477213 4031782
4 9 15 22 30 39 49 60 72 85 99 114 130 147 165 184 204 225 247 270 294
8 16 40 86 162 281 478 850 1629 3313 6920 14505 30198 62187 126285 251980 492162 938034 1741020 3143748 5522366
16 27 42 65 100 151 222 317 440 595 786 1017 1292 1615 1990 2421 2912 3467 4090 4785 5556
6 20 54 122 238 416 670 1014 1462 2028 2726 3570 4574 5752 7118 8686 10470 12484 14742 17258 20046
9 24 58 124 248 479 909 1713 3230 6126 11716 22596 43907 85957 169853 339829 690242 1423895 2975313 6264575 13205537
10 30 69 129 215 346 572 997 1808 3310 5967 10449 17685 28922 45790 70373 105286 153758 219721 307905 423939
5 6 12 44 147 410 1009 2300 5014 10641 22129 45070 89636 173785 328969 611348 1125520 2076190 3879935 7401246 14436738
4 23 58 126 255 497 955 1823 3438 6343 11360 19672 32913 53265 83561 127393 189224 274503 389782 542834 742771
-3 3 14 23 25 25 43 111 257 471 648 503 -547 -3539 -10163 -23009 -45867 -84085 -144990 -238377 -377071
24 32 45 77 159 360 827 1863 4068 8584 17521 34717 67143 127585 239871 449153 842175 1587195 3012500 5760444 11088242
-1 -10 -11 17 100 263 524 900 1447 2377 4337 9008 20296 46552 104484 225721 467367 928352 1773957 3271571 5841540
7 9 21 54 125 261 505 927 1647 2882 5033 8829 15541 27268 47277 80348 133031 213663 331917 497560 717981
10 25 59 126 244 435 733 1209 2021 3494 6227 11208 19891 34148 55951 86561 124900 164655 189507 165690 30862
17 39 65 91 129 232 527 1254 2820 5913 11798 23063 45363 91274 188528 397238 845276 1799567 3807034 7968541 16464470
10 5 8 41 136 332 666 1164 1850 2805 4324 7237 13480 27024 55294 111236 216218 403981 725888 1257753 2108568
23 28 45 103 240 500 936 1633 2784 4889 9214 18760 40184 87465 188797 399575 827065 1677498 3345611 6582649 12805268
16 36 75 162 343 693 1348 2572 4878 9227 17344 32245 59237 108076 197887 368248 703127 1380167 2768016 5612597 11386394
9 25 48 72 98 137 208 331 515 741 940 966 564 -667 -3316 -8207 -16451 -29503 -49224 -77948 -118554
8 11 19 51 147 387 916 1974 3939 7405 13332 23309 39939 67244 110732 176273 266070 368619 437421 350083 -164985
1 18 58 126 237 431 788 1443 2601 4552 7686 12508 19653 29901 44192 63641 89553 123438 167026 222282 291421
6 14 44 113 249 499 946 1753 3263 6207 12115 24099 48316 96714 192312 379634 745628 1461428 2864106 5612169 10971811
3 -1 -4 15 107 376 1022 2428 5329 11117 22350 43537 82253 150582 266772 456790 755159 1204011 1848664 2727187 3850311
-2 11 36 86 184 371 731 1440 2846 5587 10754 20106 36344 63451 107105 175172 278286 430523 650176 960638 1391400
2 12 49 136 307 612 1119 1915 3118 4931 7803 12816 22494 42330 83446 166930 330518 638386 1194857 2162772 3787073
14 23 56 129 259 471 826 1484 2816 5579 11168 21959 41757 76363 134274 227530 372722 592175 915320 1380269 2035607
-3 10 37 93 208 427 810 1432 2383 3768 5707 8335 11802 16273 21928 28962 37585 48022 60513 75313 92692
14 26 51 89 140 204 281 371 474 590 719 861 1016 1184 1365 1559 1766 1986 2219 2465 2724
13 18 22 22 18 15 24 62 151 316 582 970 1492 2145 2904 3714 4481 5062 5254 4782 3286
2 9 33 96 243 556 1172 2313 4353 7978 14545 26820 50378 96085 184258 351319 660028 1214703 2183217 3828008 6548853
16 14 18 44 112 244 468 833 1440 2494 4382 7782 13808 24196 41536 69555 113456 180318 279562 423488 627888
26 51 102 207 421 842 1643 3133 5872 10895 20161 37455 70161 132626 252290 480413 910142 1705891 3149624 5711711 10156653
-8 -9 -5 6 26 57 101 160 236 331 447 586 750 941 1161 1412 1696 2015 2371 2766 3202
6 11 36 109 272 579 1093 1890 3099 5048 8652 16275 33429 71844 154659 324750 657532 1279953 2397844 4334305 7582398
12 13 19 49 142 372 874 1886 3822 7408 13943 25807 47456 87359 161694 301190 563352 1053519 1959875 3609765 6557578
3 11 30 60 101 153 216 290 375 471 578 696 825 965 1116 1278 1451 1635 1830 2036 2253
2 5 14 38 86 167 290 464 698 1001 1382 1850 2414 3083 3866 4772 5810 6989 8318 9806 11462
12 14 25 57 123 242 448 813 1520 3071 6796 15951 37865 87827 195703 416649 847748 1652956 3099403 5608869 9829151
11 19 46 109 234 461 861 1576 2893 5363 9976 18403 33316 58797 100847 168006 272095 429091 660146 992761 1462126
12 23 46 76 103 123 168 360 988 2610 6216 13584 28159 57134 115970 237426 488356 999153 2012874 3963868 7599263
10 27 58 116 238 503 1059 2170 4308 8331 15813 29644 55142 102218 189816 355285 674142 1300799 2549636 5050248 10033414
-1 -4 -11 -23 -41 -66 -99 -141 -193 -256 -331 -419 -521 -638 -771 -921 -1089 -1276 -1483 -1711 -1961
25 51 96 173 317 600 1159 2245 4300 8080 14874 26942 48463 87669 161677 307220 603675 1220565 2511928 5198007 10707121
6 28 60 95 122 126 88 -15 -210 -528 -1004 -1677 -2590 -3790 -5328 -7259 -9642 -12540 -16020 -20153 -25014
14 27 46 83 176 401 886 1840 3627 6937 13133 24885 47239 89311 166843 305910 548124 957743 1631160 2709319 4393682
16 28 49 81 128 208 369 702 1349 2526 4627 8552 16517 33764 71801 154073 325302 666144 1315301 2501803 4590846
28 43 66 110 191 336 602 1103 2052 3863 7434 14852 30927 66172 142094 299937 614308 1213403 2307810 4230074 7487335
17 21 36 76 171 394 901 1991 4208 8544 16875 32885 63920 124479 242406 469310 897323 1685023 3096214 5556282 9732049
20 27 37 61 114 218 416 815 1700 3806 8912 21041 48724 109025 234339 483377 958252 1830189 3377111 6037213 10483638
0 13 36 73 134 248 489 1018 2144 4402 8643 16149 28862 50022 85992 151103 279532 552483 1156778 2504561 5466066
7 5 0 -5 0 33 133 396 1045 2545 5774 12261 24502 46365 83595 144430 240339 386893 604780 920975 1370076
13 9 9 34 128 365 862 1820 3630 7095 13832 26934 52012 98876 184552 339505 621668 1148550 2168444 4210603 8385165
-5 -12 -23 -30 -18 35 158 387 765 1342 2175 3328 4872 6885 9452 12665 16623 21432 27205 34062 42130
5 9 17 39 105 283 715 1694 3815 8241 17147 34472 67267 128237 240613 447347 827905 1527761 2808205 5127421 9268133
25 37 57 106 230 518 1137 2397 4859 9508 18054 33532 61594 113281 210702 398013 761477 1464303 2804527 5307542 9869150
11 17 46 114 241 455 798 1334 2159 3413 5294 8074 12117 17899 26030 37278 52595 73145 100334 135842 181657
4 -1 -4 12 78 257 677 1583 3423 7014 13911 27274 53877 108552 223482 466589 976170 2023577 4123518 8225636 16048444
0 1 0 -3 -8 -15 -24 -35 -48 -63 -80 -99 -120 -143 -168 -195 -224 -255 -288 -323 -360
11 18 29 49 92 206 522 1339 3257 7370 15531 30701 57394 102230 174608 287511 458455 710594 1073993 1587081 2298296
13 15 9 -12 -48 -79 -45 193 934 2793 6973 15712 33032 66133 128347 245886 473338 927958 1861532 3802331 7819427
2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82
11 27 52 97 186 362 709 1407 2852 5898 12324 25725 53226 108808 219736 438752 866576 1692276 3264166 6213201 11668991
4 13 42 103 207 362 569 822 1123 1528 2245 3810 7372 15123 30914 61103 115686 209767 365428 614065 999261
15 21 37 86 203 434 831 1439 2272 3276 4278 4921 4586 2303 -3346 -14328 -33259 -63497 -109221 -175488 -268259
11 16 28 64 160 393 913 1979 3985 7464 13083 21703 34688 54819 88416 149606 268111 502480 961366 1836266 3450112
19 28 52 114 257 565 1198 2452 4861 9361 17538 31985 56799 98260 165752 273013 439839 694418 1076536 1641980 2468565
15 15 13 12 12 1 -45 -137 -191 184 2178 8829 27103 71775 172317 384631 810367 1627833 3140255 5849526 10566770
12 11 5 -6 -22 -43 -69 -100 -136 -177 -223 -274 -330 -391 -457 -528 -604 -685 -771 -862 -958
14 26 38 50 62 74 86 98 110 122 134 146 158 170 182 194 206 218 230 242 254
13 19 31 63 138 294 607 1239 2530 5172 10540 21334 42843 85426 169298 333601 653532 1273267 2471552 4797589 9360217
11 3 -4 4 47 149 343 691 1325 2507 4689 8539 14934 25131 41979 74636 152691 362315 929342 2395398 5968245
18 22 40 91 193 361 613 998 1668 3038 6128 13283 29669 66335 146381 317205 674569 1409654 2901085 5895585 11864268
11 37 82 161 309 586 1087 1974 3560 6490 12081 22905 43732 83003 155088 283716 507161 886051 1515060 2540273 4184711
25 39 52 67 92 144 269 587 1366 3134 6880 14520 30088 62684 133303 289715 637379 1401437 3047748 6514061 13642856
4 -4 -20 -50 -102 -185 -302 -435 -512 -331 602 3393 10381 26381 61265 135375 290656 612718 1272684 2603156 5230544
16 37 62 103 197 413 863 1725 3295 6108 11215 20791 39404 76543 151493 302640 605473 1208410 2406047 4790866 9565986
18 28 36 48 72 117 192 305 462 666 916 1206 1524 1851 2160 2415 2570 2568 2340 1804 864
6 31 75 155 307 590 1091 1932 3290 5463 9049 15351 27179 50290 95789 183908 349686 651191 1181055 2082235 3569067
13 24 44 80 152 311 679 1524 3380 7215 14639 28129 51229 88660 146248 230547 347999 503434 697670 923926 1162710
10 22 32 51 114 303 788 1898 4249 8981 18195 35742 68605 129235 239371 436181 782284 1383028 2418714 4208909 7345156
7 30 81 174 320 532 841 1335 2242 4084 7930 15770 31017 59118 108216 189751 318817 514002 796327 1186766 1701670
14 27 59 134 293 607 1198 2270 4163 7468 13293 23865 43815 82762 160259 314926 620952 1217673 2362755 4528740 8580085
8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88
8 0 -4 18 98 273 583 1076 1829 3005 4987 8667 16029 31260 62764 126655 252582 493110 938366 1738280 3135532
-3 4 19 42 73 112 159 214 277 348 427 514 609 712 823 942 1069 1204 1347 1498 1657
14 24 32 37 53 130 397 1139 2922 6787 14546 29230 55761 101947 179931 308262 514798 840698 1345812 2115835 3271653
7 23 56 112 206 369 661 1190 2131 3727 6237 9780 14024 17718 18228 11631 -5265 -28077 -27602 87844 547546
23 36 62 118 231 444 832 1544 2899 5581 11011 22063 44521 90194 183657 376560 777027 1608138 3321360 6812948 13832967
8 0 -5 4 43 136 319 644 1176 1961 2930 3727 3573 1607 -1170 4025 48104 214582 698717 1914790 4680631
6 17 37 64 93 116 122 97 24 -117 -349 -698 -1193 -1866 -2752 -3889 -5318 -7083 -9231 -11812 -14879
-2 -7 -2 33 136 369 821 1608 2870 4765 7460 11119 15888 21877 29139 37646 47262 57713 68554 79133 88552
18 20 30 66 151 310 570 972 1603 2653 4499 7817 13726 23977 41217 69385 114336 184842 294188 462668 721393
3 0 -3 -6 -9 -12 -15 -18 -21 -24 -27 -30 -33 -36 -39 -42 -45 -48 -51 -54 -57
16 28 38 46 52 56 58 58 56 52 46 38 28 16 2 -14 -32 -52 -74 -98 -124
"""
solution09_1 = fn input ->
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
line |> String.split(" ", trim: true) |> Enum.map(&String.to_integer/1)
end)
|> Enum.map(fn nums ->
Stream.unfold(nums, fn nums ->
if nums |> Enum.all?(fn n -> n == 0 end) do
nil
else
{nums,
nums
|> Enum.chunk_every(2, 1, :discard)
|> Enum.map(fn [a, b] -> b - a end)}
end
end)
|> Enum.reverse()
|> Enum.reduce(0, fn nums, acc ->
acc + (nums |> List.last())
end)
end)
|> Enum.sum()
end
solution09_1.(sample09_1)
solution09_1.(input09_1)
Day 9 - Part 2
sample09_2 = sample09_1
input09_2 = input09_1
solution09_2 = fn input ->
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
line |> String.split(" ", trim: true) |> Enum.map(&String.to_integer/1) |> Enum.reverse()
end)
|> Enum.map(fn nums ->
Stream.unfold(nums, fn nums ->
if nums |> Enum.all?(fn n -> n == 0 end) do
nil
else
{nums,
nums
|> Enum.chunk_every(2, 1, :discard)
|> Enum.map(fn [a, b] -> b - a end)}
end
end)
|> Enum.reverse()
|> Enum.reduce(0, fn nums, acc ->
acc + (nums |> List.last())
end)
end)
|> Enum.sum()
end
solution09_2.(sample09_2)
solution09_2.(input09_2)
Day 10 - Part 1
sample10_1 = """
..F7.
.FJ|.
SJ.L7
|F--J
LJ...
"""
input10_1 = """
FJ7.FF--|--|-|J.FL7FL7LJ7F7-F.-7.FF7F|F-JJ-F----JF77.-JJFJ--|7FF7L-7.--LF.FJ-FL7JFF-77|F----F-|-F77LJ---F-L-L-77-.FJ.F77FJF7.LFJ7-|.FF-7--7.
7.L--7|.|.||F7L7J.L7L7LLF-JFJ7JL-JL77L7|||.J-JF|LFFJ-JJFLJ..7-7-J7|.FL-|LF||.----L.|JF|7JL-L-7|7.L-.F-7---J-L-J|LLJ.-F--|LFL7-F.J7L|J.F|J||7
L.|L|L--.7J||JF777-J-7JF7LFJJ|-J-|-|7F-7F7-|J7L|-FF..L7L|.F7L7.FL7JFL7-|--F-7LF.FJ.7.LJ-F--F|F7--.L77.|-LF7.|-L||FF7.7FLF7.L|-7-F7||.--|--LJ
.LF7..|77L-L7J|.LF7.FF-LJFJJ7L7JFJJ.7JL|||.L.F7LF7.L.L-||7F7.LLF-7.LLL7J||LF7F|.LJFF7F|-LJ.-J|L7.J7F7F|.LFJ7JF.LJ7.F-|7L7JF-|-J-J.F7F|7|-7J.
.FFJF-JLLJ7.L7-.JLF-FJJ7F7|F7.JJL-L|.|FL|J7L|JF7.L7L|J.L|-F777-7.F-J-LF-F7.7JF|7|F------JJF..J|L.FL||77--.FF7J7|77.|.LL.J-L-L-L7LFFJFJ-JL|LF
F77|-|7J|L-7FF77LF|-J7-L7J|-JF|.L7.F---|LF7F7J|L7.|-|LF7|FJL-7FF7J7-FF|F7-FL-F-7-JJ--7F7.FL7.FLJ|7-||F7LFF-J|F-J-77J.L|F|7FFJ.-7.77-J.||FLF7
F-7F7.7-L-J7||F7||.LJJ.LJ7LJ-|LJ-77.LL-F7||||FJFJ7JF|--J7|F-7L7||77.FJ|L||||7L7L7JJ-|LF7FF7F7F7F-7FJ|||F7L-7|7J.LJ||FJL7L|F-7.L|-|L-.FF|7.LL
LFLJ|-7..-JL-F-7-77JLJ7JL-77.L7J-F7F7LFJLJ||||FJ77-FL7|L-||-L7LJ|JF7L7-LF-7F7-L7L-7F--J|-F-JFLLL7|L7||LJL7FJL777J-7F|-F|JLL-7-.|FLJ77F7||-F.
-L7L7L7.FLJ|JL.LF|J|7L|FJF----F-7|||L7L--7||LJL--77L|LJ7JLJ-F|F-JF-7-F7-L7LJL7FJF-JL--7L-7LF7L|-|L7|||F--JL-7L77|7FLJFJJ7.FFJLL|F|.L7LL7|.-J
.|-.F-.F|JL7-J.F|LF-F7-7L7F--LL7LJLJFJF77|||F----J77|.||7JLF7|||LL7|J||7-L--7|L7L7F7F-JF-JFJL7--L7||LJL---7||FJJFFJJ-J7FJ7-J-7JJ-77||.|-LL77
7|7.||.-7.J|LJFJL7..LL7|F7-7JF7L--7FJFJ|FJLJ|F7F7LF77-J|F--JLJL7-FJ|FJL7F7-|||FJFJ||L-7L7FJF-J|7FJ|L7F----J-|L-7.|.L7LJJ|F7L-7--JF7JJ.77-L-F
F|77FJ77L7-|..|.7J7F|JLL|--F-JL---JL7L7LJF--J|||L7||J7LLL7F---7|FJFJL-7LJL7FJ|L7|FJL-7|FJL7|F7F7L7|FJ|F7F-7FJF-JF77F|7L7-LLLJL-|-|J|7----L-J
LLF-|-77-LFJJ.7.L|FF-F.|L|FJF7F----7L7L-7L-7F|||FJ||F7-7|LJF--J||FJF-7|F--JL7|FJLJF--J||F7|LJLJ|FJLJFJ|||FJ|FJF7||JFF77F7.L.FL-F.|.LJLL|JLF7
.|LLLJ.|-F7|.F|--|-J7|-|-LL-JLJF--7|FJLFJF-JFJLJL-JL7LLF7LLL7F7LJL7|FJ|L-7F7||L--7L7F-JLJ||F--7LJF--J-|LJL-J|FJLJ|F7||7.|..--7-|7.L-F7JLFJ|J
LJ7JLF-L7JL--L7JFJLJ-|LLJ|LF---JF7LJ|F7L7L7F|F7F7F--J--||7.FJ|L-7FJ||FJF-J||||7F7L7LJF--7|LJF7L-7|F--7|F7F--JL7F-J|||L-7F77JFJ.||.|FJJJ.|-JJ
.---7LLLJL--7-JFLJF7-77J.-7L-7F-JL7FJ||-L7L-J||||L7F77FJ|F7L-JF-J|FJ|L7L7FJLJL-J|FJF7L-7LJF-J||FJLJF-JLJ||F7F7||7FJ||F-J||7-L-F-77FF7.F-|.L|
-7.FL7.|L7|.|JL-J.F77LF-7LF-7LJ7F7||.||F-JF--J||L7||L7|FJ||J|FL-7||FJFJFJL---7F-J|FJ|F7L-7L-7L-JF7FJF7F7|||LJLJL-JFJ|L7FJL7.LFJ.L||.|-7-F77F
F77|J|F|LJ7-F7|L7-JL-FJFJFJFJF--JLJL-J||F7L--7|L7||L7||L7|L-7F-7|||L7L7|LF-7FJL7FJ|LLJL--JF7L-7FJ|L7||||||L--7F---JF|FJ|F-JF7-F7-|7-|7|FL-7|
LLL--L-L7-77LJ--||LJ.L7L7|FJ.L---7F-7FJLJ|F--JL-JLJ||LJFJ|F-JL7LJLJFJFJL7|FJL-7LJFJF-7LF7FJL7FJL7L-J||||||F7FJL7F7JFJL7||F7|L-JL7L|7J-7J.L|J
FJ.J7LFL|-JF|.|FL-LF||L7|||F7F7F7||.LJF7FJL-7F7F7FF7L-7L7|L7F7L7F--JLL-7||L--7L7FJL|FJFJ|L7FJL7FJF7||LJ|||||L-7LJL7L-7LJ||||F---J-FJ-|.L77||
|J-L---|L.||JFJ.|.FLFF-JLJLJ||||LJL-7.||L-7FJ|LJ|FJL-7L7||FJ|L-JL7F7JF7|||F--JL|||FJL7L7|7||F7|L-JL7|F-J||||F7|F--JF-JF7LJLJL-7FF7||.77.-LFJ
L-7L|77FF-7LFJL-77|J|L-----7LJ|L-7F-JFJL--JL7|F-JL7F-J||LJ|FL---7||L7|LJLJ|F7F-JL7|F-JFJ|FJ|||L7F--J|L7FJ||||LJ|F7FJF-JL------JFJ|JJ7..F|-|7
|.FJLLLJ|FLJ|.7J.||.F-----7L-7L--JL-7L-7F-7FJ||F-7|L7F7L-7L-7F--J||FJL-7F-J||L--7LJL7FL7|L7LJ|J|L-7-|FJ|FJ||L-7LJ|L7|7F--------JFJ|7F7.L7-7J
FJ7FFJL||JJF--L7-L7-L----7|F7L---7F-JF7LJFJL-J|L7||FJ||FFJF-JL--7||L-7J|L--J|F--JF--JF-JL7L-7L7|F-JFJ|FJ|FJ|F-JF-J-|L-JF7F----7FJJ-|7JF|J.|7
7..J7|FFL7F|7.FF7-F--7F--JLJL7F7J||.FJ|LFJF---JFJLJL7|L-JFJ|F7F-JLJF-JFJF---JL7F7L7F7L--7|F7|FJ|L-7|FJ|FJL7|L-7L7F-JF--J|L---7|L7J-JL-F.L7L7
7--7L--7JFJL7|7|||L-7|L-----7|||FJL7L7|FJFJJF-7L--7FJL--7L-7||L--7FJF7L7L7LF7LLJ|FJ||F7FJ||LJL7L7FJ||7|L7FJ|F7|FJL-7|-F7L----JL-J|.JF|F-7.-.
|FJ|7J|F-|JLF7FJL7F-JL7F----J|||L7FJ7||L7L--JFJ|F7|L-7F-JF-J|L7F-J|7||FL7|FJL-7FJL7||||L7|L-7FJFJL-JL7|FJ|FJ|LJ|F7.|L7|L7F---7F7LL7LL7L7.|.F
FL7LL-FJ.|7.|LJF-JL--7|L----7LJL7||LFJL-JF---JF-J||F-JL-7|F7L7|L-7L-JL7.|||F--JL-7|||||FJL7F||FL7F-7FJ|L-JL7L-7||L7|FJ|FJ|F--J|L7L|.F|7LJ---
JJF.L-7J7.--L-7L7JF-7|L-7F-7L7F7LJL7L---7L---7L-7|||F7F7|LJ|FJL7J|F--7|FJ|||F7F--JLJ|||L-7|FJL7FJL7LJ||F---JF-J|L7LJL7|L-JL---JFJJLJ7LJ..F.J
F-L7..|JLJLF-7L7||L7LJF-JL7L7LJL7F-J.F7FJF---J-FJLJLJ||LJF-JL-7|FJL7-LJL7||LJ|L--7F7LJL7FJ|L7FJ|F-J|F7||F7F7L-7|FJF-7LJF7F7F7F7L7||.-7.77LJJ
LJ-L7-F.FJFL7L-JL7FJF7L-7FL7L---JL-7FJ|L7L-7|F7L--7F-JL7FJF-7FJ|L7FJF7JFJLJF-JJF7||L---JL7L7|L-JL7F7|LJ|||||F-JLJFJ.L7FJLJLJLJL-JFFF---77|7|
|F7L|-LFJ||FJF--7|L-J|F-JF7|F----7FJL7|FJF-JFJ|F7FJ|F7FJL7|FJL7L7|L7|L7|F-7L-7FJ||L7F7F7FJFJL7F-7LJLJF-J|||||F---JF7FJL---7FF7F7F7F7F|7LF7-J
L-7F7..|.F7L-JF7||F7FJ|F7|LJ|F---JL7FJ||FJF7L7|||L7||||F-J|L7-|FJL7||FJLJJL7FJL7||FJ||||L7L7FJ|FJF---JF7|||LJL---7||L7F7F7L-JLJLJLJL-77.-|||
FJ7FL7JFF||F7FJLJ|||L7|||L--JL----7|L7LJ|FJ|FJ||L7|LJ|||F7L7L7|L7FJ||L7F7F7||F7|||L7||||FJFJL-JL7L7F-7|LJ||F-----J|L7|||||F--7F7F---7|JFJL7|
FJF--7|F7|||||F-7|||FJ|||-F7F7F---JL7|F-J|FJL7|L7|L7FJ||||7|FJ|FJL7|L7||||||||||||FJ|||||FJFF7F7|FJL7|L-7LJL----7FJFJLJLJLJ.FJ|||7LLLJJF7|L|
|LJL7LFJLJLJLJL7||||L7||L7|||LJF---7|||F7|L7FJ|FJL7||FJLJL7||FJ|F7|L7|||||LJ||||||L7|||||L7FJLJ|||F7|L7FJF7F-7F7LJFJF7LF---7L-JLJ77FLF7L|77|
L77F|FL-7F-7F--J|LJL7||L7|||L--JF--J||||||FJ|FJ|JFJ||L7F--J|||FJ||L7||||||7FJ|LJ||7||||||L|L-7FJ||||L7||FJLJ.LJL--JFJL7|F--J.F--7JL||||F7L7|
|LJ-|JJFJL7||F--JF-7LJ|FJLJ|F7F7L--7LJLJ||L7|L7L7L7||FJL7F7|LJL7|L-J||LJ|L7|FJF-JL7|||||L7|F-J|FJ|||FJLJL---7F7|F--JF-J|L--7FJF7|LF|7|L7J-LF
|LF|J7FL7FJ||L---J7L7FJL-7FJ|LJL-7FL---7||FJL7L7|FJ|LJLFJ|LJJF7||F--JL7FJFJ||JL7F7||||||FJ||-FJ|JLJ||7F7FF-7LJL-JF-7L--JF-7||FJLJLFF7|FJ..L.
LJLF.FF-JL7LJJF7F7F7||F--JL7L---7L----7|LJL-7|FJ||FJF-7L7L--7|LJ|L-7F7|L7L7||F-J||||||||L7|L7L7|F--J|FJ|FJ|L7F--7L7L---7L7LJ|L-7JF-JLJ|F7-FF
|7|JF|L---JF--JLJLJLJLJF--7L7F7-L---7FJL7F--J||FJ|L7L7L-JF--J|F7L7FJ|LJLL7||||F-J||LJLJL-J|FJFJ||F7FJL7|L--7LJF7L-JF--7L-JF7|F-J7L7F--J||-F7
77LF7|7.|JLL7F-----7F--JF7L7LJL-----JL--JL7F7|||FJFJJL7F7L--7|||FJL7L--7FJ|||||F-JL------7|L7L7|LJ||F-JL7F7L-7|L---JF-J7F7||||F7-FJ|F--J|-J|
FL7.J.FJ|J|-LJF----J|F--JL-JF----7F7F--7F7||LJLJL-JFF7|||F7FJ||||F7|F-7|L7|LJLJL-7F--7F-7|L7|7LJF7LJL--7LJL--J|F---7L---JLJLJLJL7L7LJF--JJ7J
JJ-77-J7LFFF--JF--7FJL7F-7F7|F--7LJLJF-J||LJF7F7F--7|LJ|||LJ.LJ|||LJL7|L7||F-----JL7FJL7||FJ|F--JL7LF-7L------JL--7L7F------7F-7L-JF-JLF|-F7
L|JL|L|F.F7L--7|F-J|F-JL7LJLJL-7L----J.FJ|FFJLJLJF7||F-J||F----J||F7FJ|FJ||L-7F7F7FJL--JLJL7|L7F-7L7|FJF7F--------J.LJFF77F7LJJ|F-7|7FFL77L|
FL7-J-FF-JL---J||F7|L7F-JF-----JF7F7JF7|FJFJF-7F-J||||F-J|L7F7F-JLJ|L7||7||F-J||||L---7F--7||FJ|FL7LJL-J|L-------------JL-JL--7LJF|L7-7J.L7|
FLL7LJFL-----7FJ||LJ7LJF7L-7F7F-JLJL-J|||FJFJFJL-7||LJL7FJFLJ||F7-FJFJ|L7LJL-7|LJ|F--7LJF7|LJL-JF7L7F7F7L---7F7F---7F---7F-7F-J-F-JFJ--7FLF-
L|FLJ.F-7F---J|J||7F---JL7J||||F-7F---J|LJFJ-L-7FJLJLF-J|F---JLJL7|FJ|L7L7F--J|F-J|F7|F-JLJ|F---JL7LJ||L---7LJLJF-7|L--7||FJL--7L7FJJL|L7|||
L-|7FFL7LJF--7|FJL7L7F--7L-J|LJL7|L7F7F|F-JF7F7LJF77FJF-JL7F7F-7FJ|L--7|FJ|F-7||F7LJ||L----7L----7L--J|F---JF---JFJL7F7||||F7F7L7LJ-F-F7L|FL
L|LL-F-JF7|F-J||F7L7||F-JF-7|F--JL-J|L-JL--JLJL-7|L7L7|F--J|LJFJ|L|F7FJ|L7||FJ|||L7FJ|F7F7FJF----JF7F7|L-7LFJF---JF7||||LJ||LJL7L-7.LLJFFJJ|
7J77LL--J|||F7||||FJLJL--JLLJL------JF---------7LJFJ|LJL--7L7F|FJFJ|LJ|L-JLJL-J|L7||F|||||L7|F7F7FJLJLJF7L7|FJF7F7||LJLJF7|L--7|F-J.F|-L.|FJ
|-FF7JJ|LLJ||LJ||LJF7FF---7-F7F---7F7L-------7FJF7|F--7F--JFJFJ|-L7L---7F------JFJLJFJ||||FJLJLJLJF7F7FJL-J|L-JLJLJL7F7FJ||F7FJ|L7J.FJ-|7FF|
F.F7J7LFJ-LLJF7LJLFJL7L--7L-JLJF-7LJL--------JL-J|LJF-JL7F7L7L7L-7|F---JL7F-7F7FJ7F-JFJ||||F---7F-JLJLJF---JF----7F7||||FJLJLJ-L-J.7J|JL-F-|
|FL|.L7.|J|.FJL--7L-7|F-7L----7|FJF7F--------7F-7|F7|F7J||L-J-L7FJLJF7LF7|L7LJ|L-7L-7|FJ|LJL--7|L7F7F--JFF-7L---7LJ|||LJL7|F7F7F-7-|F--J7|.|
|FFJFJLJJ.FFJF7F7L7FJ||FJF----J||FJ||F-------J|FJLJLJ|L7||F7LF-J|F--JL7|LJFJF-JF-JF-J|L7L7|F7FJL7||LJF7F-J-L----JF7LJ|F-7L-JLJLJFJ-|7JJJFLF7
L|7FJ7FJLLFL-J||L7|L7||L-JF-7F7|LJ-LJL-7.F7F7-||FF7LFJFJ|||L-JF7LJF7F7|L-7|JL-7L-7L-7|L|FJFJ|L-7|LJF7||L------7F7|L7FJL7L---7F--JJ7LL||.77J|
|..FJFJ7--77FFLJFJL-J|L---J|LJLJF------JFJLJL-JL7||FJFJFJ||F7FJL7FJLJ||F7LJF7FJF7|F-J|FJ|FJFJF7|L--J|||F7F7F--J|||FJ|F-JF--7LJLFJF|---|-F77J
.FFLJFL|FF||-FF-JF7F7L----7F--7.L-------JF---7F-J|LJFJ.L-J||||F-JL-7FJLJL7FJLJFJ||L-7|L7|L7L-J|L---7LJLJLJ|L--7|||L-JL7||F-J-F77LJ|FF|LF7||.
-F77.L7LL--.FLL7FJLJL---7FJL-7|F7F7F--7F7L--7|L--JF-JF7F7-LJ||L7F7FJL7F--JL7F7L7|L7LLJFLJJL--7L7FF7L7F7F-7L---J|LJF7F7L-JL--7|L-7JL-FL-J-7L7
|FLF-L7..|.F-7LLJF------JL-7FJ||LJLJF7LJ|F7FJ|F7F7L--JLJL--7LJFJ|LJF-JL---7||L7||FJF7F7F7F7F7L7L-JL7|||L7L----7|F-J|||F-----J|F-J|L7|J-LJJFJ
7|.....F-LL.LJ7F7L----7F7F7||FJL----JL-7||LJ|||LJ|F7F--7F--JF7L7L-7L7F7F7FJS|-||||FJLJLJLJLJL-JF7F7|LJL-JF----J|L-7LJLJF7FF7FJL7F7FF777|||FJ
FJ77FF-7-.|.|-FJL-----J|LJ|LJL---------J|L--7LJF7||LJF7LJF7-||JL7FJF||||||FJL7LJ|||F7F7F---7F7FJLJ||F-7F7L-----JF7L----JL7|||F7LJ|FJ|-7--7JF
LL7JLJ.||L7F-J|F-7F----JF7L------7F--7F7L--7|F-J||L7FJL7J|L-JL77LJ-FJ||||||F7|-F||LJ||||F--J|LJF7F||L7LJ|F7F7F7FJ|F-7F7F7LJ|||L--J|FJ7|L|J.-
|LJ7L-L7||-FLFJ|FJ|F----JL-7F7|F7LJF7LJL-7LLJ|F-JL7LJF7L-JF7F7L7.J-L7|LJLJLJ||F-J|F-J|LJL7F7|F-JL-JL-JF7LJ|||||||LJFLJ||L7FJ||F---J|JL|F|7.|
.F7FF7L---7.FL7|L7|L------7LJL-JL--J|F--7L---JL-7JL7FJ|F7FJ||L-J77|FJL-77|LF|||F-JL--J||.LJLJL7F-7F7F7|L-7LJLJ|L--7F-7||FJL-JLJF-7FJ|LL-J7F7
7JL|J7FLL.LFF.LJFLJF7F7F7|L--------7LJF7L----7F7L7-||JLJ|||LJJJJL-FL7F-J-JF-LJLJLLJFL-F--7F--7LJFJ|LJLJF-JF7F7L--7LJFJ||L7F-7F7L7LJF77F||L-7
|.LL7-J7|777|-L|-FFJLJ||L----------JF7|L----7||L-JFJL--7||7.J7..F-|-LJJFF|-LJFJ77J.F|-L-7|L7FJF7L-JF7F7L--JLJL7F7L--JFJ|FJL7LJL7L--JL7--J7JJ
--|J.|LJ--L7-F--7FJF-7LJF-7F-7F-7F--JLJF7F--JLJ7F7L7F--JLJF7F-L-|-|-J.|-FF7LL|J-LF-7F7|FJL-JL-JL-7FJLJL----7F7LJL---7L7||F7L--7L---7FJFJF|77
.F..-7JFL-J7FL-7LJFJ7L7FJFJ|-LJ-LJ7F---J|||F---7|L7LJJF7F7|L7J7J|7JFL-F7JL-JLLJ|LL7LJL7L--------7|L----7F-7||L7F----JLLJ||L7F-JJF7LLJL|J|LJ|
FF-7F|FL.|--7.FJF-JF--JL7L-JF-----7L--7FLJFJF-7LJFJF7FJLJLJFJFL-|.F|FJL|FJ.F7LJ-|JL7F7L---------J|JF7F7||FJLJFJL-------7|L7|L---JL---7J||-F|
F77|FF-F-7|.L7L-JF7|F-7FJF77L----7|F-7L7F7L7L7|F-JF|||F----JLJ|JL|-LLJ.F||LLLJLL-7J||L----------7L-JLJ|LJ|F7JL---------JL-JL7F7F7F7F7L-7J7J.
LLFJ-F.|.LL-J-F--J|LJ7||FJL----7FJLJJL7LJL-JFJLJF-7|||L---7LF.|7JL|JFF7.77J.|7F77|FLJLF--7F----7L----7L--J|L7F-7LF--7JF7F--7||||||LJ|F-J7L..
.F-7FJ7|FL|L7FL--7|7F-J|L-----7|L----7|F7F--JFF7L7LJLJF---J-7JJ7FFL7J-JL7|LJL7LFF----7L-7|L-7F7L7F--7L----JFJ|FJFJF-JFJ||F-JLJLJ||JLLJ|FF-J7
FL-J7.JFF--7F--7FJ|FJF-JF7FF7FJL-----JLJ|L--7FJ|.L7F--J-F7.||7.F-JJJ-|.FL77.F7.FL---7|F7|L7-LJL7|L-7|F7F---JFJL-JFJF7L7LJL-----7LJ||LLL-JFJF
7FF7F|7LJLLLL-7|L7|L-JF-JL-JLJF7F--7F-7.L---J|FJF7|L---7|L-7|FFLL-|.FF--7L-|---F-7F-J||||FJF-7FJ|F-J|||L----JF7F-JFJL7|F7F7F7F7L-7-7JFLJ.|L|
L-|L|.F7F7JLF-JL-JL7F7L-------JLJF7LJFJF---7FJ|-|||F--7LJF-JF-7LL7LF7LLJJFL|||.L7|L-7LJ||||L7|L7LJF7LJL-----7|||F7L-7|||LJLJLJL7FJ-7-7LF7-FF
J.JL|.LJJ|..L--7F-7LJL7|F7FF7F7F7|L--JFJF7FJ|FJFJ||L-7L-7L7F7JJFFF-|L7-|.FJ|F|FFJL7JL-7LJL7FJL-JF-JL7F-----7||||||F7|LJL------7||JFJ-JL|JL||
F|7-|--L--F7|F7||FL7F7L-JL-JLJLJLJF--7|FJLJFJL7L7||F7L-7L7LJL7JFJ.F-77.L--.FF-7L-7|F-7L--7LJF7F7L7F-J|F----J|||LJLJLJF--7F7F--JLJL-77LF7.L7-
FJ-F|LLJFL||FJLJL7FJ|L---7F7F-7F-7|F-J|L--7|F7L-JLJ||F-JF|F-7|J-L7F.|J-|L|..L7|F-J|L7L---JF7||||FJL--JL----7LJL-7F---JF7LJLJF7F7J7.L|FJ.|.J7
.J|LJL|JL7||L----JL-JF7F-J|LJ-LJJLJL--JF--JLJL7F7F7||L-7FJL7LJ-FJFJF|..|-FF7FJ|L7FJLL-----J||LJLJF7F---77F-JF-7FJ|F7F-JL7F7FJ|||F7JL|7-7LF7|
.FJ-77J.|7|L7F-7F----JLJF7|F-7|F-------JF7F7F7||LJLJL--JL--J7J.|---FLF77-FJ|L7|FJL-7F------JL7F--JLJF-7L7L-7|FJL7||||F-7LJ|L7|||||-F|JLL.LF7
FL-|LF.FF-JFJ|FJL7F-----JLJL7L-JF---7F7.||||||||F7|F7F-----7F7.|.LF7..LF-JFJFJ||F--JL--7F-7F-JL----7|FL7L--J||F7LJ|||L7L7FJFJLJLJL--7-7L-.F|
JJF|-L-FJF7|FJL7FJ|F-------7L7F-JF--J|L7|||||LJLJL-J||F-7F-J|L7-F-J|7FLL-7|LL7LJL7.F7F7LJFJ|F---7F-J|F-JF---JLJ|F7|||FJL|L7|F7F7F-7FJ7LJ|.JJ
L|F|F--L-J|LJF-J|FJL7F7F7F7L7LJF7L---JFJ|||||F7F-7F7LJL7|L7FJFJLL-7|F7F7FJL7JL-7FJFJ||L7FJFJL-7FJL-7|L--JF7F7F7LJLJLJL-7L-J||LJ||FJL77J.FLLF
F|J|LJFJJL|F7L-7LJF7||||LJL7L--JL----7L-JLJLJ||L7|||F--JL-JL7L7F-7|LJLJ||F7|F7FJL7|FJL7|L7|F7FJL7F7LJF---JLJLJ|F7F7F7F7L---JL-7||L-7L-7-L-|J
L--7..L7F-LJL7FJF-J|LJLJF-7L7F-7F---7L7F7F--7||FJ|||L-7F7F7LL7LJFJL-7F-JLJ|LJ|L-7|||F7||LLJ|||F7LJL7FL-------7LJ||||||L----7F7|||JJL--J-J-F7
LLLF-F--.FJLFJL-JF7L77F7L7||LJF||F--J-LJ|L-7|||L7LJL--J|LJ|F-JF-JF7L||F7F7L-7L7-|||||||L-7FJ|LJL7F7L-7F-----7|F7LJ|||L----7LJ||LJJ-|FJ7|LF-7
.LL|LJ-|.7|.L7F7FJL7L-J|FJL----J|L---7F7L--JLJL7|F---7FJF-JL7FJF7||FJ|||||F7L7|FJLJLJLJF7|L7|FF-J||F7LJF---7|||L-7LJL7F7F-JF7LJJF|-L7L|-7|L.
FF7J||7L-7FF|||LJF-JF-7LJF---7F7|F--7||L----7F7LJL7F-JL7L7|FJL7||||L7|||||||FJ|L-7F--7FJLJFJL7L--JLJ|F7|F--J|||F-J-F7LJ||F-JL---7J--7J|LJ7|.
F77-|JLJFFF--JL-7L-7|-L--JF--J||||F7LJ|F----J|L--7|L--7L7L7|F-J|||||||||||||L7L7FJL-7|||F7|F7L----7FJ|LJL7F7LJ||JF7||F7|LJF----7|JJ7|J|LJJL-
-JJF|.|F-FJF---7|F-J|F-7F7|F7FJLJLJL--JL----7L-7FJ|F-7||L7|||F7|||L7|LJ|||||7|FJL7F7|||FJ|LJL---7FJL-JF-7LJL-7|L-JLJLJ|L-7L---7LJ.LF7-F-|.LL
LJ.7.|.LJL-JJF7LJL--JL7LJ|LJLJ|F-----7F--7F-JF7||||L7LJF7|||||||||FJ|F-J|LJL-JL77||LJLJ|FJF-----JL7F77L7L----J|F---7F7L-7L--7FJF77-|L7JF-LJ.
JFLL--7L-L7LF|L7F7F---JF7L-7F-7|F--7FJL-7|L7J|||L7L7L7FJLJ||||LJ|||FJL-7|F7F7F7|FJL7J|FJ|FJF-----7|||F7L------JL--7LJ|F7L--7LJ.||F7|FJ77J|.-
|7.|-7J.L|-FFL7LJLJF---JL-7|L7|LJF-JL---J|FJFJ||FJ7|FJL--7|||L-7|||L7F-JLJLJLJ|||F7L7FJFJL7|F---7||||||F----7F-7F-JF7LJL7F7L7F7|LJLJL7J|FF|J
J.L--LJ-F|FF-7L----JF---7FJL-J|F7L-----7FJL7L7|||F-JL7F7FJ|||F7|||L-J|F-7F7F7FJ|||L-J|FJF7LJL--7LJLJLJ|L---7LJFJL--JL--7||L7LJLJF7F7FJJLF.|.
FL.L-7|-|.LL7|F--7F7L--7||F--7LJ|F7F---J|F7|FJ|||L--7|||L7LJ||LJ||F7FJL7LJ|||L7||L7F7||FJL7F7F-JF----7L----JF7L----7F--J||7L-7F-JLJLJL7|L-LJ
|F|7F7FFF7JFJ||F7LJ|7F-J|LJF7L-7LJLJF7F7LJLJL7LJ|F--J||L7L7FJ|F-J||LJF7|F7LJ|FJLJFJ|||||F-J|LJF-JF--7|F7F---J|F---7|L--7|L7F-JL-77J|L-F7.||.
F--J|.F7||FJFJLJL-7L7L-7|F7|L--JF7F-JLJL--7F-JF-JL7F7||FJ|||FJL7FJL7FJ|LJL-7|L-7FJ7|||LJ|F7L-7L77L-7LJ|||F7F7LJF7FJ|F--JL-J|F7F-JJF7FFJL-|7.
.|L7-FJLJLJFJFF-7-L7L7L||||L-7F7|LJF----7FJL-7|F-7LJ|LJL7FJ||F7|L7FJ|FJF7F7|L--JL-7|||F-J||F7L-JF7FL-7|LJ|LJL--JLJ7LJLF---7||||F7|L.|L-JJJ|J
FL-77L--7F7L--JFJF-JFJFJLJL7FJ|LJF-JF-7FLJF--J||FJF7L7F-JL7|||LJ||L7|||||||L7F-7F7||LJL-7|LJL7F-JL-7FJ|F-JF7.F7F7F7|F7|F--J|||LJL7FFL7J77...
FJLLLJ|-LJ|F7F7L7L-7L7L---7|L-JF7L--JFJF77L--7||L7||FJL-7J|||L-7FJFJ|L7|||L7LJFJ|LJL-7F7||F-7|L7F7FJL-JL-7|L7|LJLJL7|LJL-7JLJ|F-7L77||.--F77
7L-.FL7-|L||LJL7L7FJFJF---JL---J|F---JFJL7F7FJ|L7|||L7F-JFJ||F7||FJ-L7||||FJF7L7|-F7FJ|LJ|L7LJFLJ||F--7F-J|FJ|F7F-7LJF---JF7J|L7L-J.F|-|-L77
L-7LFF-.-FJL--7L7|L7L-JF7F-7F--7||F--7|F-J|LJFJ7|||L-J|F7|FJLJ||||F7FJ||LJL7||FJL7||L7L-7|FJF7F7L||L7FJL--JL-J||L7|F7L7F7L||FL-JFL7|.-7JL-J7
||-J.JJF-L7F--JFJ|JL---J|L7||F-J|LJF7|||F7L-7|F7||L--7LJ|||F7FJ||||||FJL-7FJ|||F7||L7|F-J|L7||||FJ|FJL--7F----JL-JLJL7|||FJ|F7F77-FJFL--F7FF
L77F7LFF7L||F7-L7|F7F---JFJLJL-7L--JLJ||||F7||||||F7L|F-J|||||FJ||||||F7F||-||||LJL7|||F7|FJ||||L7|L-7F-JL----------7|LJLJFJ|LJL--7-F-|L-J-L
FL7-|FJL|7LJ||F-JLJLJF7F7|F----JF7F7F7|||||||||||||L7|L-7|||||L7||||||||FJ|FJ||L7F7||||||||FJ|||FJL7FJL-7F--7F------JL--7FJFJF----J.|7-.||-|
LF7|L7J-|7FL||L--7F7FJLJLJL7F7F7|||||||||||LJ||||LJL|L7FJ|||||FJ|LJ||LJ|L7LJFJ|FLJ||||LJLJ||.|||L7FJ|F--JL-7|L------7F-7|L7L7|LF7-|7LL.77L-F
L|LJJJLFF-7FJL---J|LJF7F7F7LJLJLJ||||LJ||LJLFJ|LJFF-JFJL7|||LJL7L-7||F-JFJF7L7|F--J||L---7||FJ||FJL7||F-7F-JL7F--7F-J|FJL-JFJL-J|..JJF|-7FJJ
LLL7-F-LL7LJF--7F7|F-JLJLJL7F----J||L-7||JF7L7L7F-JF-JF7|||L7F-JF7|LJ|F7L7||FJ||F-7||F-7FJ||L7|||F-J|||FJL--7|L-7LJF7||F7F-JF7F7L77.F||L.J7F
||.|-L-7-|F7|F-J|||L7F----7|L----7|L--J||FJ|FJFJ|F7L7FJLJ|L-J|F7||L7FJ|L7LJ|L7|||FJ||L7|L7||FJ|LJL7FJ||L7F--JL--J.FJLJLJLJF-J||L7L777-7.|F||
FJ7.L|FJFLJLJL-7|LJLLJF77FJL-7F--JL--7FLJL7LJFJL|||FJL7F7L-7FJ|LJ|FJL7|FJF7L7LJ|||FJ|FJL-JLJL7L-7FJL7|L7|L-----7F-JF--7F-7L-7LJ7|FJJL-J---LJ
||.FF-L.F7|-F--J|F--7FJL-JF-7|L---7F7L-7F-JF-J7FJ||L-7|||F7|L7L-7|L-7||L7||FJF-J||L7|L----7F7|F-JL7FJL-JL--7F-7LJF-JF7LJFJF7L7JLLJF7-|LF|.L|
7|F--J7-|LJ.L7F7|L-7|L7F-7|FJL----J||F-J|F7L--7L7|L7FJ|||||L7L7FJ|F7|||7||||FJF7||FJL7F--7||LJ|F--JL------7||FJF7L--JL-7|FJ|FJ-|LL7JL|F-L.L-
L7|J|-JFFJ|F-J|LJF-JL-JL7||L7F-7F7FJ|L-7LJL7F7L7|L7||FJ|||L-JFJL7||||||FJ|LJL7||||L-7|L-7LJL-7||F7F7F-7F-7|LJL7||F-7F--J|L7||F|J.L-JF|7|J|7L
.|-7-J|F|FFL--JF7|F7F-7FJ|L7||FJ|||FJF-JF--J|L7|L7|||L7||L--7L7FJ||||LJL7|F--J||||F7||F-JF---J|LJLJ|L7|L7LJF7FJ||L7LJF-7L7|LJ7|FF-JLF-7-FJF|
|LF-JFFJ|F-----J|LJLJFLJFJFJLJL7|LJL7L-7L-7FJFJ|J|||L7|||F7FJL|L7LJLJ-F7LJL--7|||LJLJ|L-7L---7|F---JFJ|FJF-J||FJL7L--JFJLLJ..FF-|-L7L|J||7|7
L-LL-|7--|F---7FJF7F--77L7|LF--JL7F7|F-J.FJL7L7L7||L7||||||L-7L-JFF---JL-----J||L---7|F7|F---J||F7F7|LLJ.|F-JLJJLL7F--J7LL|7FFJL|JL-7|.F|-J|
F---||.|-||F--JL-JLJF7L--JL7L-7F7LJ|LJF--JF7|FJFJ||FJ|||||L7FJFF--JF7F7F-7F-7FJL----J||LJ|F7F7|||||||F--7|L----7F-J|F7F7.F77FJLF.L7F7|7|7J|L
J-|FF|-77LJ|F-7F-7F-JL7F7F-JF7||L7FJF-JF7FJ||L7|-LJL7||||L7|||FJF7FJLJ||FJ|FJL------7LJF-J|||LJ||LJ|LJF-J|F--7FJ|F7LJ||L-J|-77FL---J||7LJ.|7
.F77|.FL||LLJFJ|FJ|F--J|||F-JLJL7||7|F7||L7||FJL--7.LJ||L7||L7L-J||-F7LJL7|L7F7F7F-7L-7L7FJLJF-JL7FJF7L-7|L7FJL7|||F7LJF7FJ7|L-..FL-|LJ|FF|7
FJJF--F-L|FLFJFJL-JL-7FJLJL7F--7|||FJ|||L7|||L7F--JF77||FJ|L7L--7|L-J|F--JL7|||||L7|F-JFJL-7L|F7FJL7|L-7LJFJL7FJ||||L7FJ||L-JJ.L-J|FL-|-L-.|
F-F-J||-F-7.L7|F----7LJ.F--JL-7||||L7||L7LJ||FJL---JL7||L7L7|F-7|L-7FJL---7||||||FJ|L-7L7F7L7LJ|L-7||F-JF7L7FJ|-||LJFJ|L||F|JF-.F-|J.||7JL|J
--JLLJ7F|7F7FJ|L-7F7L---JF7F7FJ||||FJ||FJF-J|L7F-7F-7|LJL|FJ|L7|L-7LJF7F--J|||||||L|F-JL|||FJF-JF7||||F-JL-JL-J7LJ.FJFJ7LJ-L.JJFF-7..-JJJ7|.
.J|LJ..-77.FL7|JFJ|L7F7F-JLJ|L7LJ||L7|||J|F7|FJL7|L7LJF--JL7L-J|F7|F-JLJF-7|||LJ|L7|L--7|||L7L7FJ|||||L---7JF---7.FL-J-7J.F|-LF7J|J-|.L-LL-7
L7-7.F7J|.FJLLJ|L-JFJ|||JF7FJFJF-JL7LJ|L7||||L7FJ|FJF7L---7|F7LLJ||L7F--J7|||L77|FJ|F7FJ|||FJFJL7||LJ|F7F7L7|F--J-LJFJ7|-LJ|.|.L-|7.L-J7F|LJ
FJJFF7J-.7JFF|.J.J-L7|||FJLJFJJL-7FJF-JFJLJLJF|L7|L7|L7LF-JLJL--7LJL||-F--J|L7L7|L7||LJF||LJFL7FJ||F-J|||L7LJL--7.LJL7FJ7JFFJ.F7J|F-7F.LJ-J.
LJF-JL7F-F7-JJ.L|J7.||||L--7L-7F-JL7L-7L-7F---JFJ|FJL7L-JF7F-7F-JF--JL7|F7FJ.|FJ|FJ|L--7LJF---J|FJ||F7||L7L7F7F7|7--J||FL7-F7.|7-F-.FF7FL.F7
|-|-7.JJ|F|F|LL..LF-LJLJJF-JF7|L7F7L-7|F7|L7F7FJFJL-7L7F7||L7|L-7|F-7FJLJ|L7FJL7LJLL7F7L-7L7F-7|L7||||||FJF||||LJ--J7.J-L7..|7LJFLJ.LLJ|7F7|
|FLJL7|-|JLFJ.L77-LF-----JF7|||FJ||F7|||LJFJ||L7L7F7|.|||||FJL--J||FJL--7|FJL7FJF-7FJ||F-J.|L7||FJ|||LJ||F7LJ|L-7LJF7-.F|JL7JF-|7.|FF77|FJ--
||-7F---||LL|..-JF-L--7F-7||||||FJLJ||||F7L7|L7|F|||L7||LJ|L----7LJL7F7FJLJF-JL-JFJL7|||7F-JFJ||L7||L77|LJL-7L-7L7-J-77|L7---|LL-7F-7J7|L7-J
-J7.L7LFJFJ.|..|-L7LLL|L7LJ||LJ|L-77||LJ||FJL7|L7|||FJLJF-JF7F--J-F7||LJJJFJF7F7FJ7L||||FJF7|FJ|.|||FJFJF-7FJJF|FJ|FLF77J|FL7.77.L|7|.-JF|L|
J.77-L-J-|..L.F.-J7FLL|FJ.F||F-JF7L7LJJ.|LJF7||FJLJLJJJFL-7||L--7FJLJ|J7F-L7||||L-7JLJLJL7|LJL7L7|||L7L7|JLJJ-FLJ7L7L7LF7FJ|L7L---LJ-LJFL-FJ
LLJF-L-|7..7LFJ...-7JJLJJFF||L-7||FJ|.LFL-7|||||J|7|JFFJJL||L7F7|L7F7L7F7J|||||L-7L7JJ|J.LJ||JL7||||FJ-||JJJL-||JJ||.F7LJ-L--J.|.F7L-L-J-||.
|L-JFJ7LF77|FJLFF7F7FF-JJ7|LJLFJ|||L|7FF--J|LJ||L-7J|-|JFFJL7||LJFJ|L7LJL7FJ||L7FL-J.L7-|7J||FL||||||7FLJ7.|.|LJL-7-FJ||FFJ-F777FLF.FJ7JL-J7
F-J.F-FJLJ-J7--J..|L---J7LJLL7L7|LJL||LL--7L-7LJ77L-|LF.FL7FJLJ-FJFJJ|F--JL7|L7|7J||7FF7|-..FL-LJLJ||J|LLJF-77FF7-|7||LL|L7--JL77-F7F.F--7LF
J.J-7.J-FJ-L7J.---J7.LLJ|-L7FJ7LJJ.LF7F|F-JF-J7FF7..JFJ7|LLJ7|7LL7|JFJL---7LJ.LJ..F|J7JF7LLJ.LJFJ7.LJJ77J.7.|-7JFF.7||FJJLLF7FJJF.LJL-|.LJJ|
|-|--F.||7.FJ-|JJLFJL7|FL7.-7FLJL7--JLF-L7FJJ-L7.LL7.|.LL-|7LL7-LLJ-L-7F--JFJ7|7L7JJ|.F-JL|F7JFJ-|-|JJ|-7FF-F77JFJ-FFF--7LF7-7.7L-..|L|JF|JL
--7-||-7LJ--.-F-7-L7JF77.F-.-|.|||FJ7.-J7LJ.|LL|7||LJLF7L-7-JFF7F7LJ.L||JFJ-.7J7-||F77J7.L|L7.7L-LF7.7JLJ7L|||J|.|-F-LJ7J7||L7FJF|-F7FLJFF7|
J-.F7J-J|L-|-FJ-F--7LLJ-J-.F7|F--JJFJF|L-L7F7.|.L-FJ|LL-7F|LF7.-JLL.7.||.|J|F--||LL7|J-F7.|-|7L7.||||J-|.-.|J||--F.--L||F7.J-J-J|LFLFF7.|.F|
|-LFJJJLLJLJ.FJF--7J-.LJL-JLLL-L-F-7-|J.|LJJ.LFJJ-LLL.LLLJ|JLJ|-LL-FJLLJ-J7--LJLL-LJ.|LL-FJJLLLJ.L|JJLF|-J-JLJ-FJ.FJ.L|LLJL..LJFJL-FJJLJ--FJ
"""
solution10_1 = fn input ->
map = input |> String.split("\n", trim: true) |> Enum.map(&String.to_charlist/1)
h = map |> Enum.count()
w = map |> Enum.at(0) |> Enum.count()
outside? = fn {x, y} -> x < 0 or x >= w or y < 0 or y >= h end
get = fn {x, y} = p ->
if outside?.(p) do
?.
else
map |> Enum.at(y) |> Enum.at(x)
end
end
neighbor = fn {x, y} = p ->
n = {x, y - 1}
s = {x, y + 1}
w = {x - 1, y}
e = {x + 1, y}
get.(p)
|> case do
?| -> [n, s]
?- -> [e, w]
?L -> [n, e]
?J -> [n, w]
?7 -> [s, w]
?F -> [s, e]
?. -> []
?S -> [n, s, w, e]
end
|> Enum.filter(fn p -> not outside?.(p) end)
end
next = fn last, cur ->
neighbor.(cur) |> Enum.filter(fn p -> p != last end) |> List.first()
end
fy = map |> Enum.find_index(fn line -> ?S in line end)
fx = map |> Enum.at(fy) |> Enum.find_index(fn c -> c == ?S end)
first = {fx, fy}
second = neighbor.(first) |> Enum.filter(fn n -> first in neighbor.(n) end) |> List.first()
find_cycle = fn [cur, last | _] = path, find_cycle ->
case next.(last, cur) do
^first -> path |> Enum.reverse()
p -> find_cycle.([p | path], find_cycle)
end
end
[^first, ^second | _] = cycle = find_cycle.([second, first], find_cycle)
div(Enum.count(cycle) - 1, 2) + 1
end
solution10_1.(sample10_1)
solution10_1.(input10_1)
Day 10 - Part 2
sample10_2_1 = """
...........
.S-------7.
.|F-----7|.
.||.....||.
.||.....||.
.|L-7.F-J|.
.|..|.|..|.
.L--J.L--J.
...........
"""
sample10_2_2 = """
.F----7F7F7F7F-7....
.|F--7||||||||FJ....
.||.FJ||||||||L7....
FJL7L7LJLJ||LJ.L-7..
L--J.L7...LJS7F-7L7.
....F-J..F7FJ|L7L7L7
....L7.F7||L7|.L7L7|
.....|FJLJ|FJ|F7|.LJ
....FJL-7.||.||||...
....L---J.LJ.LJLJ...
"""
sample10_2_3 = """
FF7FSF7F7F7F7F7F---7
L|LJ||||||||||||F--J
FL-7LJLJ||||||LJL-77
F--JF--7||LJLJ7F7FJ-
L---JF-JLJ.||-FJLJJ7
|F|F-JF---7F7-L7L|7|
|FFJF7L7F-JF7|JL---7
7-L-JL7||F7|L7F-7F7|
L.L7LFJ|||||FJL7||LJ
L7JLJL-JLJLJL--JLJ.L
"""
input10_2 = input10_1
solution10_2 = fn input ->
map = input |> String.split("\n", trim: true) |> Enum.map(&String.to_charlist/1)
h = map |> Enum.count()
w = map |> Enum.at(0) |> Enum.count()
outside? = fn {x, y} -> x < 0 or x >= w or y < 0 or y >= h end
get = fn {x, y} = p ->
if outside?.(p) do
?.
else
map |> Enum.at(y) |> Enum.at(x)
end
end
neighbor = fn {x, y} = p ->
n = {x, y - 1}
s = {x, y + 1}
w = {x - 1, y}
e = {x + 1, y}
get.(p)
|> case do
?| -> [n, s]
?- -> [e, w]
?L -> [n, e]
?J -> [n, w]
?7 -> [s, w]
?F -> [s, e]
?. -> []
?S -> [n, s, w, e]
end
|> Enum.filter(fn p -> not outside?.(p) end)
end
next = fn last, cur ->
neighbor.(cur) |> Enum.filter(fn p -> p != last end) |> List.first()
end
fy = map |> Enum.find_index(fn line -> ?S in line end)
fx = map |> Enum.at(fy) |> Enum.find_index(fn c -> c == ?S end)
first = {fx, fy}
second = neighbor.(first) |> Enum.filter(fn n -> first in neighbor.(n) end) |> List.first()
find_cycle = fn [cur, last | _] = path, find_cycle ->
case next.(last, cur) do
^first -> path |> Enum.reverse()
p -> find_cycle.([p | path], find_cycle)
end
end
[^first, ^second | _] = cycle = find_cycle.([second, first], find_cycle)
last = cycle |> List.last()
find_dir = fn
{x, y}, {bx, y} ->
cond do
x == bx - 1 -> :w
x == bx + 1 -> :e
end
{x, y}, {x, by} ->
cond do
y == by - 1 -> :n
y == by + 1 -> :s
end
end
first_type =
[last, second]
|> Enum.map(fn p -> find_dir.(p, first) end)
|> Enum.sort()
|> case do
[:e, :n] -> ?L
[:e, :s] -> ?F
[:e, :w] -> ?-
[:n, :s] -> ?|
[:n, :w] -> ?J
[:s, :w] -> ?7
end
get_border_type = fn p ->
cond do
p == first -> first_type
p in cycle -> get.(p)
true -> nil
end
end
horizontal =
0..(h - 1)
|> Enum.map(fn y ->
1..(w - 1)
|> Enum.reduce({[false], nil}, fn x, {[last_scan | _] = scan, bend} ->
last_border_type = get_border_type.({x - 1, y})
case {last_scan, bend, last_border_type} do
{_, _, ?|} -> {[not last_scan | scan], bend}
{_, _, ?-} -> {[last_scan | scan], bend}
{_, nil, type} when type in [?L, ?F] -> {[last_scan | scan], type}
{_, nil, nil} -> {[last_scan | scan], nil}
{_, ?L, ?J} -> {[last_scan | scan], nil}
{_, ?L, ?7} -> {[not last_scan | scan], nil}
{_, ?F, ?7} -> {[last_scan | scan], nil}
{_, ?F, ?J} -> {[not last_scan | scan], nil}
end
end)
|> then(fn {scan, _} -> scan |> Enum.reverse() end)
end)
vertical =
0..(w - 1)
|> Enum.map(fn x ->
1..(h - 1)
|> Enum.reduce({[false], nil}, fn y, {[last_scan | _] = scan, bend} ->
last_border_type = get_border_type.({x, y - 1})
case {last_scan, bend, last_border_type} do
{_, _, ?-} -> {[not last_scan | scan], bend}
{_, _, ?|} -> {[last_scan | scan], bend}
{_, nil, type} when type in [?F, ?7] -> {[last_scan | scan], type}
{_, nil, nil} -> {[last_scan | scan], nil}
{_, ?F, ?L} -> {[last_scan | scan], nil}
{_, ?F, ?J} -> {[not last_scan | scan], nil}
{_, ?7, ?J} -> {[last_scan | scan], nil}
{_, ?7, ?L} -> {[not last_scan | scan], nil}
end
end)
|> then(fn {scan, _} -> scan |> Enum.reverse() end)
end)
0..(h - 1)
|> Enum.map(fn y ->
0..(w - 1)
|> Enum.map(fn x ->
h = horizontal |> Enum.at(y) |> Enum.at(x)
v = vertical |> Enum.at(x) |> Enum.at(y)
not_cycle = {x, y} not in cycle
if h and v and not_cycle do
1
else
0
end
end)
end)
|> Enum.map(&Enum.sum/1)
|> Enum.sum()
end
solution10_2.(sample10_2_1)
solution10_2.(sample10_2_2)
solution10_2.(sample10_2_3)
solution10_2.(input10_2)
Day 11 - Part 1
sample11_1 = """
...#......
.......#..
#.........
..........
......#...
.#........
.........#
..........
.......#..
#...#.....
"""
input11_1 = """
........................#...............................................#................................#................................#.
....#..............#......................#............#....................................................................#...............
................................#.............................................................#.............................................
.........#.....................................#...................#........................................................................
....................................................#.......................#..............................#................................
..#................................................................................................#................#......................#
.........................................................#.........................#.....#..................................................
..................................#.............................#...............................................#.............#.............
.......#.....#...........................#..............................................................#.............................#.....
......................#...............................#................................................................#....................
............................#.................#........................#.....................................#..............................
....#.................................#...............................................#.....................................................
...............#...........................................................#............................................................#...
..................................#...........................................................#...................#...........#.............
....................................................................................................................................#.......
................................................................#................#..........................#...............................
...#..............#........#.........#.............#........................................................................................
.........................................................#.............#.............#..............#...................#...................
........#...................................................................................................................................
..............................................................................................#.................................#........#..
....................#.......................................#.....................................................#.........................
#..............................#.......#......#...................................#......#..................................................
...........#.......................................#......................................................................#.................
.......................................................................................................................................#....
............................................................................................................................................
.........................#...................................#...............................#..............................................
..................................#.......................................................................#.............#...................
.........................................#...........................#...............................#.........#..........................#.
............#......#............................................#...............................#...................................#.......
.............................#.....................................................#........................................................
....#........................................#...............................#.................................................#............
......................#............................#.....#.........#........................................................................
.........................................................................................................#..................................
.......#........................#................................................#..........................................................
...............................................#..........................#................#..........................................#.....
.#................#.............................................................................................#......#....................
..............................................................................................................................#.............
..........................#........................#.............................................#..........................................
.............#..........................#............................................#..............................#.......................
........#..............................................#.....................#..........................#..................#................
............................................................#.....#..................................................................#......
....................#.........................#..........................#..................#...................#...........................
..............................#...................................................#................#........................................
.........................................#..............................................#..................................................#
.#........#.........................................#.....................................................#.....................#...........
.........................................................#.........................................................#........................
......#...........................#.........................................................................................................
................................................#........................................................................................#..
...................................................................#...............#........................................................
.....................#................................#..............................................................................#......
...........#................................................................................#.....#.........................................
....#........................#............................................#..............................................#..................
................#.......#........................................................#........................................................#.
#...................................................................................................................#.......................
....................#...................#..............#.................................#...................#..............................
.............#....................#.................................................#..................#...................#................
.................................................................................................................#.....................#....
................................................................................#...........................................................
.......................#.............#....................#.................................................................................
.......#.............................................................................................#..............#.......................
...................#.....................................................................................................................#..
......................................................#..................#.......................................................#..........
..........................#..................................................................#..............................................
............#.................................#.........................................#...................#............#..................
.....................#......................................#......................................................#..........#.............
.#.........................................................................#......#...................#.....................................
............................................................................................................................................
................................#...........................................................#...............................................
........................................#..........................#..................................................#.................#...
....#........................................#.....................................................#.............................#..........
..........................................................#.................................................................................
...............#............................................................................................................................
..........#............#............................#.............................#...........................................#......#......
....................................#........................................................#...............#..............................
...........................................#..............................#...............................................................#.
.#...........................#.......................................................................#......................................
.........................................................#...........#....................................#.................................
......#.......#...................#...........................#.......................#.........#..................#........................
............................................................................#.........................................................#.....
.....................#.........................................................................................#........#...................
..........................#.............................................#................#........................................#.........
............................................................................................................................................
....#.....#.....#..................................#.........#.....................#....................#...................................
........................................#.....................................................................................#.............
...............................................................................................#............................................
.......#........................#...........................................#............................................................#..
....................#......#....................#...........................................................................................
.........................................................#...........#..........#.............................#...........#.................
......................................................................................#.....................................................
....................................................................................................#................#..........#.....#.....
............#.........#.....................#...............#..............................................#................................
.......#............................#.......................................................................................................
.......................................................................#......................#................#...................#........
............................................................................................................................................
........................................................................................................................#...................
..........#..........#.......................#.........................................................................................#....
...................................................................#.................#...........#..........................................
........................................#................#..................................................................................
................#....................................................................................................#......................
............................................................................................................................................
.......#....................#.................................................................#...............#.........................#...
.................................#...........#.....#...........................................................................#............
...........#.......................................................#....................#...................................................
........................................#...............................................................................#...................
............................................................................................................................................
.....................................................................................................#......................................
................#.........................................#..................#................................................#.......#.....
....#................................#.............#...................................#.....................#.......#......................
.........................#......................................#...........................................................................
...........................................................................................#.......#........................................
..........#.....................#..............#........................#...................................................................
..#.........................................................................................................................................
....................#.....................................#.......................#.........................................................
..........................#.............#...............................................................................#.........#.........
......................................................................................#.....................................................
.....................................................................#..........................#...........................................
.......#.........#...........................................................#.......................#........#............#............#...
........................#....................................#..............................................................................
.......................................#............................................#....................#.........................#........
..............................................#....................................................................#........................
..............#..................#.....................................#..........................#.........................................
..........................................#..........#..........................#...........................................................
.....#......................................................................................#................#..............................
.....................#................................................................#.......................................#.............
.....................................................................#......................................................................
...........#.....#............................#.....................................................................................#.......
................................#.....#..........................#........#..........................................#....................#.
...........................#.................................................................#........#.......#.............................
#...........................................................................................................................................
........#........................................#...................................#......................................................
.............................................................................................................................#..............
.................................#..............................#........................#.........#........#...............................
............#.....#..........................#.......................#....................................................................#.
........................#........................................................#..........................................................
............................................................#..............#......................................#.........................
...#........................................................................................#...............................................
...........................................................................................................#......................#.........
..........#.......................................................................................#.........................................
......................#................#............................................#.................................................#.....
...........................#.....................#........#...................................................#.............................
"""
solution11_1 = fn input, expand_multiplier ->
map =
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
line
|> String.to_charlist()
|> Enum.map(fn
?. -> 1
?# -> "#"
end)
end)
expand = fn line ->
if line |> Enum.all?(fn v -> v != "#" end) do
line |> Enum.map(fn _v -> expand_multiplier end)
else
line
end
end
map = map |> Enum.map(expand)
map =
map
|> Enum.zip()
|> Enum.map(&Tuple.to_list/1)
|> Enum.map(expand)
|> Enum.zip()
|> Enum.map(&Tuple.to_list/1)
gals =
map
|> Enum.with_index()
|> Enum.flat_map(fn {line, y} ->
line
|> Enum.with_index()
|> Enum.flat_map(fn
{"#", x} -> [{x, y}]
{_, _} -> []
end)
end)
[x_dist, y_dist] =
[map |> List.first(), map |> Stream.zip() |> Enum.at(0) |> Tuple.to_list()]
|> Enum.map(fn dist ->
dist
|> Enum.map(fn
"#" -> 1
dist when is_integer(dist) -> dist
end)
end)
dist = fn from, to, dist ->
dist |> Stream.drop(from) |> Stream.take(to - from) |> Enum.sum()
end
gals
|> Enum.flat_map(fn a ->
gals
|> Enum.flat_map(fn b ->
if a < b, do: [{a, b}], else: []
end)
end)
|> Enum.map(fn {{a, b}, {x, y}} ->
[a, x] = [a, x] |> Enum.sort()
[b, y] = [b, y] |> Enum.sort()
dist.(a, x, x_dist) + dist.(b, y, y_dist)
end)
|> Enum.sum()
end
solution11_1.(sample11_1, 2)
solution11_1.(input11_1, 2)
Day 11 - Part 2
sample11_2 = sample11_1
input11_2 = input11_1
solution11_2 = solution11_1
solution11_2.(sample11_2, 1000_000)
solution11_2.(input11_2, 1000_000)
Day 12 - Part 1
sample12_1 = """
#.#.### 1,1,3
.#...#....###. 1,1,3
.#.###.#.###### 1,3,1,6
####.#...#... 4,1,1
#....######..#####. 1,6,5
.###.##....# 3,2,1
"""
sample12_2 = """
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1
"""
sample12_3 = """
?###???????? 3,2,1
.###.##.#...
.###.##..#..
.###.##...#.
.###.##....#
.###..##.#..
.###..##..#.
.###..##...#
.###...##.#.
.###...##..#
.###....##.#
"""