Recursive Circus


Fork me on GitHub
2017-12-07

Day 07: Recursive Circus

Description:
--- Day 7: Recursive Circus ---

Wandering further through the circuits of the computer, you come upon a tower of programs that have gotten themselves into a bit of trouble. A recursive algorithm has gotten out of hand, and now they're balanced precariously in a large tower.

One program at the bottom supports the entire tower. It's holding a large disc, and on the disc are balanced several more sub-towers. At the bottom of these sub-towers, standing on the bottom disc, are other programs, each holding their own disc, and so on. At the very tops of these sub-sub-sub-...-towers, many programs stand simply keeping the disc below them balanced but with no disc of their own.

You offer to help, but first you need to understand the structure of these towers. You ask each program to yell out their name, their weight, and (if they're holding a disc) the names of the programs immediately above them balancing on that disc. You write this information down (your puzzle input). Unfortunately, in their panic, they don't do this in an orderly fashion; by the time you're done, you're not sure which program gave which information.

For example, if your list is the following:

pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
qoyq (66)
padx (45) -> pbga, havc, qoyq
tknk (41) -> ugml, padx, fwft
jptl (61)
ugml (68) -> gyxo, ebii, jptl
gyxo (61)
cntj (57)

...then you would be able to recreate the structure of the towers that looks like this:

gyxo
/
ugml - ebii
/ \
| jptl
|
| pbga
/ /
tknk --- padx - havc
\ \
| qoyq
|
| ktlj
\ /
fwft - cntj
\
xhth

In this example, tknk is at the bottom of the tower (the bottom program), and is holding up ugml, padx, and fwft. Those programs are, in turn, holding up other programs; in this example, none of those programs are holding up any other programs, and are all the tops of their own towers. (The actual tower balancing in front of you is much larger.)

Before you're ready to help them, you need to make sure your information is correct. What is the name of the bottom program?

--- Part Two ---

The programs explain the situation: they can't get down. Rather, they could get down, if they weren't expending all of their energy trying to keep the tower balanced. Apparently, one program has the wrong weight, and until it's fixed, they're stuck here.

For any program holding a disc, each program standing on that disc forms a sub-tower. Each of those sub-towers are supposed to be the same weight, or the disc itself isn't balanced. The weight of a tower is the sum of the weights of the programs in that tower.

In the example above, this means that for ugml's disc to be balanced, gyxo, ebii, and jptl must all have the same weight, and they do: 61.

However, for tknk to be balanced, each of the programs standing on its disc and all programs above it must each match. This means that the following sums must all be the same:

ugml + (gyxo + ebii + jptl) = 68 + (61 + 61 + 61) = 251
padx + (pbga + havc + qoyq) = 45 + (66 + 66 + 66) = 243
fwft + (ktlj + cntj + xhth) = 72 + (57 + 57 + 57) = 243

As you can see, tknk's disc is unbalanced: ugml's stack is heavier than the other two. Even though the nodes above ugml are balanced, ugml itself is too heavy: it needs to be 8 units lighter for its stack to weigh 243 and keep the towers balanced. If this change were made, its weight would be 60.

Given that exactly one program is the wrong weight, what would its weight need to be to balance the entire tower?

Input:
hndzyx (28)
kdelzk (399)
uylvg (403) -> xrvcjq, hihltxf, junpjcj, onkvtu, cckdoyb, favay, xsygurk
jiyqd (842) -> vunjzqr, sfooljn, gsnlv
mxmzyac (67) -> pbwmrq, eiqjanp, dyanei, zmkuj, vkvvtm, ktlhztg
wspoq (19) -> chpxtc, mylibd, vmutmbz
obqyrh (55)
inzzz (94) -> ayevuhk, rstjsa
mgraypm (108) -> ivvcytp, iaabs
eiqvo (87)
kienpis (32)
ohjesb (115) -> piepj, tplrep, yprilie
vthvyt (28)
vmyqa (5)
whavaec (79)
kpkcku (169) -> wprvgb, ektvj
amtxnd (99)
yauplaz (5) -> gnstbtt, ivucxwy, htoep, crgver
saaggxs (399)
kddqkkz (348)
tgcmyr (63) -> setljkt, qpyiycr
fhjpe (52)
tlirtlm (47)
xvkdd (15)
ybneks (12594) -> immqut, csprk, eyjif, oykud, bazfmo, nbmup, bxabcu
nwuxy (44)
trepya (17)
ibzuz (11301) -> dcqdop, pzpltg, xqzsy
acwne (28) -> gliupmb, hcwly
fcmspin (11992) -> thblrfo, rcsthxt, bmbkh, gnqdxl
pbwmrq (286) -> rupwawl, snqbfd
ivucxwy (64)
abaox (123) -> znltrss, hvfbx
udpwvnp (64)
fddgtmo (13)
gcult (71)
bykobk (1224) -> oaonzl, giiie, pdwwc
xrzdoz (84)
wwtxe (9)
cafeffy (311) -> wjwqs, qezwnc
lqimnfv (58) -> hekghqb, csirnil, ndnmvz
jjdzuw (9)
nbmup (360) -> ziouqpy, ilyaln, vecsik
zmukql (24)
tdxsvy (20)
qxtttuu (80)
fufgis (196) -> cdewiot, zdekdn
tgken (84)
leymr (98) -> msxnc, xxgvcq
rwhbcy (171) -> wmhwmv, yjdmkg
lncyf (93)
yhzue (994) -> mofidvl, xjghf, detpnh
lkfjzec (22)
khydeiy (53)
laxksv (35)
cmgap (28)
risnzi (84)
xmnqwd (249) -> ovsqv, qbdrnwf
wvrvgio (22)
vycfxv (20)
hacbd (93)
evmfp (254) -> ezfoih, xnyma, ltalmp
hrxxih (50)
jybwslx (1227) -> nadjis, qomycms, dmswq
mnvip (79)
kfvzter (233) -> aiizew, piuudr
pmtkuu (71)
vlujgrg (72)
hweuik (213) -> zdlyf, omdnuon
hymjivf (28) -> xrdkdkq, tonljgn, vcitv, wcufjj, ykcmzu, pgefkd
hdpqb (115) -> ecrdh, wnxya
eqcmflu (73)
euhmwat (89) -> jishckj, datzi, wjrjt, evmfp, mpgkscw
ywdvft (333) -> bktgoug, fufgis, dbkhupp, lhcndy, nggfb, tdgeaw, kdsmtx
kcfqe (33) -> guyzk, osnpcl, pejys, xbvlp
csirnil (43)
zzlopja (2024) -> opgjd, cigdar, olxbw
sakrb (82)
vpfaa (79)
hlsoeh (2786) -> prgfkm, eoabav, agfxi
ggdcjbd (120) -> hzfgjnm, qihokeg
qpyiycr (49)
vhyiaf (96) -> ghhwci, eudtoy, ceofy, kbzfvrp, ibzuz, vgkvnu, vmjcif
ysmrs (24)
pdwwc (235) -> iagng, hndzyx
knmdxw (57)
jijjnbw (34) -> xtqrjc, jqfou
uynpswf (98)
gxxwgu (73)
fmufi (124) -> lhcegk, uypiw
tzyav (40)
ystegvn (33)
xfyybbx (56)
eyjif (84) -> jvvnvo, yenoyh, yjldllm, dzcyze, acwne, wycdpt
ojjnnko (572) -> zmaxz, pqiivg, xmnqwd
cscdc (171) -> ynpehry, fbbcf
nczrlw (2351) -> jvhvlo, vrypfpq, egtdt
srozv (47)
kinfgwy (84)
qlscb (37) -> jlbbmrc, iehag, endqfm, ohksn
zlgewg (80)
ibqev (78)
edkcs (33)
gneen (33) -> vkeqd, bmfkrnb
zmtzfbt (68)
wnxbu (295)
qbsvwcc (45)
lclup (94)
wycdpt (170) -> btlvmkx, denjcv, iutqxkf
wxjne (287) -> blvgj, fddgtmo
ibuzkf (18)
wqhxpu (63)
gpmfjj (113) -> ioypyd, srozv
sowli (43)
rtfmatr (6)
knxli (53) -> qdbendr, zbpsmm, djfnwv, dsuhkja
yhcsmfs (88)
sthzqgi (17)
jujtux (99)
rpagi (166) -> rjrlumz, utoyap
cqrqt (52)
jgtnj (15)
xrdkdkq (435) -> voytx, tfqvoz, cxieq, nzdcujt, efwflo
yfcnm (54)
wkdquda (78)
ogexy (85)
rodlg (77)
ohavz (100) -> zlgewg, gjjykjf
znwmy (50) -> mvwtr, rzopy, qcbtref, snbjccn
zyvdjl (25)
fkgjr (38)
qyyiyo (63)
lzgcs (98)
nfrnbw (460) -> pajjlng, ibwax
eujco (71)
ickkf (50)
ipwjrx (71)
ijynzc (271) -> hshja, odlobo
rnwcn (69)
ojijdav (19)
ivnla (143)
ensst (6)
yjldllm (128) -> ltcwt, zwfyefp
drqjijj (37)
efwflo (249) -> tbosn, qhxasm
cxrmuo (50)
tvoqmae (15)
jurdmpq (77)
mowtdty (53)
cteerd (85)
hqbad (404) -> rhgfl, eeofxt
pofvr (72)
ibixfz (28) -> firwwz, xxqyp
fdbyixt (167) -> rodlg, alwsn
wyovcqf (47)
hgaupyo (32)
xirit (25)
ahatk (13)
wtuse (163) -> qbsvwcc, auqjapr
mphoskw (1275) -> wpdrp, lqimnfv, uoghp, dztpfb, lufzptb
ehucp (25)
rzwqxgp (76)
dwlqul (44)
csprk (1148) -> nrzao, agcqog, ehucp, ljtub
hzpagsa (89)
uoghp (153) -> pwyqx, isfuod
pbtuupy (42)
ykcmzu (1370) -> mozwerl, ddooi, teufo, rakjhe
ucafi (51)
sqwioau (19)
ewbfx (10)
qnbyib (86)
wvcui (35)
lgjkmc (57) -> nvuiy, idvtm
junpjcj (96) -> eqcmflu, ujpttyx
zdlyf (70)
ksbrn (58)
jrrrwqw (19)
xtqrjc (14)
foyeln (45)
soyzhei (74)
crgver (64)
xsygurk (242)
ugrxr (151) -> kmtpsb, lwkbk
nzzzh (22)
iwovx (36)
tfqvoz (185) -> pvxzi, sxwegk
yiwyghj (1246) -> seipdcu, lsgmebq, agdmzu
tovve (94)
hcjoif (67) -> sqkra, dufuw
kzbgh (68)
osnpcl (94)
kpwgdrt (263) -> winyji, ipwjrx
cdewiot (28)
iglpkvv (353) -> bozvn, ensst, rtfmatr, gnukyxz
hgbgr (220) -> cqrwox, ntqdd
putdy (21)
bwdstyz (62)
yofqkfe (973) -> iabql, mgraypm, pllcvd
zevpw (72)
nsrsjtk (237) -> nwvbh, eqkno
vgxle (142) -> fkgjr, vjupomu, lerrsh, sbgsxdw
ubiagvr (191) -> pbncc, tykqh
jriph (1998) -> cqrqt, kibpy
pbkyjk (179) -> hfrgc, jtvvv
gqrjzf (158) -> hzpagsa, bvtsl, hqaxdqm
lwnpt (43)
ejucumc (6)
imzjzf (257) -> rzwqxgp, lwatsc
eypmjnl (82)
vzglbr (33)
mlslqa (162) -> siwcnqk, coenxv
piuudr (88)
rcsthxt (220) -> szcxg, btkth
kixinqo (62) -> dcjiu, rnwcn
prgfkm (85)
enlnjb (88)
dcrhafq (28)
qkhwa (2607) -> sgoseob, zbwfbgd
emxti (5)
dkhddzb (82)
ffvsvb (73) -> ubuuw, tntwm, yiimp
nlaym (178) -> iqwsxmt, qcmxoe
lgyab (295)
wprvgb (46)
sjsqaol (48)
uzifsnw (84)
voytx (172) -> scjek, knmdxw, qwuug
ruroup (53)
lssxhxw (8)
pheyymh (78) -> kiwylpo, taapm, ggcyyr
zagsm (70)
ivvcytp (63)
lhcndy (134) -> idjquuv, tvpovok
ijjri (6)
vzttnzk (117) -> mmyaot, ignsmt
xqzsy (464) -> qlucu, fdnxe, soyzhei
jkbuq (29619) -> oielzfu, ocyjmcy, ybneks
pvuno (58)
tpxvyjx (92)
alwsn (77)
ioypyd (47)
zgjhbp (79) -> wpboq, pcitx
dlfghsv (84) -> rxozjry, uejnd, fpkgx, chvari
zddmfy (60)
qcbtref (61)
gabpxsf (1503) -> pjbrh, hsbzn, hjroy
hfrgc (67)
ytxusu (1914) -> upapd, tgcmyr, zgjhbp, qahkfnd, abaox, gobzapu, wnmyhx
yvdidmd (21)
iutqxkf (8)
kutxof (22)
ziouqpy (142) -> zfqvkc, jpwhcjy
sxxod (88)
lohgt (98)
ewbngna (15)
ffuxvj (83) -> fbbeae, xtbhjq
ulqloyn (79)
bazfmo (492) -> vvcoce, vekxtb, pheyymh
qhaxz (21)
fsfdbgt (77)
agdmzu (41) -> xbaluf, ucafi
thblrfo (148) -> lxmtjx, lwnpt
becfiz (97) -> xywsyz, mznemqf, zbbyzr, hftcktd
tzuiasi (91)
scjek (57)
wrhfj (46)
dxllc (44)
msxnc (81)
lswznxp (24)
vojtq (60)
ecrdh (63)
fymxr (77)
mfvdags (72) -> uljtowd, jurdmpq, jgome, syvhbgb
wpmef (75)
qomycms (222) -> wxbsqif, cmgap, xilohyg
roedr (77)
vbhmz (73)
hmonryr (344) -> euhmwat, lpmsj, jjrto, scabkd
qdbendr (67)
seffc (98)
geqrhsr (76)
txxjkb (306) -> lmtisu, sovgznm
cozmd (33) -> wvkqb, yquoa, seffc, uynpswf
vikpkr (233) -> xznjrta, emxti, efyiyc, nemethx
tabwkx (91)
wlpnxme (72)
mhgzc (60)
sfeepek (28)
dcpgsg (58)
upapd (161)
kyukz (10)
hihltxf (44) -> kugzwm, skzmpao
jmypi (32)
mrfswq (99)
ltalmp (51)
szymk (28)
qhnifn (287) -> nosbdrs, hzjcwc
nggfb (200) -> moaabux, xcriywz
cjgtg (343) -> rnimplt, vthvyt
iqvnyzy (55)
wltxoge (318) -> ewbngna, xvkdd
uczyc (93)
elvjpjr (32)
agfzkj (329) -> sjsqaol, rafvktj
cmqglh (84)
rzopy (61)
sbocc (48)
ihjyjx (11)
jpwhcjy (77)
radwgcq (46)
fpkgx (88)
fpiatig (2611) -> inxpyl, jlmgl
jnlnsk (1966) -> vzttnzk, wpidtfu, wnggxc
qxqwvi (99)
wmyojtm (260)
bsbjxg (9)
adyogf (99)
upsbm (19)
ynpehry (46)
vjupomu (38)
pvxzi (79)
knxyay (22)
wtluvr (88)
nadjis (284) -> xeqol, ihjyjx
mozwqgu (24)
cufloa (7) -> exmpr, jzjgef, gotuw
zqbkt (905) -> yauplaz, hcjoif, rwhbcy, kpkcku, vehlv
xwudzc (284) -> gneipe, ityktpq, wyovcqf
npehrzk (77) -> xsdzkqs, mzpumh
tmakl (51)
ocyjmcy (43) -> hlsoeh, wsgab, zzlopja, nczrlw, ytxusu, hzmxo, lffnvze
jmtqh (191) -> hacbd, lncyf
chpxtc (71)
ujpttyx (73)
qywnr (253) -> rdkqd, nfrnbw, juykf
uvybtgx (344) -> ijjri, ejucumc, yscyxrt, esskfkp
cuvke (18)
svprq (85)
sgoseob (38)
ghhwci (9294) -> jiyqd, ojjnnko, aawaew
znltrss (19)
pbncc (81)
ioyibl (77)
lwkbk (56)
ktlhztg (328) -> tzyav, gkzimba
gavzkq (15)
jdpfhyl (13)
mpyhy (263)
auqjapr (45)
caufkxz (55)
sbgsxdw (38)
rtckpbz (67)
yqewlf (92)
loukhc (80) -> adyogf, mrfswq, qxqwvi
xrvcjq (212) -> xhqpkdq, pisrmb
zfqvkc (77)
tqpgecy (76)
xcrejqf (5)
rrvihye (36) -> dkhddzb, sakrb
rbast (28)
bcygph (10)
ubfljy (95)
omdnuon (70)
mmyaot (61)
jwcsw (367) -> ounhwx, flcxc
gnqdxl (66) -> xqbgo, cmqglh
qipkli (218) -> putdy, rfvtz
rakjhe (103) -> wrhfj, ssvgu
rzuig (90)
iewgymm (10)
pqiivg (191) -> hjuhoum, bwpbkb
sswszre (78)
vihkn (63)
efuzst (72)
nbtxoam (83)
lerrsh (38)
myvyjck (86)
daxxjtz (445) -> ewypdpk, jfaseqo, bqxwpf, hweuik, ubiagvr
wefmw (88)
qlezcmj (44)
jvhvlo (230)
tplrep (20)
asvbb (67)
diqon (862) -> mgonf, rnjxo, ykijrb
dmswq (75) -> fsfdbgt, roedr, oplfyg
ietond (42)
tjwtl (87)
kdsmtx (78) -> tjwtl, fdkkxk
tplgx (76)
kbzfvrp (2091) -> xltrwv, hcxpyq, gogfx, uoqkd
ljtub (25)
irupq (60) -> grstedk, hzyxurv
ubzly (253) -> gbrnge, tzuiasi
rjrlumz (72)
dyrpzor (78)
lmtisu (51)
cqrwox (80)
jhxsez (7)
uxzql (84)
upjapf (77)
watsby (84)
adetez (46)
wxpagp (19)
hzjcwc (17)
bmfkrnb (87)
qljvi (237) -> iatmk, sowli, auigtqr, ddeso
chvari (88)
qhxasm (47)
ektvj (46)
feywd (2062) -> nrgrjty, cjhrs, ytomrhu
fjcbsj (97)
hzfgjnm (56)
uidqcn (84)
oagdsv (235) -> ndnxy, kbmqdsc
vcitv (1040) -> xyzmpjv, nlaym, fqftj, zrtlh, lnozan
dbqwqo (13)
lnozan (166) -> yhtmfb, dcrhafq
lhcegk (85)
taapm (58)
tntwm (79)
ovozt (70)
meuoa (90)
wzrpo (28)
lzmldaf (71)
oaonzl (95) -> lzgcs, wblgb
stvho (6)
xcerg (19)
denjcv (8)
budzpo (22)
wpmoil (54)
vehlv (233) -> jhxsez, xavbkjb, jdhwx, beinhu
blvgj (13)
giiie (95) -> lohgt, ekezedh
onmidw (436)
lftsl (79)
ktgfxpm (55)
nwvbh (29)
vdywyof (10)
juykf (339) -> wbqyxc, qghexm, spqtfmy
dzcyze (6) -> tovve, jtugpxm
rxozjry (88)
htoep (64)
qbdrnwf (6)
wpidtfu (49) -> ubfljy, slbyad
agfxi (85)
mtaatz (266) -> gjegewd, cozma
mznemqf (78)
eoabav (85)
ewypdpk (21) -> fdxizm, sbfiowr, zpatw, nbtxoam
ntqdd (80)
fqoozik (14)
gobzapu (50) -> pturyym, drqjijj, yoxfi
ytomrhu (197) -> xcrejqf, zbfds
vgoayw (21) -> vvyuxd, ahcxyzi
gslkem (11)
pgefkd (2000) -> rxmaax, wpmef
dztpfb (187)
dsvthh (82)
nemethx (5)
yquoa (98)
opfgye (151) -> yuctaoj, hsxey
vqecsyp (84)
hlxhne (35)
jfaseqo (247) -> khydeiy, lvbgvb
qborl (299)
yzpfod (28)
spqtfmy (45)
ptwgg (21)
suxsxhs (72)
kchnqf (82)
qvaemxv (99)
rupwawl (61)
gsnlv (137) -> oopqw, wghzp
tsqmps (63) -> bykynh, xfyybbx
yiimp (79)
xalpz (49)
xcriywz (26)
uabcnf (78)
zmkuj (364) -> kutxof, knxyay
egkkx (405)
kfojlo (9)
xavbkjb (7)
uuepceb (52)
rfvtz (21)
vunjzqr (15) -> gtwif, uuepceb, rgthsm
fbbeae (40)
yuctaoj (6)
tllmans (2018) -> abvtv, sbocc, fyxrsks, camnbrn
wirio (33) -> ztgujur, ovozt, nhfaz, zagsm
mozwerl (37) -> vpfaa, ulqloyn
mydrx (165) -> hdpqb, lgjkmc, aikum, ohzbeco
qvzsob (88)
etksk (47)
oopqw (17)
fowke (51)
txlrdpc (1421) -> jmtqh, flbni, loukhc, iglpkvv
dbkhupp (117) -> bugid, fzftvzt, foyeln
aurik (2443) -> jriph, bykobk, uylvg, yxhntq, ywdvft
tqved (35)
btkth (7)
gjqasxb (33)
snqbfd (61)
qgyboht (10)
eqdugzw (51)
xeqol (11)
oynrsea (79)
ilfmw (68) -> rzahe, fbfawqa, hxtumb, wtuse, vikpkr
dphwkj (88)
utoyap (72)
opbyya (93)
flcxc (19)
jishckj (155) -> uzifsnw, vqecsyp, uidqcn
kvrrast (175)
teufo (99) -> jmypi, aegkypi, kienpis
rlghl (32)
bugid (45)
vkeqd (87)
osppg (72)
xxcsggt (97)
vpgtsem (354) -> aqgufrg, sthzqgi, kwemyhv
eqkno (29)
ieqrsbo (65)
syvhbgb (77)
vxcuhd (66) -> vhnoll, xphisb
kugzwm (99)
vekxtb (202) -> zyvdjl, xirit
andsm (60)
gjegewd (10)
wmril (38) -> lmkdc, yhnbyxd
awcgokk (71)
wynfir (95)
seavb (67)
ohksn (97)
bykynh (56)
bjcmqj (72)
fyxrsks (48)
qhzdnug (51)
vvyuxd (93)
lsgmebq (143)
tykqh (81)
cwkoak (74)
ozeuxvw (90)
lmkdc (81)
nrgrjty (33) -> vkrhnw, eiqvo
vqxoyl (13)
onkvtu (83) -> mowtdty, zivoem, ruroup
hzyxurv (70)
immqut (285) -> fdbyixt, qhnifn, knxli
pjrin (295)
qihokeg (56)
nalhjfn (2161) -> lwogeq, ayvoftj, vxcuhd
siwcnqk (74)
nwmgu (285) -> mndwt, jjbgnry
blwogji (19)
kibpy (52)
iabql (84) -> ickkf, jfkhs, ypdcyhe
exmpr (230) -> pofvr, osppg
xbvlp (94)
ovsqv (6)
ddooi (107) -> dxllc, nwuxy
iutebku (1047) -> kfvzter, awronb, imzjzf, becfiz
qahkfnd (123) -> xcerg, upsbm
skzmpao (99)
tonljgn (57) -> gpwroki, qborl, eskfcor, leecyuk, nwmgu, zqbje, zalfzf
xxqyp (91)
ssvgu (46)
vmjcif (9360) -> tyrncu, ilfmw, nntuwn
oplfyg (77)
cigdar (339)
ilyaln (76) -> caufkxz, ktgfxpm, obqyrh, iqvnyzy
ryxdad (84)
zgjcuz (53) -> wefmw, wtluvr, wgqlq, enlnjb
pdswch (67)
glbvimo (211) -> fjcbsj, ggoegus
eyxvb (60)
utghvik (24)
ymnotlu (88)
hekdhpe (13)
ukldjwr (335) -> fvhtci, elvjpjr
ayvoftj (98) -> fvdpch, mnvip
bkpjjg (51)
mndwt (7)
hxunt (72)
yprilie (20)
kspwjf (55) -> ietond, orjnuc
nvuiy (92)
lgvgz (9)
hdtndko (38)
djfnwv (67)
bktgoug (208) -> nzzzh, lkfjzec
xnyma (51)
jfkhs (50)
firwwz (91)
sfooljn (69) -> gaszn, qhzdnug
qddxuou (63)
xjghf (181)
lnzzwfi (24) -> blwogji, ojijdav
puvpxd (38) -> opbyya, uczyc
pgqdymw (88)
sovgznm (51)
wzcini (97)
mekcnd (38)
cakeb (67)
grstedk (70)
rfnnn (7)
zrtlh (68) -> upjapf, pqcxw
gtoij (184) -> lssxhxw, brirt
vxgbrvk (5)
bmbkh (168) -> gjqasxb, ystegvn
xltrwv (2388) -> htqkf, ivnla, jsrfoem
xmxvd (31) -> bjcmqj, zevpw
hcxpyq (24) -> ukldjwr, gyymhc, kdelzk, tqjtmnl, glfsclp, cjgtg, saaggxs
jsojra (78)
eijnbk (65)
slbyad (95)
nrzao (25)
wnggxc (217) -> gslkem, ojzyz
pejys (94)
wjrjt (407)
gotuw (86) -> vlujgrg, pkkpfqd, hxunt, efuzst
hfzsc (58)
jzjgef (234) -> hlxhne, laxksv, tqved, nnhhm
jtugpxm (94)
bxabcu (570) -> eztcv, cnvjej, jikwvk
aikum (205) -> lgvgz, kfojlo, jjdzuw, yvkbhqt
iaabs (63)
rnjxo (61) -> eypmjnl, ebudz
kbmqdsc (39)
hvfbx (19)
iqwsxmt (22)
usbgi (53)
petrvdq (61)
elpnrhu (39)
fdxizm (83)
eskfcor (263) -> xlsmzvh, cuvke
fpkcbpf (210) -> hrxxih, cxrmuo
ggoegus (97)
zwfyefp (33)
iehag (97)
hmxzzp (42)
wpdrp (41) -> gxxwgu, vbhmz
qlucu (74)
jnotktj (302) -> bxoslf, usbgi
sxwegk (79)
gogfx (2601) -> warwhgb, wlpnxme, suxsxhs
ybuocfy (1374) -> tzfii, safaxql, opfgye, johvj, ezjzcma, ffuxvj, ztubst
jfnojdk (212) -> lsqafn, xjzwjwo
ecqun (20)
wblgb (98)
pfohpw (43)
yhtmfb (28)
oedzmki (360) -> npehrzk, ugrxr, mcjpy, mpyhy, cscdc
detpnh (47) -> dqxjmn, seavb
fvhtci (32)
wpboq (41)
bwpbkb (35)
zbbyzr (78)
dwghva (53) -> nalhjfn, txlrdpc, sxplgr
jlbbmrc (97)
ehogp (84)
jdhwx (7)
leecyuk (173) -> qyyiyo, fqbwlo
xfafo (9)
miuaxx (380)
bqxwpf (251) -> vcweon, bkpjjg
mvwtr (61)
bvtsl (89)
zqbje (219) -> tdxsvy, vycfxv, ecqun, ketqren
lwogeq (102) -> fymxr, ioyibl
dmnohav (23)
hpqvzn (5383) -> mxmzyac, gtukrss, ybuocfy
moaabux (26)
quwnokw (19)
qfmbrpi (7) -> ryxdad, kinfgwy
wnmyhx (161)
rilyl (28969) -> aurik, fcmspin, hpqvzn, hymjivf, qgrkb
lelwex (210) -> gabonn, rfnnn
zbpsmm (67)
bafivi (408) -> kresb, fqoozik
mwvpdtt (188) -> udpwvnp, ollxzi, uhomjuv
czwhzbc (282) -> guggdb, xalpz
dufuw (97)
rnnbl (114) -> zctkn, pfohpw
sddwvuf (297) -> wpmoil, yfcnm
totce (96) -> wqhxpu, ibxac, vihkn, qddxuou
vecsik (50) -> dsvthh, kchnqf, uifjz
pllcvd (30) -> gcuxn, kzbgh, zmtzfbt
zpatw (83)
unexcu (58)
gjjykjf (80)
asorc (67)
akpehu (85)
pkkpfqd (72)
wvkqb (98)
rfguypo (216) -> tqpgecy, tplgx
elfenmu (99)
efyiyc (5)
wgqlq (88)
tbosn (47)
fdkkxk (87)
gneipe (47)
guyzk (94)
awronb (279) -> ieqrsbo, eijnbk
nosbdrs (17)
ztgujur (70)
vvqdsqo (19)
gcuxn (68)
zrfcjo (293) -> ajqgxy, gcult
mvhek (52)
emjyxt (17)
kvblxto (39) -> cafeffy, qljvi, viftnsh, kcfqe
pisrmb (15)
uhomjuv (64)
oykud (1210) -> quwnokw, vvqdsqo
hnmipv (48) -> qvzsob, dphwkj
setljkt (49)
pdvmaam (67089) -> dwghva, hmonryr, rjdmf
tsmekuh (216) -> budzpo, wvrvgio
lpmsj (1266) -> inzzz, pwibnc, mtaatz
xbaluf (51)
lsqafn (84)
ezfoih (51)
hekghqb (43)
htqkf (9) -> asvbb, rtckpbz
wsgab (66) -> qlscb, xwudzc, cozmd, agfzkj, yewec, hvdpvf, gqrjzf
kmhdfd (10)
kmtpsb (56)
kiwylpo (58)
wbqyxc (45)
bozvn (6)
viftnsh (315) -> tlirtlm, etksk
udisj (10)
cgtirrb (368) -> stvho, shwgbpx
jlmgl (36)
xxgvcq (81)
sbfiowr (83)
nhfaz (70)
johvj (163)
osckuj (58)
idswf (15)
tqjtmnl (115) -> eujco, amacxs, lzmldaf, awcgokk
pwibnc (22) -> pgqdymw, tjffc, mbzenl
jtvvv (67)
hshja (12)
qghexm (45)
uejnd (88)
qlgkl (94)
aqgufrg (17)
cjhrs (131) -> zrruyn, sqwioau, jrrrwqw, rupecqk
rywlizi (44)
xyzmpjv (28) -> xxcsggt, wzcini
xyarhf (80)
hztbvq (348)
piepj (20)
ojzyz (11)
uljtowd (77)
ceofy (3309) -> yofqkfe, iiyhw, yiwyghj, oedzmki, qywnr, kvblxto
fzftvzt (45)
hsvleq (2142) -> emjyxt, ymjcf, mxtxzdj, trepya
jikwvk (110) -> unexcu, ksbrn
wnxya (63)
tjffc (88)
hsxey (6)
qijgfwk (155) -> fbbzyxj, ewbfx
pxkcra (23)
isfuod (17)
lgdtj (24)
qszyv (15)
zbwfbgd (38)
bgjreum (62)
mxtxzdj (17)
xjzwjwo (84)
rxmaax (75)
pwyqx (17)
qezwnc (49)
wvjhjjn (2611) -> zmukql, lswznxp, rsujfpj
amacxs (71)
lwatsc (76)
hpohuv (128) -> fhjpe, mvhek
vhnoll (95)
uujpyn (84)
lqnym (99)
ollxzi (64)
itqiej (90)
vmutmbz (71)
hwcnp (67) -> bjsyz, znwmy, sdxxuml, vgxle, fmufi
gnukyxz (6)
wmhwmv (45)
hcwly (83)
qwuug (57)
ggcyyr (58)
ztubst (43) -> zddmfy, wdmkbxa
qduyad (78)
uifjz (82)
tpkmqc (30) -> hqbad, oatauv, dlfghsv, bafivi, onmidw
cozma (10)
yxqwz (75) -> rlghl, hgaupyo
ohzbeco (175) -> vzglbr, edkcs
fqbwlo (63)
pzpltg (56) -> tnnjkm, tfkbv, ibixfz
sdxxuml (246) -> lrqeps, utghvik
nntuwn (109) -> txxjkb, gihcxn, jnotktj
mylibd (71)
gbrnge (91)
gtwif (52)
hsbzn (32) -> gfnxtjy, tabwkx
zrruyn (19)
safaxql (107) -> rbast, yzpfod
eztcv (78) -> cwkoak, bcmhwm
hxbcz (10)
ozecapv (121) -> bsbjxg, cpbasst
lufzptb (63) -> bgjreum, cryabx
fgsxy (13)
zivoem (53)
ibwax (7)
taudz (71)
fbfawqa (197) -> mdledr, szymk
hzmxo (1301) -> tlkqqk, ubzly, zrfcjo, nlbjopb
wxbsqif (28)
nnhhm (35)
doevlp (67)
nzdcujt (280) -> yvdidmd, qhaxz, ptwgg
nkviw (61)
xqbgo (84)
mdledr (28)
bxoslf (53)
rqbqxy (80)
endqfm (97)
jlrfg (88)
idvtm (92)
yscyxrt (6)
pjbrh (214)
camnbrn (48)
dcqdop (500) -> jijjnbw, bwdstyz, lnzzwfi
yhnbyxd (81)
qfhptx (92)
qyucm (127) -> yjdfxn, ysmrs
jvvnvo (138) -> wzrpo, sfeepek
olxbw (99) -> rqbqxy, xyarhf, qxtttuu
fvdpch (79)
osgdles (76)
yvkbhqt (9)
khyzbb (78)
lrqeps (24)
fbbzyxj (10)
gabonn (7)
jsrfoem (143)
zbfds (5)
mwojc (18)
opgjd (217) -> nkviw, petrvdq
hftcktd (78)
cryabx (62)
ezjzcma (21) -> taudz, pmtkuu
gfgrl (36)
zelhlaj (44)
shwgbpx (6)
jjrto (1452) -> puvpxd, lelwex, hnmipv
vcweon (51)
fqftj (102) -> chyyj, uetfc
xilohyg (28)
zctkn (43)
ounhwx (19)
rgthsm (52)
uypiw (85)
gnstbtt (64)
tdgeaw (252)
ebudz (82)
hqtwr (56) -> dyrpzor, sswszre, jsojra, qduyad
wdmkbxa (60)
guggdb (49)
pturyym (37)
abvtv (48)
eudtoy (99) -> hsvleq, daxxjtz, tllmans, tpkmqc, mphoskw, zqbkt
warwhgb (72)
orjnuc (42)
tzfii (115) -> mozwqgu, lgdtj
yxhntq (9) -> bmgtktw, kddqkkz, hztbvq, omouek, totce, wltxoge
ykijrb (225)
fdnxe (74)
bcmhwm (74)
uoqkd (1565) -> oagdsv, pbkyjk, wirio, wxjne
iprxseg (99)
gaszn (51)
gihcxn (56) -> jlrfg, sxxod, ymnotlu, yhcsmfs
tvpovok (59)
pqcxw (77)
sddsn (84)
iagng (28)
mcjpy (129) -> cmgugdz, asorc
xlsmzvh (18)
gyymhc (353) -> pxkcra, dmnohav
oielzfu (2549) -> jnlnsk, qkhwa, iutebku, fpiatig, feywd, wvjhjjn, ffypved
eeofxt (16)
xtbhjq (40)
tfkbv (165) -> tvoqmae, idswf, fjlsk
hjuhoum (35)
brirt (8)
zvittjn (202) -> iwovx, wklcvl, gfgrl
kwemyhv (17)
auigtqr (43)
ndnxy (39)
pfwuaht (295)
mofidvl (13) -> tgken, sddsn
flbni (341) -> mwojc, ibuzkf
ekezedh (98)
coenxv (74)
esskfkp (6)
jjbgnry (7)
mumddr (79)
rzahe (73) -> rzuig, meuoa
xywsyz (78)
dsuhkja (67)
vkvvtm (92) -> whavaec, lftsl, oynrsea, mumddr
gkzimba (40)
rstjsa (96)
qrqxdk (43) -> xrzdoz, risnzi, ehogp
dqxjmn (67)
xytmux (48) -> osgdles, geqrhsr
vihqwqe (95)
hjroy (214)
gfnxtjy (91)
lhplxk (5)
yewec (425)
wapwp (35)
hlqnsbe (77) -> rilyl, vhyiaf, pdvmaam, jkbuq
wjwqs (49)
rhgfl (16)
omouek (256) -> adetez, radwgcq
fjlsk (15)
ubuuw (79)
beinhu (7)
mzpumh (93)
rjdmf (2692) -> uotis, hwcnp, yhzue, diqon
yoxfi (37)
szcxg (7)
hzuqtd (39)
lffnvze (2861) -> ozeuxvw, itqiej
idjquuv (59)
xhqpkdq (15)
favay (44) -> iprxseg, jujtux
bjsyz (276) -> xfafo, wwtxe
xphisb (95)
jgome (77)
scabkd (574) -> rpagi, ffvsvb, fpkcbpf, mlslqa, zvittjn
yjdmkg (45)
cckdoyb (172) -> wvcui, wapwp
uetfc (60)
vrypfpq (29) -> doevlp, pdswch, cakeb
vlgyos (10)
odlobo (12)
cxieq (91) -> uujpyn, uxzql, watsby
uotis (137) -> rnnbl, irupq, rrvihye, gtoij, xytmux, kixinqo, wmril
rupecqk (19)
zmaxz (89) -> qnbyib, myvyjck
ignsmt (61)
tnnjkm (165) -> gavzkq, qszyv, jgtnj
inxpyl (36)
glfsclp (87) -> ibqev, khyzbb, uabcnf, wkdquda
ajqgxy (71)
nlbjopb (309) -> pbtuupy, hmxzzp, arzxsdq
jqfou (14)
wghzp (17)
winyji (71)
qcmxoe (22)
pajjlng (7)
ibxac (63)
zdekdn (28)
slrxywr (38)
vgkvnu (6924) -> oaddogg, gabpxsf, jybwslx
chyyj (60)
cpbasst (9)
xznjrta (5)
pcitx (41)
arzxsdq (42)
aegkypi (32)
ffypved (23) -> jfnojdk, cgtirrb, czwhzbc, mfvdags, miuaxx, mwvpdtt, hgbgr
ymjcf (17)
onhpt (19)
lxmtjx (43)
mbzenl (88)
yenoyh (80) -> mekcnd, hdtndko, slrxywr
vvcoce (76) -> zelhlaj, qlezcmj, dwlqul, rywlizi
ayevuhk (96)
ityktpq (47)
ypdcyhe (50)
seipdcu (65) -> elpnrhu, hzuqtd
wcufjj (925) -> qijgfwk, kvrrast, xmxvd, qfmbrpi, tsqmps, ohjesb, qyucm
gliupmb (83)
bmgtktw (108) -> mhgzc, eyxvb, vojtq, andsm
kresb (14)
dyanei (378) -> kyukz, vdywyof, kmhdfd
eiqjanp (218) -> wynfir, vihqwqe
btlvmkx (8)
rdkqd (78) -> amtxnd, qvaemxv, elfenmu, lqnym
sxplgr (94) -> jwcsw, sddwvuf, vpgtsem, glbvimo, egkkx, kpwgdrt, zgjcuz
fbbcf (46)
hvdpvf (237) -> lclup, qlgkl
oaddogg (80) -> pfwuaht, wnxbu, ijynzc, lgyab, pjrin, nsrsjtk, qrqxdk
mpgkscw (355) -> hekdhpe, jdpfhyl, dbqwqo, vqxoyl
kuydvlr (92)
hxtumb (233) -> udisj, iewgymm
hqaxdqm (89)
cmgugdz (67)
aiizew (88)
ndnmvz (43)
rnimplt (28)
flstvi (25) -> hqtwr, uvybtgx, rfguypo
tyrncu (712) -> vgoayw, gpmfjj, gneen
ahcxyzi (93)
zalfzf (259) -> qgyboht, hxbcz, bcygph, vlgyos
ketqren (20)
qgrkb (9541) -> cufloa, flstvi, mydrx
egtdt (210) -> vxgbrvk, vmyqa, dpqznt, lhplxk
wklcvl (36)
gtukrss (1819) -> wspoq, ggdcjbd, hpohuv
gpwroki (95) -> tmakl, eqdugzw, fwtuv, fowke
rafvktj (48)
rsujfpj (24)
fwtuv (51)
iatmk (43)
ltcwt (33)
aawaew (55) -> ohavz, tsmekuh, qipkli, leymr, wmyojtm
datzi (67) -> svprq, cteerd, ogexy, akpehu
agcqog (25)
mgonf (199) -> ahatk, fgsxy
tlkqqk (67) -> kuydvlr, yqewlf, qfhptx, tpxvyjx
dcjiu (69)
dpqznt (5)
xsdzkqs (93)
iiyhw (1258) -> ozecapv, yxqwz, kspwjf
snbjccn (61)
yjdfxn (24)
cnvjej (188) -> onhpt, wxpagp
vkrhnw (87)
sqkra (97)
oatauv (204) -> hfzsc, pvuno, osckuj, dcpgsg
ddeso (43)
lvbgvb (53)

Part 1:
#!/usr/bin/env python3

import aoc


def parse_line(line: str):
    childs = list()
    if ' -> ' in line:
        split1 = line.split(' -> ')
        childs = list(map(lambda x: x.strip(), split1[1].strip().split(',')))
        line = split1[0]

    line = line.strip()
    line = line.replace('(', '').replace(')', '')
    split2 = line.split(' ')
    name = split2[0].strip()
    weight = int(split2[1].strip())
    return name, weight, childs


rawinput = aoc.read_input(7)

data = list(map(lambda x: parse_line(x), rawinput.splitlines()))

rnodes = list(map(lambda x: x[0], data))

for datum in data:
    for xnode in datum[2]:
        rnodes.remove(xnode)

assert len(rnodes) == 1
print(rnodes[0])



Result: hlqnsbe

Part 2:
#!/usr/bin/env python3

import aoc


def parse_line(line: str):
    childs = list()
    if ' -> ' in line:
        split1 = line.split(' -> ')
        childs = list(map(lambda x: x.strip(), split1[1].strip().split(',')))
        line = split1[0]

    line = line.strip()
    line = line.replace('(', '').replace(')', '')
    split2 = line.split(' ')
    name = split2[0].strip()
    weight = int(split2[1].strip())
    return name, weight, childs


def calc_weight_rec(fdatamap, key):
    w = fdatamap[key][1]
    for child in fdatamap[key][2]:
        w += calc_weight_rec(fdatamap, child)
    return w


def is_balanced(fdatamap, key):
    if len(fdatamap[key][2]) == 0:
        return True
    subweights = list(map(lambda x: calc_weight_rec(fdatamap, x), fdatamap[key][2]))
    return len(set(subweights)) == 1


rawinput = aoc.read_input(7)

data = list(map(lambda x: parse_line(x), rawinput.splitlines()))
datamap = {x[0]: x for x in data}

rnodes = list(map(lambda x: x[0], data))

for datum in data:
    if is_balanced(datamap, datum[0]):
        continue
    weights = list(map(lambda x: calc_weight_rec(datamap, x), datum[2]))
    if len(set(weights)) != 1:
        for idx, w in enumerate(weights):
            if weights.count(w) != 1:
                continue
            if not is_balanced(datamap, datum[2][idx]):
                continue
            real_direct_subweight = datamap[datum[2][idx]][1]
            real_full_subweight = w
            wanted_full_subweight = weights[(idx+1) % len(weights)]
            wanted_direct_subweight = real_direct_subweight + (wanted_full_subweight - real_full_subweight)

            # print(datamap[datum[2][idx]])
            # print(real_full_subweight, real_direct_subweight, wanted_full_subweight, wanted_direct_subweight)
            # print(datum, weights)
            print(wanted_direct_subweight)
Result: 1993


made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript