David Lambert/AOC17
Dec 1
+/".&>(#~(=_1|.]))1!:1<'input' +/".&>(#~(=(|.~-:@:#)))1!:1<'input'
Dec 2
SS=:0 :0121 59 141 21 120 67 58 49 22 46 56 112 53 111 104 130 1926 1910 760 2055 28 2242 146 1485 163 976 1842 1982 137 1387 162 789 4088 258 2060 1014 4420 177 4159 194 2794 4673 4092 681 174 2924 170 3548 191 407 253 192 207 425 580 231 197 382 404 472 164 571 500 216 4700 1161 168 5398 5227 5119 252 2552 4887 5060 1152 3297 847 4525 220 262 2417 992 1445 184 554 2940 209 2574 2262 1911 2923 204 2273 2760 506 157 644 155 638 78 385 408 152 360 588 618 313 126 172 220 217 161 227 1047 117 500 1445 222 29 913 190 791 230 1281 1385 226 856 1380 436 46 141 545 122 86 283 124 249 511 347 502 168 468 117 94 2949 3286 2492 2145 1615 159 663 1158 154 939 166 2867 141 324 2862 641 1394 151 90 548 767 1572 150 913 141 1646 154 1351 1506 1510 707 400 646 178 1228 1229 270 167 161 1134 193 1312 1428 131 1457 719 1288 989 1108 1042 93 140 822 124 1037 1075 125 941 1125 298 136 94 135 711 112 2429 1987 2129 2557 1827 477 100 78 634 352 1637 588 77 1624 2500 514 218 209 185 197 137 393 555 588 569 710 537 48 309 519 138 1567 3246 4194 151 3112 903 1575 134 150 4184 3718 4077 180 4307 4097 1705 )
([:+/(>./-<./)@(_&".);._2)SS
NB. part 2 A=:((_&".);._2)SS f=: -.@:=@:i.@:# *. [: (= <.) %/~ +/(f #&, %/~)"1 A
Dec 3
MY_INPUT=: 368078Dyad=: [: : While=: 2 :'u^:(0-.@:-:v)^:_' rotate=: |:@:|.
NB. f rotates the current matrix and then prepends the next group of numbers f=: (,~ (([: i. [: - _1 { $)+[:>:(<0 _1)&{))@:rotate
NB. example use of f f^:14 ,:,1 NB. f While(MY_INPUT > (<0 0)&{),:,1
NB. computes the index vector of x in multi-dimensional y find_index=: ([: , $@:] #: I.@:(= ,)) DyadA=:f While(MY_INPUT > (<0 0)&{),:,1
1 find_index A303 303
MY_INPUT find_index A0 371
+/ | 0 371 - 303 303371
part2=: 4 :0a=. 1 = y i=. 1 whilst. s < x do. k =. < j =. i find_index y s =. j (+/@:,@:([;.0~ (3 ,:~ _1 + [))~) a a =. j (s"_)`(k"_)`]} a i =. >: i end. a)
C=:MY_INPUT part2 A>./,C
Dec 4
PP=:0 :0vxjtwn vjnxtw sxibvv mmws wjvtxn icawnd rprh fhaa qwy vqbq gsswej lxr yzl wakcige mwjrl bhnlow huqa gtbjc gvj wrkyr jgvmhj bgs umo ikbpdto drczdf bglmf gsx flcf ojpj kzrwrho owbkl dgrnv bggjevc ndncqdl lncaugj mfa lncaugj skt pkssyen rsb npjzf kdd itdyhe pvljizn cgi jgy pyhuq eecb phwkyl oeftyu pyhuq hecxgti tpadffm jgy zvc qdk mlmyj kybbh lgbb fvfzcer frmaxa yzgw podt dbycoii afj zfr msn mns leqem frz golnm ltizhd dvwv xrizqhd omegnez nan yqajse lgef gbej rvek aehiz bgje yej cphl jtp swe axhljo ddwk obwsq mnewiwu klddd ipiev henods rpn qfpg gjfdgs zcpt sswab eosdhn teeil gzje ydu oiu jzge udy sqjeoo olxej mgn gox tcifta vzc lxry gox gox mvila qdl jipjnw dvu hxk xhk unhdmdz yomze povrt nbww bxu qqsqc rvuk tgffy twddm fyx fyx nzkm fyx ymnoc zogudq yncom tqrob sidvy dfuu ccjpiej yidvs bxebny akknwxw jeyxqvj syl cedps akknwxw akknwxw zpvnf kuoon pnkejn wqjgc kcebrkj zmuf ueewxhi mgyepbr nleviqc dez argavx fqguii gebohvw klnrq rkqnl goevhbw ywqi abwi eswph nlplbl pswhe lnqx fpgk lllnpb abpb mpkw ampey yapme xnuyj tmuaq asd bhbs sqmbsnw wsbnqsm ydwdncn rpa vrllkh dnltf cck djy ydj wywwl scezo clowuz dkgqaj dohyzcp diimshr vlmsnlj whqb dkicau ckdaiu terp kgcii npqc vvzrqzv nol wfpxe sqf tbb ruqpcq zfgb kajykuz tsxgtys vuz kglmgg ihnnn plyjxj rcrvo mij plyjxj jqiur pxs hmet dwgvd mvhkvn cjxg yvid vmhnkv kwxz rfemsua wdgvd okixk lzwxas ddtyeh ivyama crrhxdt hedytd jfw vjfv oyd fvjv kfwlj mradbx mckseee xradmb llga yytxyvj lstspek lstspek lstspek fabgf wgop fabgf bvsfoaw grqnbvo tntomdw hizg tmotdwn mau ufkw cxfi rhehj ebe xyv rhehj acxngo arl qtl rhehj kbkto stqjtm tpcwshj saerkrt pffj dthp pfjf axc gwmmfdw glnqtdy xmskw veff zqm hzhxap lgwnwq twsdk mqz xbbarbv cdx fhnwt qjcji bbvbrxa fjw eds hofskl nkbsv des hvx xyn qzort qzort qesz rtq oonk vwzlw wapoj ifr cta pja hvy nhjg paj smtfe fmtse xvi tcjj xvkjtab nqftt aumijl xkd cmilegf hvsmodx uuo igmcelf mslkq mdhezgv lelzy kzfvsqu hvmvaxw pxiqjc hvmvaxw kzfvsqu hsicsav csshrhx znojm eapi lhmzq bbwnz seao gfk azk pup xtgjyzy wqt ijeektl ktwh qdegzs btj pfwzzho xdkmdm izqtjrr iqbke vtp fmrbpdr zpccv tmtwx tmtwx tmtwx bys ehphfgq idd ehphfgq ehphfgq uphe hvrc jcscne nbnslqy xzqucgj fcih fljk barz lvln hcfi azrb cmfmclv mfgvifw rnxgn jpg bsnq wnduzj ymsdx smdxy pqomf rlqsm qrsml emts qsmcowv scmvwqo tshzkpa zwtpda ftsiwo nil tpawdz kjpa ptzashk mnep sfc swjawtd vnwud gyulluw zpa kmwyvln evd btnmoi dnwe jwq scepq redoxmw rbdzsa wlkzso kxpm bttg vxuc moxwdre ijtdd rzsabd wpvo dsjox amuwjm pls lgwksva ctakgpl rmsjj lzwwpr zzm udg bji obbn tmwyc afpmkxr glvrd kahhgpq rna qkxyntp vmd mloshc ymq rtnr nxjzm pqiddrn qmy vgxw ull mmzk ikge zhtzhs xyo qwe lll gjjm icetq qgrr mzwqa knec kxomfck idlh xrbowo nyetbnl qskh xuwkkxe upmmmf zhvuyp srcwyhl czgr xmhuws jueyh xcuib xhsuwm bxuic crkueh beyxopz xpyozbe dxgadw qktmce rjropjg lbktun imdpcp fkssp fhcpt fehho jqdnt aoewa jmun pynzjo trs ijwcc pelf oft pcsqdxg zvql mneaaq vjrg jidlrzz phd mvxpivd ldkhu sao xqw nrukn gatkz quscpsx vmz oscoeb goi wzxhb rrk aylqqcd mlcbvvf ororn heptid kdu byevr qsj lsbieef deez vzwdx hez iwd lmgfb keqt mqbsuis ogrr errbi xiqe xsszacp ato hmk zfjaj kmh plxup cida dqd pfwh nkbxvpr buajw pxkrvnb cli bdwu vrwott vowtrt grle zisgks ciuaqr zvk tcb kvz ugmtv oegrojm wofpwp gnaocx rweyull ellhwow dtefylf dqsz oiw varr bcirpf oxusz oydkmib oydkmib yefts gbl gbl sruwjk pgkrp kea gppkr zdcky cfljh obpxbax jhpcrj slcsa lgd fborz vvpaus wsrpsws ifijuzo rixz jwh uhdaf hoacv hdfua kntk qprmfow kntk tbmcjx vnqe ooyxtb ixl hdmnpn orpz ykspl xromvj kowtq wmho gquos ynk xjjqw sut lmtub bmtlu zdo dztlk bpkuul smhpx rbczg zals csdbe sbj dibicq kdfwwt coyy pjddlfc lwvhyms ldjdcfp ryubz kfwst dqjrjja jtv jjjaqrd jaexhms iqoiln ewgyr exmnrr fsr lgmyy fdofhn pjgyn hfoz zbcnz nczbz ovntivq vcey vdrkse giu ohyaxy ionyy fvpn yvwrgrv qta yelpz htbk njgeyub tggh mdthzp fwyux rduqli twlhfp pnh gywif ttn yxhsbil vplsmmx rgtq grsf lyibxhs hctnkfr awg lmloz jroy lpgb wga kzytass szyksat tyskasz ehmhhu jkus hwjv ymnnkk yffugg cvtnits gbl lywkn szihcn dbrbalf rxqpbqh koyfcef wkom mwok qgjrytl slmhry lcr slmhry lcr mvoxbt cfkz purnsui xar ouhtc thbx xcdifw kvvxyrj knac qmypw bou tmukqy eusgaoo bktiu ablgnhb axumg bwpxnjp zqpc vtw ghhoxu zqpc znfpvl ghhoxu jlg ntdk vmvc cdkhrx cvz rvxk mmcuo udpcayd lsmm gufduzt linj mgyeqkv hqionh rgnqgz kkc qrgnzg egkmqyv topdp koa dimwx gjxa atlfdy uuez ueuz zeuu ezo daq ofpaw bgomvmt mqa dexpy mbipd epyzcoa nuwrh vwly xppz qkjrleo rwhnu wok grxk lchvtg plrzr lwaax cfeu ijapws dmkdwc cfeu zkd hysxxip hlydw wicsvy gbwoaw dapre ktjn dzg uri blzh hblz qgmjceg fyf vkhpn xnc ogva pjrh cxn hkpnv aja cldzta tdcazl lorr fwmxxh knilf ges tdhp gnlo vihrl ucpr peair nlbmc msfg trv ppq bmo xqd vbui yegsr xqxawu fvuz aclhspo wnan loiq fvg kare rmgq hir rzo ossd ziw renh ygtkjys vda xmans kio alexs ujekfl vvf ddghn fcxvsf bjuytet zrzsobo uhn mlfzhlq bjefs zys htlqvky plno pbcqfuf fjwc vshkxrl lonp lyzmy dqmui vyyc glad tlc krhcter krhcter bolk tlc opryl idcii dverl uswb wusb zgax zhbt gjsnlso yhs cti npri rcbxjdw ollj nirp ghfvxzh blyhug aflnrrz zudyw ccnstq cyoju jxtqoj ntuknjq gunjiwy ycuoj igac cqctns bul yehpnw jifjrhc ifetu ufrodp hqzpeqf hdvpc qtvgxg ibb wcxsitx xztshb xzct scetn eoaufyo jtudgkx xrpgxip lpubtq juezstc nuc hokswh obkf ipbu nfq lwpmn qltal xnphsqs zlrgf iewtrtd mqzsob duokpy kfbqs icg vil zjz xkqrvni uay ystq terrrnt lnfg clm lbs ptpiy ybcuup ayzjm pqugx lmc yppit mbf dtajh vqivg vnblt fmn qxkw stiwna pclrrr fro khu wbslnqp tjyosu uqlehn tjuiy obt uedct bbwiq uxndqn hiqfovy xiimca zwne ivunvjk cmctzi mxnnrx dclib xzaoq ieztkg shpr xuorihj chuwq poadbo mhtvex gymsp iltgl sypjfua fmyh sgiv alv nxjt txnj bhact vjvtrex obmrxk fgigs meixbc fggsi awi rxdjpeg ypwo oicmbdw xbpeeyj uabzj cjvutvc oicmbdw immtmks exijri hogl epr gzdqyur xiiejr pre ihzlgzu rlh qfhx lrh qmvrx kogq okhd mivmivb mivmivb okhd taekt nhjaa znbaahn iaospxy jawwf ytdvq ghtqwud jkiig mre kzmmjxu jba nwpykc ktyzr aczd exgadhb uinrgac izazxky yyfe yrifb qgc lsiuapg teyelxn ugezu wdzkc ltx fkhncb hwrecp kfbchn sfcpc hjvq rjdjyt ahwxh nvggsmx lmz oshd xbcik powse ahhxw yhiq gxmgsnv qdr qjnam gag qjamn kooek mqnaj pza gml opf ilfbblu kjp luilbfb rhfrzgp ixagj ofp yphz runy dhull bozcsgk wfxekrd akgkbz urcphc tfyxwol lhcl npik beug szatel yfkve yfkve lzqhs yjzqon pcjibu bdncmcl kczuymm pbmg nyn rerqvs aoxucwi pmstl sstawu joqu abvcchg mvgjn mslpt vhmfkr utusuh gqbec jjpqdh yeaiavi nledfi jhzwc vyxjpf momnm vnknjs nvgjzik ipm psirt rispt lrkgma irtsp jbbaph xvunete gsvnr mjd ifxhpry cpsx hmuokkx vhcm yth shrrl zbhd gfa bcmlxtf sqyanrp cugg qxfvftz pbl ujsgc jajxltm gugc oil xjuhyg aht vmyvzhh oby oyb ybo xbybgmx atfk qjudfzz mky tfy nxk yzy jqgg qxgjt bevvvv efi xcbw bohc zaqlqjq hdc qpnx ygmtqw acvoa udboxw dhc klh mwgpk xfpuri cycgbkq skwhyf skwhyf veaqss skwhyf jnezf jowjt vsdu uck scgxd fvopomz vfajslp djvi epgkyqn apzd cpm owm kpwih fsr adlhqu jicp pmc erxlmhj wqxvofi ugj ttrmtsb omku vmrgoy tdicbje ewml dfnwbap gpih pyt ptsmzc gmdbu rqxkqmz objm nurxjz oozbere ztxug koth jpnl jpnl dmeh qed intdwv ksgw qwlzhq zpd lrl mwjl dozrjwq aujbet bsnf vhqyg eqs uot qyz xor aem kmrh mrhk jqx tsbrf irytjab mdzm qbb kkjt gofiwo xgbovg kyeyxqn tcks tljhx zgejy qodgah nqavvx xnigdvt eqve bizrxq lkhz yzwxgt nwe zfe sxypkz xnssept bxqn lkfg yfxbszo sphwifz wnj crhbq dvokzw vzn afatwye ogzvnu vnz rfjba xtugnj kpbgly ocsjd xrc cxr rahv yvhk khyv bed ctgbuq cmqwpqa jlbg hpj vmesvw jbshkya dgqw lfl mzcch jxsg czcmh ifruvlw ufwrlvi xcczlol cqqchmr rbk mhn tnmqdc sxnnn kvoa mhn sxnnn mgemob ieiyajs cqi ghxg ghxg ghxg uqwdxn qli gdtkngp gnptdgk udxqwn dmcczr dnjaqc qwdta rhrbi hkdwe qdjcan peic iulaz xns tcmppb nzq ecy sitdud nft ecy afrbf wvnc vmfpzx tcmppb cgb plitv efnpq mjqav nrxxo izg lpitv rwbzdo rdbzwo day dntga adtng agndt hhvtd yrg iudsh gyr ryg qttyeew tco flq bszw jkzftc wdh efcwnp mja rfmju moch prkze uslzyv plhjuy kxczyq qlmm hgq xtg ypz izy ixg bvs xlqgj xcy sepza abiylsg wxvsxn bqag jnlzgxq ikxwa dfd plqxl xlgqnjz nuqvoyb emhodso gaqb bzjdsm xmxkj fhuqn gauyw ntl kjxmx zcxdr vrds ofjcc uxyzlk ofjcc ofjcc zwosex kkvwobl cpudsmb kes zklf bayuojr otqnyr udbbs iqpvzh ybds piovrh oivprh voprih pov sfl upns cpeelht xboyk itb hsxdmt dnwgfbw upns fygf kwdpxzm mli dyy djwutl sikh shki ikhs gecd jqkon trqyw prbbdf vdp bvvfjcg ydqb muxygg vhpurzn psemqe xwqfk hrvonxu nxkxacq xicmhss tnpja qiad woipfy uvadcq usljh hzgs jntvfv wzikk mmupc twntp upcmm pumcm qnisuzy lppnfd uiqr eyqbain uxlp eyrfwjo olgkrps sbikam zin vckr nmokl skfni jcdfot njzqeaj nqzjjea slmaxx offfzqp wudicrf nfn rwfcdui cwirufd paffi murnjd oyj lbtjdqe babuas dtqh qkt stapzl yrqlp eedc rig zmnfmn edec ecde bcfdf edovdj lacx nzvze sordvxj ybs ujh zvvvp rzstejg ueosuq xrrfsd okuvem znzlvmb jwzcb bfg bmuxbc qzwfry pqgxybd cvgra acgn ocd ancg fvfcx fbb bfb zfzv tmmv mpywyg fwl bnvcv lcnv flw xxnfbro papc ianru beuzx apcp rnt wuyhycj nrnc cka ebg rncn rvo wcyhjuy thh cmoog hwf imqfp okzpxd rzxiqt rtaiy ytria tyria cjkmro myif myif xyirn aqxlol wlhwibi dhzsen pzwgm bfbz bufjs qwffg mxhiui umiihx zomyll vfieccs yyntf rjk iivgj mwh rjk dsshx wsmaxhc xcwuelh rdsgtr wsmaxhc rgtsfj rdh nwlxiwu xsjzbpr bsgps ufyo vqtzkg kpeohu mxzt fyuo gawgaq youf hzbhut bxsnjwb zuhhbt zhhtbu pdz sgntypg ragev hrrji goitft yphnebs xjzoo sqf jsuzijq dsocb hcxg pptsq woomypc woomypc woomypc axcg wfbnpql ejqb cmnn nncm csvlc wraludb pkmp whtht tfpicer moom oomm ommo vfqeii xvrgpp rofl yxyrkb oage nypzau pwfnkn jxnhkw cyxsi clzb adwpuh mfbz vdtt muzhm wvwwfl ttdv cpqgvbu byc pgfrlkr aftl tqm zcqxi juu gnf ppovxh huoa konpcp lzordid jqng lwxs nqgj gghkxmf kyn ngqj iorhccj xfygc cnfr tysqc xpcyf vmjpitf nut zmrk mgbrtb tcblxwf dkadwrm kov jtmp xoatesx qxkilp rmggpfx ltpxzwf vko reqms mqq nps hjigmk fyqy wpuwe mwmso thsimfs okcmeyh mzqkez duzaq vzhyrm uyvpkox cwivpls ukoerf korufe zhs ntwfz hugem vriyk enfaib hrrcdgf zllsk vkiyr shkx khxs wntpjv qdevaw noqyht nwpvjt egh hgok mukdjfi law bzbvjz dquk kczxsq tdu trnkjs wqtdc ybvcb hlrotxn cumcjkm qwufgle ylm nejh hnje pvaigrx myl sfvsd szmvisn aywic vsnimsz iufmybr zjozr zojzr qmn ffrggdh wam dafvok nxkvlhr posmf posmf posmf zhlzb ywis kpqpyb qae zqxpuz pcj hbsfz ejlwa lajew znuom qxsl ussivur dstd avojo yoeagao egpaqm ymzf kkauy ivm illir wsvchne skmamvn nqxc cldo ixzzy vhk nra zhypgab qjdd ecxud tbuqq mpotbdk tjdpczn knncm tyy rbfc fhhjf innia tsjbbbv fmtcuup rapvhqz ebpzt whdbms gvjoy lykl fquvcby bihhfwi lhal udxz uwjwp dmb fekxamy uophet yzvv rqj zawlp ldrv mdymkzy taauf rcwxvmh edueui ltdyo xfghz dgjig senm ifj qcu fii axmgijj ifi oixjfsg jxagijm sdtyr rbdh yvnvq czzuig wro lot xkto cmpiena nht ozcg aotcw xiegl cyaouj und lsclep cexn pgihljk cmgmv sajhi zfvbqij ogwoc ajsih zmppe jexwkdp dwpexjk mzjydfu bff rubgdb yshfhx emkl hshxyf mkle dxgti jdo tkwprv pbxbrqd oiz gsbdphd qotu utfdnq tzvve bqc ovdf bshfxyl xspjpd vljdsm mgkd djlsvm mlsjdv etyia eytai sfq qafj xzgp ewhsn snwhe lhqp zjz mwh dorxm ges gexo rckwsa dltoq mmntha hqkuj ypsjcxo dixbe rmvnhjh ovnr edc iffaxc lolu xwrvpb gva vti vit ceuxq xbwejr lzyvm rozseit cwe mham fivpwj qtv omaktaw alzdrk tsxbuld mdbq pgbdtoo xwf vzalric nqe jqwlxsy cbtylu dtubxsl lqm rqjmjcs exjpn kpilcgu ihcm lfadjm mlri hpd vqs cxqwqhu twxrtk aeuvlcp aubvnw riedvz arypagp uuvg kliehx cokt ogh xsdw cdsyywv ddwrgvp bscaq bbfv qrbutp jpdg uey eyu uyarl zgbk qyhqq fdvlql zmwkp kbt bkt lebhpfu smrzt xalw mmwa zmtzfry tkb fcvcv oewfzu fvvcc mldww lwdmw ejrltsu sqoyx wfvsdbp bfdspvw bfir jqhgrmt ofdmrjg ysq jzwucwn erqjd eikq knpf cvk xvqnscy eei wvfjzmj xujq cqaim boev jqhkmr ipjpj zwno ybu krhqjm zqfyyzb dyciy ugwsw rpwteje qtvwi pwyhrzt hfcdfmc qbovk ibws ffy kdder qjookz bfvmvvq yjzuaj fvxllfb pjyz jcezhye fimyydt qjookz qjookz loupd nwsc yytvuqo ltcqxnf iho ulvxguz fxbf iqu ofjtmvq xhs ybbusd kxg mebdnah ucttcf zufb wzdb wumuhtv kef aavv buu xmjtlur faaccl wospwff bjasr eapfsi jau qzszci ciu inagax kui tqig fyovsp fvwol fyovsp mzth tcp nhoq ajdla wtpj amylu jly tvq wjqef ofqc einz bdze tows bdze eew avwavzt aesrsjv lbmpi hllv chdbul ezelxn imcprs cafb clfg rsjo iylqu nvk vkrq izezlnu vkqr tyhnv rwj zboui reh buzio wuhpvid cpzy jrw tsbuiby hmxwqr ute ixq luwbi uoiwsjh souz ysoubw uilbw ffwjvw ewzswoh hci zmfdaov whowzse xrhgqf xrhgqf giyv giyv toiqgzv gakg udgdlb wvi carrn pjyha muqclu wuxthi srtszr ourab hpds bakvy fnk yefe yfee doowxcx ijdc ujhvls xmy hwg yetsda qelbe nang xgywo wgh bhm icq cnam dec enksf qfctz pwxoo bdf cnma xoowp rbls jguzh fextz yax kesaunn waljo jltcza tfzxe dezs syi ebwxnks flvq bzgd clvqw ahtyvu xbdyv wssxx boscm grgl nqcg caskpli hqctxxc nwpyo wjlqfqf ebti dva wmsz fzpd ikgeq gti ejftoou ezs cqef mybojc rgwz mdaay yfppa pavl fuuvfkh hpod tpb dhxmia emdecm rbqcwbk vecyt neha rmvl ndp vlrm dpn debghi vyhvc bnp zkxdu iqqkesd abtlx hmjasdq kyvekr krt srrjyd oxmfev oot dumlcqd ccm hyir oritdz madjjw oakqrs advfmu verrc zkfdcn btndsp onlkinl rdtm bscfxre bnu oumyrvv kgc zkj tfxfsgm uwmic agswclg uofezgc wpfdyjn kjlihk etbot fbu scm gwccce xgownte wig cuaijbo bzbdk etozk qracb oftfoo lkooe xupzw vmxwu sis wzpxu gbz oqbgh jwgrru bzg kwmxcfc jrurgw agyjnyc tuec imxlult omwiyjg fiwnoqx nhmnro qtg kbr agyjnyc koiq llreotu elrtoul dubfvgy whq htm lll crzppb gdjaae nsmxzh gnfvn obiuy ymspzbo iuboy thm xlfrr pbxdfo mht tygi sapxgbv mmngzf dej eus seu qmstw ues yvfsw esut biblze kbjcpk estu xih qzki ezlbbi blzv ohq ugc tqqeo jygvpwm vfs ldnfibp ycbpa sml rmime kuuow gbg nzwdaf wiimtg lam oqmm wsbwkdd hda nqk ticz mvt gqbljyh zqugqs cjod sxwlqy qkfs wwvwvt dsojb qbhjlgy riusoa uosari jkphfx dbt les jsvoij rnuw mxmmchu dol vto swn qqxe vwvephr twdqlyg cvdu xjiych clooq vkwavl whvverp yuz vkwval txtbudi tiutdbx wqhx tws utgbf amh hmf izsez ooz egdube nhsxjs nxjshs xoy sjsxnh egdziod diodegz ejxn zogedid uhhkr rnm cyvvuc uqbl rbn pinwag sidwdwv jqdbe jlbemk blkeaqq ipfqbtn zkrbp bdryz sbh wxvn mhot wemsfm oemkff vxyn xvdwwo xhd vyca zxjaw vfkz xhg ofsphks dyq mmzzd yjrqsjf iiesdh envwyx rmtbmiv ggzsg ukx bprfym qmyqc vag ymho hjtoh fuxxrd wbweptd vkoffr wbweptd gfwcez smetli yjyh pslpz qyokpsm qsy cxjymg wqfkf obuq awz eqhm ceest kayf heqm rdi dti vntcf ewkmpvf jjwoihc sfq qlb xrm ocy vtnj zdznbal zvon stln zwnj wsgalvq vhphap pya jay mgnyo pya xmapdn hrwbj xhr gvwl ktq ktq gvwl rzgqi hjwtthl kxhggbl wepc hgavj ctmqug tzfwkc xeqfath iiuwq iiuwq dhwuvy gibagy smq getjofc lum msq ulm xuxu bilrus ily xlv ndrkch hdcknr nqltoze xvl wmc vuzlrj mwc atp cvpx atv ujatz hxpafgl ymjltv nvvpy ahycdk jhpdcks ettm lvqyw ertpivm dnezwxx usi kdhcay vrh hqyomv mcq ilwjbkz yprjxad ugv szfitxg zeluib pfj ijm zmiigxx gltxzz jzljhgh otskue mxp bilj jlbi tce yfted zxsqas ftyed ykasqv ehye kirmnl upmi dojwmw wzj ykasqv ifixn vreoypz kerbgub nnroqk onkqnr gbebkur tjhl knjo ccsem yozvrcg ygq evkoj wkn ffljhds scxeibh egsybeg mwvi vgjblj qda ywqpp hocvpl ozgkxp xgmj ejzyxm gernu kks lxe nxzv sypg xle goz xoatis fjp wzlbo dzkonz jtutyj vdonj swro tqclemv xhomap ymeqkua vaxcw mxcyjs ywyxndk wng vpftv nsuvu jmiyyhh gwser shgcu jmyg cjzegc hmhe eopg kmkan smdd dmds mgqhtkh qtamih haqmit skkcy dnj rmggy rgymg uburbao rymgg klcpjgq ons ajyv sqryt son pjlcgkq xlobdt piw shonk tzi mcdumz noskh tebolw yaypn ozm mvmjgtg nxj weommiq asnmhzq xjn uobztuo cqgjh utfb oydt ommiewq qlwgsc vvpe xgft ahpjc zjtx iyof scwqlg dxgcokx ltrefj xyzq rwto ggqdd dqgdg ggdqd kjkmmfp htzjam fjbg iagc xls iagc iydtf ihxl boa iydtf vhe nqj bwgdoi hhaoa qtulz axvyja hpdkwee hnryj prou rgadv oubjdqg knjbc caz xibj wqkzwe peioeya vmz hesy ftb dudwcr gupj sjrtzc xsqbb hiet nujv bebcvsj eks uuzlcx gex kywozi tfzuc mflssw hnxxxqt zzc tzfuc hkokuv mnjg lwkavjp lvpwjak xez izgh zfv cingjt dkf cknite qox vfz zvf ojpu dzk tehpgnt gntpteh glxfxa uxq ajtles ahgzn ajlste zwgc mrpu adz wuunwhc zda hdgdtn hnoyz aromkb qujfv yjgmn tbf atw uyvsv oaopjv uyvemxk ldpp tthe iisjk txr hebmd yxevukm rkziao znt ypdr mnwuzvw acpg kzwz ywbn wcrr umrnlbe lkult ljify azyhu mgqoo abmpl omsd xmyl mxyl mgoq kracrf ufm ppwi zpggh uxfdpv jnm vvc vchunhl ubv ktj mxolsxz fcja eci edzrb nlvksaw lhf ycohh tfztt xso ceub tyv rkwtp tcmmvv kufg cxui hdamg suuaej fgku cvjlv oldbgy riadoyo djsi wca zxoeq pmemqap aijxa nyy ruxcosx xisqoz yny jvzfpbe tlfdiaj ybd jifatdl zuzv kxwdz qvrvx svllp ergmme swjfuv eronk favcxfm acptbh pnbjn ciqcrlt rgvdnlt icgahb ddza xxfn use obqka bfzwjp gmf bld fyvde mxdfdl ame bmxbyf ame bmxbyf rdgby pyfog dybrg gdryb lpztd sntg impd uxgxai naoalb ntnk xgix oadpmqj oso criln izih oos ouzjq gtl ito xefqt phnv ouzjq hoyjjj mlp rboq lpm roqb whvp tghcw ggshevw dzsgj ggshevw kec ggshevw kmwhb kfcb mbhkw gemz fdh euve veue kplrq evue hikfiw bcdktj hcnawja gjasvwc vcht igrzly rkxijxe ikfwhi dvmp hvksis kafs ktcs sfyqzyt etctrgt vodwr wff tskc juobnm dpcsodn ehwc pglywfl yhdp mdiyzx ibog umftejh cfm pnxhna wqwx yabnk ygws dqw dezz tqw qism rarfe fpmlab xvbau irwtfs wwmoyss yvn xetqp xtqep pchqwk npsmd jefec qok uuc ucnpz rlkakn kudh rjysb xrdbx bkbmjfo xrdbx rogu ssdwsus voa ncw obkxsr tflf hlevus scq rrbpat tau wxsq wxoblt rzr lex kqdy whtj ffnys xlgkkff msjhy dimaq hrc wyde qkwf ghtwd wernjpn tdgwh olrfvmr edq gxvp rjirvf skhdgln aauit bipu mubjiwp kowz gyjfbjx cmgdqs aftfpbv agajyy aqjll vsf twh robpys lebt eav yribup sby ymkla sxkbfwl awmd nhb vlp kizvjj ycjswr jkzjiv vuy jijzkv jcs cwvch xzqfal tephz lqfzax cnkbdcr mql zflaxq jjxzwl himpra ssjf bibfiui seeaq pzse jogrn jogrn sqew jogrn oixgwr khonpyw iiyxir vybhc ndnxxv kzlt ipmncn okqkqu svbemi nfn ovd xgwy edd ujet nrrbv dde vdo jobvf dus asvio vaosi sovia knmz qbz nkmz zmkn isbmopr unduey impobrs hea zswciev sopbmri duuj ocs ntgnrdu kbvtzp cvyieu fiyn znmh lhrz ixtnzrj vktbpz lbpqx vzkpbt muduhc sabc dlyoisz kuaz ogpyepw yuog ictiiqt xjflsf nfklvml thfh uajnmby cichyj xxoqi lpime bxpyx riahifn bohbgd obhdgb jni qzvkf ybp hjkkwq ytutd cakcsh smfdoe tuytd iddku nccp zgtl yne ppzpqcx lwm refpcz uqt uqt uqt mtn czxkagb nmt caqacrg bcakxgz itxjii uethxbj vpds bsqod diqax inv zrwt doepe bfyaj nbvhg zmi buf dtre dkwdr nrapm qtfth odvt bbcnae vxuk gqm enlg ybt qcfozrk yzrh bfp euuozuz pzsdkxx mhi nbkzprb vpuhqn gyx caint antci vfep incat kqdakdx ddhi chgnjk ibg xbemitr mjtdph eovw ngbtuvq qdttlsg dbqhhwk bkrqze qdttlsg qdttlsg evn smvhi dgcmn xjo ascc ahbpj uvzc pwn tung ksu thr omg onvsqzz rllakar ysfjtfj grxwyx oawix gpk suk qvb iouav yhtndkd vuoia ouaiv kud kofcip hcczrgc cvvxxlk rvyamwe duthdzr dftun rgv ynw gph tmxwfup nwy dnc trawj kwzbx trawj zvp ogqxijy tbqtsg tbo vqinnlq jbvgl sfafh rve mcxqs ubh qccr lpv puuvdyb tydaflf uxic tlon tbfwkxg tlon tlon iytiz qjlqaqw uixb lnt zwro uzgxqfi gklgnqs zwgoidw iifk wkwdo tmvhxw tmvhxw tmvhxw fhiqpjy ejk kvysd cmphg xjjz groiccd dvetuk xbwa zhm lyi ohhd neg bxaw yil kdmzopy lxx bvhach goxmxu qbqvzcm qbbrhvb nrfom aixmio grpxz hbrqbbv lkucih bnqn phqr uycuxc mopyyfh bbpesqm stgigq stggqi cwtjm asqhpl imvlxj lbmloo pws iuvbvjr cwccm qbr srqnstz cjebq bfh jobkcy gtbroe lpagq icmax jobyck fbh ounqdo qrrr pwi alho rrqr beao rsioepe vrccqge qvcgrce cbslkjs qnclw rvmjkw aaxjns deupjs wtgxtp penad depbho tbrdt depbho qxg zhjxpgd drqfo kbp jfa jaf izn oczcitj cpae quvzqo iwwk jck idjdpm ecort zgcvxx bvh vrprsf fhubfvy ndcfjo kol hyufbfv hvpka kpt zgajpc rjvsxa gayznjd xeoixk peq kfu lqa mjnv mzvh bicl hlfk wyt imdx lksy twy xeptp ilxs qbsqzwn rsy slxi xtpep dsdkekl rotvbt fuirp elos ciu nhx bxej trmtx ixn xbpc vrxtma skcprn yns sao ghlq vftezvc aaryahy telt fkaov gexa xijv yiksa xega dhgw okfva gxxs edkecag mqbqvrm nrzcqub ljc jujxeof fdj gdzjzr mabbktu pmyrfv uspven zxry snt hrah nhujhdr jdhrnuh midm bbavhpp cpjk zmpbasz eptrpou znq zqn ywzfq wuu lfflon uuw rke qzwyf hjbms gakx yqrq zsk jzn uuuzrml kzs lseupsg waynfh blech gwyqej weyjqg uwuje uujwe lxud rnwkc bgygkh csq rfvtos ystqp keb gkakodj uthcce eqxifl elvj evj rfwo vvgkosh aarcgjs utsbh orwf jxcqvmh uowmktl qtgf bqszre oxntty ombwiz mbiwzo ccp iilcc tacf czk giwv erqi jgdfah wip xtrzhv wosvbyb gymyw rwsxeg gvydr izyk spsonkg knospsg djj tbr tbr tbr ice yyzh zkykapw puydtik ysxc hjumhsd cuhhw dnnhida yyzh lnklymg nhbcxsu ccrbbyw scbxunh ghxrkqh brcwcyb latdaav sexa ipzuzjl ayusb etb fshh giz akqd vjmabii arfuzgv efrww jxkvolg efrww vrnzgbx jmcc vqy adkzj fqrkdo tjrczp ccmj cfponk rptzjc jsviu sraw imsj fujm cdf xwqhl lhz ojejzuy trtqblg ibz dulm muoq quom etvjzxn tuhrpp jfukac jqctqn qhgbae msgmcit ludm zgx bpfa elhp rnyqtq wyceube nkeuxz lzxfo vygpecv jszacku zfxlo cpmv ysaaj xnp wbvqg hrsiuj venjxna yeqvwmk ftaga dcqxc jgapb rqdixp xpbbe tyn hfdlu fto wrgzkou sxylv cqto wdv xqc pnu rapk pkrxypl wnu oipq tzbhnc gpug tgzf ofjb mvaz bwcv gll itgcye dessw szt gzimgeu bvmohh wbywyhc kzerxbr anjsive lhvnrzs qkmjwy pnyciwp mgp jfdz ghvtf yusfzg upab xbscukx aubulj snbcmc uscxkbx ddpucyg hgv ollh yzpjmpy fcicyae vhg gvh prd onyd iux oik xui zipadig nvewx cir lbpcusx dljqy ifyxzsc btmy lsu tmyb lus ldyzx egmyxbe ieasvek dylmj qahtatr uyqgbk mejjczw spj vaekp kdud vwan mgenld mnlged vpfuil euoxlr rclkpi dfknyoa rhthij kcyxl qaxab crlpik pqm eihogk iwml nuauxi ngilkoh jmu mbdi cqxz nblb rmuj zczdgp pswbe mtzch wbeps fxtnc psa aioff pas prwrpvz oadpqvz tgzrt giom pjyihh rxdir dmya xjolzxv khdybe obqkjn kdq jkvmgwo enpat wyw qjbnko waid msest wwkoyts yep liv ofmtpod imdd qyw afnrx jgn gxarpb myltj ggrsajy mdaobjo vbtn vbtn zlziz eds hqr kqu oub skoeqk icnfm cqvld aay bto rga odaf exoosh pwevx zpbd plaa xoseoh mbr gqu oxvchrt nqa larxmjx pfozej ozuo ywubjbg xcua eblwqp nfdvw hmhen zkjfu gmhgp bsyi ktprtf src vrysby srybvy znwjm hmypwdl gdmau pqe cldr crhi lbaq fbuduyn hygbz uhida qrxukq dygkp oaks soka oask vpido ajgfq pwlv hezt fmg epwrxo rqvjke iovpd hhkjm anxf ydl xnfa hqph olorp exydcg onxjm psqlbv ehz boar hze qsblpv mnzrvc ipj swg ijp sgw gdkntsd fzz grqwly erpq qghpj fay gci uglm afy jwbq hbxaub jpdilyt yvalrlk topl qup eczonk ftcc paltirb owz tihhe dglxory wthvqcb qdnxm lirejh alyxsr ooruaby gboyeu lkv arrz jcqyzl uxlfk fhmeony fcmh wzr xjb pwmf okqj adwcedy lkidve uwekxf asbdzr biub dikhur pxgh urdinjh wednf ulzdxs iplf byt tyt qnnlba pzt bednml ljjtkvo tjovlkj uwms xat htzk ltmfha xikeze atfmhl fchxhyz lqala bqwgcul vetaa xuxjau zcb wtdmomu wfqmpq sief uyblyz ahv aytvvo awm ojaaigg awm dbfaokz abq npcyld fzbfku oia qss jkxldm wgtmki pasgxi dieix rpqnuac tecnfy nmr qzfj qjfz lsz vnahex djxoo jzlkh svy xige tjlkkg glcuvmh fwzlhi ecun qlgulj hrfhyql qgdlf ofakqdf zokkvm gelxkq oowgs upfpk gfstjlv lxc rjd nhj sbq jpzsz zsjzp favd nzqfdid nekfjsf mtjndu sgdqx uvpuefv vhwrgd aivav gsqxd jdhfoq llaf cthbgy njrpw fqgkx jzf xqkgf lnrfrm gkxqf wzdwlc wisst alw kyjeur sjsqfcr tta bijnyn whfyoxl dtjr baxkj lmnyrlg nrmyllg mtgky xmwf zdko nnocxye gytkm ygp hixk xwmf maudjy okgjga uadjmy dzfrk omd azz ajdcqkd bcafn zaz dcjaqdk gylyzo xzvfbf fopmfxu mvftgr mfupoxf coyhof talcc vpkslo )
+/(=&#~.)@:;:;._2 PP
NB. part 2+/(=&#~.)@:(/:~L:_1)@:;:;._2 PP
Dec 5
LF=:10{a.A=:_&".;._2 LF,~1!:1<'36b5.dat'
part1=: 3 : 0
NB. return the final program memory state i=.0 while.(0<:i)*.(i<#y)do. j=.i+i{y y=.i(>:@:{)`[`]}y i=. j end. y)
+/(-~part1)A318883
part2=:3 :0steps=.i=.0 while.(0<:i)*.(i<#y)do. steps=.>:steps j=.i+i{y y=.i((+1 _1{~2&<)@:{)`[`]}y i=.j end. steps;y)
part2 ANB.+--------+----------------------... NB.|23948711|2 3 3 3 2 2 2 2 3 2 2 ... NB.+--------+----------------------...
Dec 6
NB. 5=#parta TEST=: 0 2 7 0parta=:3 :0
n=.#y state=.y states=.0$~0,n whilst. state-.@:e.states do. states=.states,state mx=. >./ state i=. state i.mx t=.(_,n){.(-n)[\(((>:i)#0),(mx#1)) state=. (+/t)+((i{.]),0,(>:i)}.])state end. states)
partb=:3 :0
n=.#y state=.y states=.0$~0,n whilst. state-.@:e.states do. states=.states,state mx=. >./ state i=. state i.mx t=.(_,n){.(-n)[\(((>:i)#0),(mx#1)) state=. (+/t)+((i{.]),0,(>:i)}.])state end. state;states)
#parta TEST
- parta 0{:: partb TEST
Dec 7
Dyad=: [: :INPUT=: 1!:1<'/home/lambertdw/src/j/adventofcode/2017/36b7.dat' A=: <@;:;._2 INPUT , LF top=: #~4=#&> bases=: -.top base_names=: [: {.&> bases middle_man=: (i.~ >)~"0/ base_names base=: base_names #~ 0 = [: , |:@:middle_man -."1 (0 , [: ~. #&>) second_row=: {.&>={.@:base
box=: [: <@;:;._2 LF,~-.&'()->,'"1 weight=: _ ". (0;1) {:: [: , select select=: [: :((= {.&>) # ]) top=: #~2=#&> NB. nothing rests on usNote'select'
(<'ebii')select box TEST┌─────────┐ │┌────┬──┐│ ││ebii│61││ │└────┴──┘│ └─────────┘
(<'ebii')weight box TEST61 )
Filter=: (#~`)(`:6)
I=:1&((_: ".&.> {)`[`]})@;:;._2 LF,~INPUT-.'()->,' weight=: 1&{::"1
top_mask=: 0&(-:&datatype 2&{::)"1 tops=: {."1@:(top_mask Filter) base_mask=: -.@:top_mask bases=: base_mask Filter
b=:3 :0
TOPS=: tops y BASES=: (#~base_mask) y)
Dec 8
INSTRUCTIONS=: ([:<;._2,&' ');._2 LF,~1!:1<'/home/lambertdw/src/j/adventofcode/2017/36b8.dat'vars=: [: ~. [: , 0 _3&{"1 initialize=: (<0) ,.~ vars
VARS=: initialize INSTRUCTIONS
INSTRUCTIONS=: (=&(<,'>' ))`(,:&(<'gtdwl '))}"1 INSTRUCTIONS INSTRUCTIONS=: (=&(<,'<' ))`(,:&(<'ltdwl '))}"1 INSTRUCTIONS INSTRUCTIONS=: (=&(<,'<='))`(,:&(<'ledwl '))}"1 INSTRUCTIONS INSTRUCTIONS=: (=&(<,'>='))`(,:&(<'gedwl '))}"1 INSTRUCTIONS INSTRUCTIONS=: (=&(<,'=='))`(,:&(<'eqdwl '))}"1 INSTRUCTIONS INSTRUCTIONS=: (=&(<,'!='))`(,:&(<'nedwl '))}"1 INSTRUCTIONS INSTRUCTIONS=: 3 (<' * ')"_`[`]}"1 INSTRUCTIONS INSTRUCTIONS=: 1 (' ',,&' ')&.>@:{`[`]}"1 INSTRUCTIONS INSTRUCTIONS=: 0 _3 ('''',,&'''')&.>@:{`[`]}"1 INSTRUCTIONSindex=: ({."1@:[ (i. <@:,) ])~ NB. NAME index VARS
inc=: 4 : 0
i=. x index VARS VARS=: i ({.,y&+&.>@:{:)@:{`[`]} VARS) dec=: inc - eqdwl=:4 :0
i=. x index VARS y=>{:i{VARS) nedwl=:-.@:eqdwl ltdwl=:4 :0
i=. x index VARS y>>{:i{VARS) ledwl=:ltdwl+.eqdwl gtdwl=:-.@:ledwl gedwl=:-.@:ltdwl
R=:".@;"1]INSTRUCTIONS
|:(/:{:"1){:R
NB. part 2 >./;,{:"1 R
Dec 9
A=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36b9.dat'remove_garbage=: 3 :0
garbage =. result=. '' state=. 0 for_c. y do. if. (0 = state) do. if. c = '<' do. state =. 1 else. result =. result , c end. elseif. 1 = state do. if. '!' = c do. state =. 2 elseif. '>' = c do. state =. 0 end. elseif. state = 2 do. state =. 1 end. end. result)
part1=: 3 :0
s=. n=. 0 for_c. y do. n=. n + (c = '{') - (c = '}') s =. s + n * (c = '{') end. s)
TESTS2=: ('{}'; 1);('{{{}}}'; 6);('{{},{}}'; 5);('{{{},{},{{}}}}'; 16);('{<a>,<a>,<a>,<a>}'; 1);('{{<ab>},{<ab>},{<ab>},{<ab>}}'; 9);('{{<!!>},{<!!>},{<!!>},{<!!>}}'; 9);<('{{<a!>},{<a!>},{<a!>},{<ab>}}'; 3)
testpart1=: 3 :0
'a b'=. y assert. b = part1 remove_garbage a) testpart1&>TESTS2
part2=: count_garbage
count_garbage=: 3 :0
garbage =. result=. '' state=. 0 for_c. y do. if. (0 = state) do. if. c = '<' do. state =. 1 else. result =. result , c end. elseif. 1 = state do. if. '!' = c do. state =. 2 elseif. '>' = c do. state =. 0 elseif. 1 do. garbage=. garbage , c end. elseif. state = 2 do. state =. 1 end. end. result;garbage)
NB. testing part 2, data and adverb
he icaTEST_PART2=: ". LF -.~ 0 :0 ('<>'; 0);('<random characters>'; 17); ('<<<<>'; 3);('<{!>}>'; 2);('<!!>'; 0)
- ('<!!!>>'; 0);<('<{o"i!a,<{i<a>'; 10)
)
Testpart2=: 1 :0
'a b'=. y assert. b = {:#&> u a
)
NB. example for verb part2
part2 Testpart2&> TEST_PART2
Note 'anticipate no assertion errors'
┌───────────────────┬──┐
│<> │0 │
├───────────────────┼──┤
│<random characters>│17│
├───────────────────┼──┤
│<<<<> │3 │
├───────────────────┼──┤
│<{!>}> │2 │
├───────────────────┼──┤
│<!!> │0 │
├───────────────────┼──┤
│<!!!>> │0 │
├───────────────────┼──┤
│<{o"i!a,<{i<a> │10│
└───────────────────┴──┘
)
Dec 10
Note 'test'Suppose we instead only had a circular list containing five elements 0, 1, 2, 3, 4 and were given input lengths of 3, 4, 1, 5 Result 3 4 2 1 [0] product is 12)
TEST=: 3, 4, 1, 5 ; 5 INPUT=: 14,58,0,116,179,16,1,104,2,254,167,86,255,55,122,244parta=: $:&256 : (4 :0) NB. LENGTHS parta N
list=. i.y skip=. 0 for_length. x do. list=. (length + skip) |. length (|.@:{.)`(i.@:[)`]} list skip=. >: skip echo length ; skip ; list end. i=.+/(,i.@:#)x list ; i ; ((#list) | -i) ; */ (0 1 + ((#list) | -i)){,~list)
P2IN=:'14,58,0,116,179,16,1,104,2,254,167,86,255,55,122,244' xor=: 22 b. hex=: (Num_j_,26}.Alpha_j_) {~ 16 16&#: part2=: $:&256 : (4 :0)lengths=. 17 31 73 47 23,~a.i.xlist=. i.y skip=. 0 for_i. i.64 do. for_length. lengths do. list=. (length + skip) |. length (|.@:{.)`(i.@:[)`]} list skip=. >: skip NB. echo length ; skip ; list end. end.i=.+/(,i.@:#),64&#&.<lengths list=. ((#list) | -i)|. list hex _16 xor/\ list)
Dec 11
TESTA=:<@:".;._2]0 :0'ne,ne,ne' ; 3;'steps away' 'ne,ne,sw,sw' ; 0;'back where you started' 'ne,ne,s,s' ; 2;'se,se' 'se,sw,se,sw,sw' ; 3;'s,s,sw' )
parta=: 3 :0
path=. ([: <;._2 ,&',')y path=. (path i.~;:'ne n nw sw s se'){1ad30 1ad90 1ad150 1ad210 1ad270 1ad330 +/ path)
P=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bb.dat'
DIRS=:;:a=:'ne n nw sw s se' ('a'~)=. 1ad30 1ad90 1ad150 1ad210 1ad270 1ad330
count_steps_old=: 3 :0
position=. +/".y h=. ne,n,nw,sw,s,se path=. 0j0 p=. 0$<'' while. 0.2<|position-{:path do. i=. (=<./)|position-,h+/{:path path=.path,({:path)+h#~i p=. p,<i#DIRS end. (;~#)p)
count_steps=: 3 :0position=. +/(". ::])y h=. ne,n,nw,sw,s,se path=. 0j0 p=. 0$<'' while. 0.2<|position-{:path do. i=. (=<./)|position-,h+/{:path path=.path,({:path)+h#~i p=. p,<i#DIRS end. (;~#)p)
>./0{::&>RESULT=:count_steps +/\".P NB. where P is...s,s,sw,se,s,nw,nw...
Dec 12
While=:2 :'u^:(0-.@:-:v)^:_'
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bc.dat' 406655572016 A=:<@:".;._2 LF,~'<->'-.~INPUT
L=: ,0
145 84
parts=: 3 :0a=. y while. #a do. b=. a ([: ~. [: ; (#~({.&>a)&e.@:]))^:_ ,{.>{.a a=. (({.&>a)-.@:e.b)#a echo #a end.)
parts=: 3 :0result=. i.0 a=. y while. #a do. b=. a ([: ~. [: ; (#~({.&>a)&e.@:]))^:_ ,{.>{.a a=. (({.&>a)-.@:e.b)#a result=. result,([echo)#b end.)
Dec 13
While=:2 :'u^:(0-.@:-:v)^:_'
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bd.dat' 406655572016 A=:".;._2 LF,~':'-.~INPUTNB. depth range position direction
FW=: 1,~0,~|:A
advance_fw=: 3 :0
y=. ((+2&{)`2:`]}~ {:)y 0 (({: * _1 ^ ((0 =_2&{) +. _2&{ = _1 + 1&{))@:])`_1:`]} y)
parta=: 3 :0
fw=. y p=. _1 q=. i.0 last_wall=. (<0 _1){y while. p < last_wall do. p=. >:p if. p e. {. fw do. q=. q , 0 = (<2,(({. fw) i. p)){fw end. fw=. advance_fw fw end. q)
mp=: +/ .*~~ mp/|:(parta FW)#|:2 _{.FW
smack=: 3 :0
fw=. y p=. _1 last_wall=. (<0 _1){y while. p < last_wall do. p=. >:p if. p e. {. fw do. if. 0 = (<2,(({. fw) i. p)){fw do. p return. end. end. fw=. advance_fw fw end. >:p)
partb=: 3 :0
fw=. y last_wall=. (<0 _1){y answer=: 0 whilst. last_wall >: smack fw do. fw=. advance_fw fw answer=. >: answer end. )
partb=: 3 :0fw=. y last_wall=. (<0 _1){y answer=: 0 whilst. last_wall >: whap do. fw=. advance_fw^:2 fw answer=. 2 + answer whap=. smack fw NB. smoutput answer,whap end. answer)
MISERY=:([:|:(1,:~i.@:<:)(,"1)_1,:~}:@:i.@:-)&.>i.21
repeat_length=: _2 2 p.1&{depth=: 0&{ range=: 1&{
(repeat_length | DELAY + depth) {:: MISERY {~ range
Dec 14
KEY=: 'jxqlasbh'KEYS=: KEYSTRINGS=:(KEY,'-')&,L:_1 <@":"0 i.128
,/@knothashbinary=:(4#2)#:(Num_j_,26}.Alpha_j_)&i.&> ,/@:binary'55eab3c4fbfede16dcec2c66dda26464' a=:[:,/[:binary[:,/knothash
+/,a&>KEYSTRINGS
GRAPH=:a&>KEYSTRINGS
b=:3 :0 NB. b GRAPHGY=:_,~_,_,.~_,.y{_ 0 groups=: 0 for_i.i.#y do. for_j.i.{:$y do. indx=. <&:>:i,j if.0=indx{GY do.star indx[groups=:>:groups end. end. end. groups)
star=: 3 :0
'i j'=. >y GY=: groups [`(y"_)`]}GY for_d._1 1 do. indx=. <(i+d),j if.0=indx{GY do.star indx end. indx=. <i,(j+d) if.0=indx{GY do.star indx end. end. groups)
Dec 15
Filter=: (#~`)(`:6)g=: 2147483647 | 16807 48271&*
band=: 2b10001 b. K=:1 :'m*1000'
TEST=: 65 8921 INPUT=: 883 879 MASK=: #.16#1 +/=/"1 MASK band }. g^:(<>:40 K K)TEST
partb=: 3 :0
batch=.<>:10 K K while.1 do. r=. }. g^:batch y y=. {: r 'a b'=. |:r 1!:3&(<'/tmp/A'),LF,.~":,.(0=4&|)Filter a 1!:3&(<'/tmp/B'),LF,.~":,.(0=8&|)Filter b end.)
verb externally stopped follow with file post processing
Dec 16
Note'instructions' Spin, written sX, makes X programs move from the end to the front, but maintain their order otherwise. (For example, s3 on abcde produces cdeab). Exchange, written xA/B, makes the programs at positions A and B swap places. Partner, written pA/B, makes the programs named A and B swap places. ) s=: (|.~-)~ x=: ({)`(|.@:[)`]} p=: (i.~{])`(|.@:i.~)`]} 'eb'p 3 4 x 1 s 5{. 16{._26{.Alpha_j_ NB. test INPUT=:[;._2',',~(=&'/')`(,:&' ')}1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bg.dat' S=:".@:}. X=:".@:}. P=:1 3&{ parta=:((s~S)~)`((x~X)~)`((p~P)~)@.('sxp' i. {.@:[) parta/(|.INPUT),15{._26{.Alpha_j_ partb=: 4 :0 I=:(_,#y){.|.INPUT NB. I=:(_,#y){.|.'s1','x3 4',:'pe b' f=.((|.~ -) ".@:}.)~`(({`(|.@:[)`]}~ ".@:}.)~)`(((i.~ { ])`(|.@:i.~)`]}~ 1 3&{)~)@.('sxp' i. {.@:[) result=:0 16$' ' while.x do. x=.<:x y=.f/I,y result=:result,y end. ) partb=: 1&$: : (4 :0) I=:(_,#y){.|.INPUT NB. I=:(_,#y){.|.'s1','x3 4',:'pe b' f=.((|.~ -) ".@:}.)~`(({`(|.@:[)`]}~ ".@:}.)~)`(((i.~ { ])`(|.@:i.~)`]}~ 1 3&{)~)@.('sxp' i. {.@:[) result=:0 16$' ' while.x do. x=.<:x y=.f/I,y result=:result,y end. )
Dec 17
Note 'example'(0) 0 (1) 0 (2) 1 0 2 (3) 1 0 2 (4) 3 1 0 (5) 2 4 3 1 0 5 2 4 3 (6) 1 0 5 (7) 2 4 3 6 1 0 5 7 2 4 3 (8) 6 1 0 (9) 5 7 2 4 3 8 6 1
TEST=: 3
parta=: 2017&$: :(4 :0)
L=:,i.0 j=. >:y for_i.i.>:x do. L=: i , j |. L end. L)
INPUT=: 356
parta=: 2017&$: :(4 :0)
L=:,i.0 j=. >:y for_i.i.>:x do. echo 0 i.~ L=: i , j |. L end. L)
Dec 18
coclass'i'INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bi.dat'
TEST=:}:0 :0 set a 1 add a 2 mul a a mod a 5 snd a set a 0 rcv a jgz a -1 set a 1 jgz a -2 )
assemble=: [: <;._2 [: ,&LF [: toupper (=&'-')`(,:&'_')}
split=: [: <;._2 ,&' '
value=: [: ":@:".^:(Num_j_ -.@:e.~ {.) argument
argument=: >@:{ split register=: argument
NB.snd X plays a sound with a frequency equal to the value of X. SND=: 'SOUND=: SOUND , ' , _1&value
NB. set X Y sets register X to the value of Y. SET=: 0®ister , '=: ' , _1&value
NB. add X Y increases register X by the value of Y. ADD=: 0®ister , '=: ' , 0®ister , ' + ' , _1&value
NB. mul X Y sets register X to the result of multiplying the value contained in register X by the value of Y. MUL=: 0®ister , '=: ' , 0®ister , ' * ' , _1&value
NB. mod X Y sets register X to the remainder of dividing the value contained in register X by the value of Y (that is, it sets X to the result of X modulo Y). MOD=: 0®ister , '=: ' , _1&value , ' | ' , 0®ister
NB. rcv X recovers the frequency of the last sound played, but only when the value of X is not zero. (If it is zero, the command does nothing.) RCV=: '([: echo@:{: SOUND"_)^:(0&~:)' , _1&value
NB. jgz X Y jumps with an offset of the value of Y, but only if the value of X is greater than zero. (An offset of 2 skips the next instruction, an offset of -1 jumps to the previous instr JGZ=: 'IP =: IP + (_1 + ' , _1&value , ') * 0 < ' , _2&value
quote=: ''''&([ , ,~)
run=: 3 : 0
".((,~,&(,26{.Alpha_j_,.' '))''''),'=: 0' NB. reset the registers SOUND=: ,i.0 program=. assemble y IP=: 0 steps=. 0 while. (steps < 100) *. (0 <: IP) *. (IP < #program) do. (0&{:: ".^:2@:([echo)@:(, quote) ;:inv@:}.);:IP{::program IP=: >: IP NB.steps=. >:steps end.)
Dec 19
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bj.dat'TEST=:}:0 :0
| | +--+ A | C F---|----E|--+ | | | D +B-+ +--+)
'S E N W '=: DIRS=: 0j1^i.4
Advance=: 2 :0
d=. m p=. n a=. y if.'+'=(<+.p){a do. for_nude.DIRS-.(,-)d do. if.' '~:(<+.p+nude){a do. d=. nude end. end. end. d,d+p)
parta=: 3 :0
map=. [;._2 y,LF map=. ' ',.(map,' '),.' ' id=. ,'' direction=. S location=. 0 j.'|'i.~{.map while. 1 do. 'direction location'=. direction Advance location map indicator=. map {~ < +.location NB.echo indicator=' ' NB.echo (<+.location)('o'"_)`[`]}map NB. not such a good idea for the full size map if. indicator = ' ' do. break. end. id =. id , 0&#^:(e.&'|-+') indicator end. id)
partb=: 3 :0map=. [;._2 y,LF map=. ' ',.(map,' '),.' ' id=. ,'' direction=. S location=. 0 j.'|'i.~{.map steps=. 0 while. 1 do. 'direction location'=. direction Advance location map indicator=. map {~ < +.location NB.echo indicator=' ' NB.echo (<+.location)('o'"_)`[`]}map NB. not such a good idea for the full size map if. indicator = ' ' do. break. end. id =. id , 0&#^:(e.&'|-+') indicator steps=. >:steps end. id;steps)
Dec 20
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bk.dat'PVA=:x:(3 3$_&".);._2 LF,~(-.@:e.&(Num_j_,'-',LF))`(,:&' ')}INPUT
mp=:+/ .*~~
add=: (+/@:{)`({:@:[)`]}"2
parta=:3 :0
y=. 2 1 add y y=. 1 0 add y) length=: mp@:{."2 NB. *:length actually.
(i.<./)length a10000=:parta^:10000 PVA NB. parta
uncollided=: 3 :0mask=. 1 = +/"1 = {."2 y nub=. ~: {."2 y mask # nub # y)
partb=:3 :0
y=. uncollided y y=. 2 1 add y y=. 1 0 add y)
- b10000=: partb^:10000 PVA
Dec 21
INPUT=: 1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bl.dat'transpose=:|: rotate=:|:@:|.
index=: $@:] #: (i.~ ,) column_of_1=: [: {: 1&indexfamilars=:((rotate^:(<4))@:transpose,(rotate^:(<4)))
restructure=: [:[;._2,&'/'
TRANSFORMATIONS=: (({.~ ;&restructure (}.~ 4&+))i.&' ');._2,&LF INPUT
START=: <3 3$'.#...####'
find=: [: column_of_1 ({."1 TRANSFORMATIONS) =/~ ([: <"2 familars@>)
odd=: 1&(2b10001 b.) even=: -.@:odd Filter=:(#~`)(`:6)
parta=: START&$: :(4 :0) NB. BOXED_INITIAL_PATTERN parta INPUT_RULES
TRANSFORMATIONS=: (({.~ ;&restructure (}.~ 4&+))i.&' ');._2,&LF y remove_us=. ~.,":3 3$<3 3$' ' for_i.i.5 do. left_argument=. 2 2 $ 2 + odd #&> x x=. < ([:,' '&(-.@:e."1)) Filter remove_us-."1~}.}:":(,/"2)0 0 1}.TRANSFORMATIONS{~left_argument find@:<;.3>x end. )
partb=: START&$: :(4 :0) NB. BOXED_INITIAL_PATTERN parta INPUT_RULESTRANSFORMATIONS=: (({.~ ;&restructure (}.~ 4&+))i.&' ');._2,&LF y remove_us=. ~.,":3 3$<3 3$' ' for_i.i.18 do. echo i; $x left_argument=. 2 2 $ 2 + odd #&> x x=. < ([:,' '&(-.@:e."1)) Filter remove_us-."1~}.}:":(,/"2)0 0 1}.TRANSFORMATIONS{~left_argument find@:<;.3>x end.)
Dec 22
TEST=: }:0 :0..#
- ..
... )
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bm.dat'
index=: $@:] #: (i.~ ,)
DIRS=:'SENW' (1j1#'DIRS'~)=: 0j1^i.4
draw=: (1j1 #"1 {&'.#')@:odd
odd=: 1&(2b10001 b.)
parta=:4 :0 NB. TURNS parta INPUT
grid=. '#'=([: [;._2 ,&LF)y NB. y is the INPUT position=. j./<.-:$grid grid=. (<+.position) (2+{)`[`]}grid velocity=. N grid=. (,~(#grid)++:x){.grid grid=. (-x)|.(-x)|."1 grid position=. j./1 index 1 < grid grid=. (<+.position) (_2+{)`[`]}grid for_i.i.x do. NB. echo position;velocity node=. odd(<+.position){grid velocity=. velocity * node{E,W grid=. (<+.position) (>:@:{)`[`]} grid position=. position + velocity end. echo position;velocity grid)
d=: ([: ,. 1&{:: ;~ [: draw 0&{::)@:, even=: -.@:oddparta=:4 :0 NB. TURNS parta INPUT
grid=. '#'=([: [;._2 ,&LF)y NB. y is the INPUT position=. j./<.-:$grid grid=. (<+.position) (2+{)`[`]}grid velocity=. N grid=. (,~(#grid)++:x){.grid grid=. (-x)|.(-x)|."1 grid position=. j./1 index 1 < grid grid=. (<+.position) (_2+{)`[`]}grid infections=. 0 for_i.i.x do. NB. echo position;velocity node=. (<+.position){grid infections=.infections+even node velocity=. velocity * (odd node){E,W grid=. (<+.position) (>:@:{)`[`]} grid position=. position + velocity end. echo position;velocity ,.grid;infections)
parta=:4 :0 NB. TURNS parta INPUT
grid=. '#'=([: [;._2 ,&LF)y NB. y is the INPUT position=. j./<.-:$grid grid=. (<+.position) (2+{)`[`]}grid velocity=. N n=. <.-:(#grid)++:2000<.x grid=. (,~+:n){.grid grid=. (-x)|.(-x)|."1 grid position=. j./1 index 1 < grid grid=. (<+.position) (_2+{)`[`]}grid infections=. 0 for_i.i.x do. NB. echo position;velocity node=. (<+.position){grid infections=.infections+even node velocity=. velocity * (odd node){E,W grid=. (<+.position) (>:@:{)`[`]} grid position=. position + velocity end. echo position;velocity ,.grid;infections)
NB. 1$.sh;a;e produces a sparse array. sh specifies the shape. a specifies the sparse axes; negative indexing may be used. e specifies the “zero” element, and its type determines the type of the array. The argument may also be sh;a (e is assumed to be a floating point 0) or just sh (a is assumed to be i.#sh — all axes are sparse — and e a floating point 0).
draw=: (1j1 #"1 {&'.W#F')@:(4&|)partb=:4 :0 NB. TURNS parta INPUT
grid=. +:'#'=([: [;._2 ,&LF)y NB. y is the INPUT position=. j./<.-:$grid a=. 9 grid=. (<+.position) (a+{)`[`]}grid velocity=. N n=. <.-:(#grid)++:2000<.x grid=. (,~+:n){.grid grid=. (-x)|.(-x)|."1 grid position=. j./1 index (<:a) < grid grid=. (<+.position) ((-a)+{)`[`]}grid infections=. 0 for_i.i.x do. NB. echo position;velocity node=. (<+.position){grid state=. 4|node infections=.infections+1=state velocity=. velocity * (4|node){E,S,W,N grid=. (<+.position) (>:@:{)`[`]} grid position=. position + velocity end. echo position;velocity ,.grid;infections) Note 'states'
0 Clean nodes become weakened. 1 Weakened nodes become infected. 2 Infected nodes become flagged. 3 Flagged nodes become clean.) Note 'rules'
Decide which way to turn based on the current node: If it is clean, it turns left. multiply by E If it is weakened, it does not turn, and will continue moving in the same direction. multiply by S If it is infected, it turns right. multiply by W If it is flagged, it reverses direction, and will go back the way it came. multiply by N Modify the state of the current node, as described above. The virus carrier moves forward one node in the direction it is facing.)
Dec 23
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bn.dat'
Note'instruction set'set X Y sets register X to the value of Y.sub X Y decreases register X by the value of Y.mul X Y sets register X to the result of multiplying the value contained in register X by the value of Y.jnz X Y jumps with an offset of the value of Y, but only if the value of X is not zero. (An offset of 2 skips the next instruction, an offset of -1 jumps to the previous instruction, and so on.))
assemble=: [: <;._2 [: ,&LF [: toupper (=&'-')`(,:&'_')}
split=: [: <;._2 ,&' '
value=: [: ":@:".^:(Num_j_ -.@:e.~ {.) argument
argument=: >@:{ split register=: argument
SET=: 0®ister , '=: ' , _1&value MUL=: 'multiplications=:>:multiplications[' , 0®ister , '=: ' , 0®ister , ' * ' , _1&value SUB=: 0®ister , '=: ' , 0®ister , ' - ' , _1&value JNZ=: 'IP =: IP + (_1 + ' , _1&value , ') * 0 ~: ' , _2&value
quote=: ''''&([ , ,~)
run=: 3 : 0
".((,~,&(,26{.Alpha_j_,.' '))''''),'=: 0' NB. reset the registers multiplications=: 0 program=. assemble y IP=: 0 steps=. 0 while. (steps < 100) *. (0 <: IP) *. (IP < #program) do. (0&{:: ".^:2@:([echo)@:(, quote) ;:inv@:}.);:IP{::program IP=: >: IP NB.steps=. >:steps end.)
runb=: 3 : 0message=. ' STEP IP A B C D E F G H instruction' ".((,~,&(,26{.Alpha_j_,.' '))''''),'=: 0' NB. reset the registers multiplications=: 0 program=. assemble y IP=: 0 A=: 1 steps=. 0 echo message echo (9j0":steps,IP,A,B,C,D,E,F,G,H),' ',IP{::program while. (steps < 1000) *. (0 <: IP) *. (IP < #program) do. (0&{:: ".^:2@:(, quote) ;:inv@:}.);:IP{::program IP=: >: IP steps=. >: steps if. (steps < 100)+.0 = 100000|steps do. echo (9j0":steps,IP,A,B,C,D,E,F,G,H),' ',IP{::program else. break. end. end. echo message)
Dec 24
TEST=: }: 0 :00/2 2/2 2/3 3/4 3/5 0/1 10/1 9/10 )
index=: $@:] #: (i.~ ,)
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bo.dat'
in=: _2 ]\ [: ". (e.&('/',LF))`(,:&' ')}
parta=: 3 :0
dominoes=. in y paths=. ,:(,:0 0);dominoes finished=. paths while.paths do. 'p d'=. pd=. {. paths if. 0=#p do. break. end. paths=. }. paths no=. 1 for_i. <. -: I. (,d) e. match=.(<_1 _1) { p do. no=. 0 domino=. i { d ds=. (i{.d),(>:i)}.d np=. p,({:domino=match)|.domino paths=. paths , np ; ds end. if. no do. finished=. finished , pd end. end. finished)
>./+/@:,"2>{.|: parta INPUT
mp=:+/ .*~~parta=: 3 :0
dominoes=. in y mask=. =/"1 dominoes inisout=. {."1 mask # dominoes dominoes=. dominoes#~-.mask paths=. ,:(,:0 0);dominoes best=. 0 finished=. 0 while.paths do. no=. 0 'p d'=. pd=. {: paths if. 0=#p do. break. end. paths=. }: paths no=. 1 for_i. <. -: I. (,d) e. match=.(<_1 _1) { p do. no=. 0 domino=. i { d ds=. (i{.d),(>:i)}.d np=. p,({:domino=match)|.domino paths=. paths , np ; ds end. if. no do. strength=. (+/ + [: +: inisout mp inisout&e.),p if. strength > best do. best=. strength echo finished=.(<best),pd end. end. end. finished)
partb=: 3 :0
dominoes=. in y mask=. =/"1 dominoes inisout=. {."1 mask # dominoes dominoes=. dominoes#~-.mask paths=. ,:(,:0 0);dominoes bl=.bs=. 0 finished=. 0 while.paths do. no=. 0 'p d'=. pd=. {: paths if. 0=#p do. break. end. paths=. }: paths no=. 1 for_i. <. -: I. (,d) e. match=.(<_1 _1) { p do. no=. 0 domino=. i { d ds=. (i{.d),(>:i)}.d np=. p,({:domino=match)|.domino paths=. paths , np ; ds end. if. no do. blort=. inisout&e.,p strength=. (+/ + [: +: inisout mp blort"_),p length=. (+/ blort) + # p if. ((bl = length) *. (bs < strength)) +. (bl < length) do. bl=. length bs=. strength echo finished=.(<bl,bs),pd end. end. end. finished)
Dec 25
TEST=: 0 :0Begin in state A. Perform a diagnostic checksum after 6 steps.
In state A:
If the current value is 0: - Write the value 1. - Move one slot to the right. - Continue with state B. If the current value is 1: - Write the value 0. - Move one slot to the left. - Continue with state B.In state B:
If the current value is 0: - Write the value 1. - Move one slot to the left. - Continue with state A. If the current value is 1: - Write the value 1. - Move one slot to the right. - Continue with state A.)
LF=:_1{TEST TEST=:}:TEST
INPUT=:1!:1<'/home/lambertdw/src/j/adventofcode/2017/36bp.dat'
i=:[: <;._2 ,&LF
parse_state=: 3 :0
name=. (1;_2){::y write=. (3;_2){::y advance=. _1^'f'=(4;_3){::y next_state=. (5;_2){::y rule=. name;write;advance;next_state write=. (7;_2){::y advance=. _1^'f'=(8;_3){::y next_state=. (9;_2){::y rule=. rule,write;advance;next_state)
prepare=: 3 :0
I=:i y STATE=: (0;_2){::I MEMORY=: '0' N=: 0"._2{::;:1{::I PROGRAM=: _10 parse_state\2}.I POSITION=: 0)
show=:4 :0
NB. 1!:3&(<'/dev/stderr')LF,~1{":y;(20{.POSITION ('+-'{~'0'={)`[`]}MEMORY);}.":<x echo y;(20{.POSITION ('+-'{~'0'={)`[`]}MEMORY);x)
turing=: 3 :0
prepare y states=.0{::"1 PROGRAM n=. 16 for_i.i.N do. rule=. PROGRAM{~states i.STATE value=. POSITION{MEMORY MEMORY=: value (rule >@:{~ 1 3 p.'1' = [)`(POSITION"_)`]}MEMORY POSITION=: POSITION + value (rule >@:{~ 2 3 p.'1' = [) MEMORY STATE=: value (rule >@:{~ 3 3 p. '1' = [) MEMORY if. POSITION >: # MEMORY do. MEMORY=: MEMORY , n#'0' elseif. POSITION < 0 do. MEMORY=: (n#'0') , MEMORY POSITION=: n + POSITION end. if.0=1|i do.rule show >:i end. end. MEMORY)
parta=: turing