Last active
December 10, 2017 08:12
-
-
Save SeanConnelly/065cb51fc6572c6bf3dac4a9973fb54f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class AOC.Y2017 Extends %RegisteredObject | |
{ | |
/* | |
ADVENT OF CODE 2017 | |
Built With... | |
_ | |
_ \ \ _____ _ _____ _ _____ _ __ | |
| | | | |_ _| | | / ___| | | / __ \ | | \_\ | |
| | | | | | _ __ | |_ ___ _ __\ `--. _ _ ___| |_ ___ _ __ ___ ___ | / \/ __ _ ___| |__ ___ | |
| | | | | || '_ \| __/ _ \ '__|`--. \ | | / __| __/ _ \ '_ ` _ \/ __| | | / _` |/ __| '_ \ / _ \ | |
| | |_| _| || | | | || __/ | /\__/ / |_| \__ \ || __/ | | | | \__ \ | \__/\ (_| | (__| | | | __/ | |
\_\ \___/_| |_|\__\___|_| \____/ \__, |___/\__\___|_| |_| |_|___/ \____/\__,_|\___|_| |_|\___| | |
__/ | | |
|___/ | |
== , == | |
<^\()/^> _/^\_ <^\()/^> | |
\/ \/ < > \/ \/ | |
* /__\ /.-.\ * /__\ | |
== /\ * `/&\` /\ * == | |
<^\()/^> !_\/ ,@.*;@, \/_! <^\()/^> | |
\/ \/ !_/I_|| /_o.I% _\ * ||_I\_! \/ \/ | |
/__\ /I_/|*|| (`'--:o(_@; || |\_I\ /__\ | |
/_ \ !//| | || /`;--.,__ `') || | |\\! /_ \ | |
(- ) /I/ | | || ;@`o% O,*`'`&\ || | | \I\ (= ) | |
\__/!//| | | ||* (`'--)_@ ;o %'()\ ||*| | |\\!\__/ | |
/ \I/ | | | || /`;--._`''--._O'@; || | | | \I/ \ | |
{_ __} | | | || /&*,()~o`;-.,_ `""`) || | | | {____} | |
_!__|= || | *| | || /`,@ ;+& () o*`;-';\ || | | | || |__!_ | |
_I__| ||__|__|__|_|| (`""--.,_0 +% @' &()\ ||_|__|__|__||- |__I_ | |
-|--|- ||--|--|--|-|| /-.,_ ``''--....-'`) *||-|--|--|--||= |--|- | |
| | || | | |*|| /@% ;o:;'--,.__ __.'\ || | | | || | | | |
| |= || | | | || ;*,&(); @ % &^;~`"`o;@(); || | | | *||= | | | |
| |- || | | | || /(); o^~; & ().o@*&`;&O.\ || | | | ||= | | | |
| |- || | | | || `"="==""==,,,.,="=="==="` || | | | ||- | | | |
-|--|= ||--|--|--|-||__.- .(\-''#####---...___..||-|--|--|--||- |--|- | |
~~~~~~~~~^^^^^^^^^^ ^ \)_`"""""` ^^^^^^^^^^^^^^^jgs~~~ | |
.--' ') | |
o( )_-\ | |
`"""` ` | |
*/ | |
Parameter FOLDER = "C:\Temp\aoc2017\"; | |
ClassMethod FileUtil(name, ByRef file = "", Output line) | |
{ | |
if file="" { | |
set file=##class(%File).%New(..#FOLDER_name) | |
do file.Open("R") | |
} | |
set line=file.ReadLine() | |
quit $s(line="":0,1:1) | |
} | |
/* DAY 1 | |
/ __'. .-"""-. | |
.-""-| | '.'. / .---. \ | |
/ .--. \ \___\ \/ /____| | | |
/ / \ `-.-;-(`_)_____.-'._ | |
; ; `.-" "-:_,(o:==..`-. '. .-"-, | |
| | / \ / `\ `. \ / .-. \ | |
\ \ | Y __...\ \ \ / / \/ | |
/\ | | | .--""--.| .-' \ '.`---' / | |
\ \ / / |` \' _...--.; '---'` | |
\ '-' / jgs /_..---.._ \ .'\\_ `. | |
`--'` .' (_) `'/ (_) / | |
`._ _.'| .' | |
``````` '-...--'` | |
*/ | |
ClassMethod Day1PartA() | |
{ | |
set input="892195969991735837915273868729548694237967495115412399373194562526947585337233793568278265279199883197167634791293177986152566236718332617536487236879747167999983363832257912445756887314879229925864477761357139855548522513798899853896612387146687716264599943289416326727256525173953861534244979466587895429399159924916364476319573895566795393368411672387263615582128377676293612892723762237191146714286233543514411813323197995953854871628225358543514157867372265718724276911699514971458844849349726276329135118243155698271218844347387457343656446381799296893222256198484465873714311777937421161581798189554141474236239447612421883232173914183732126332838194648583472419154369952477422666389517569944428464617457124369349242479612422673241361777576466946622932243728551273284837934497511114334421486262244982914734452113946361245377351849815584855691778894798219822463298387771923329337634394654439458564233259451453345316753241438267739439225497515276522424441532462541528195782818326918562247278496495764435386667383577543385186827269732261223156824351164841648424564925198783625721396988984481558391866483955533972212164693898955412719161648411279149413443192896864258215498543827458438871355879336892721675937111952479183496982825163456282747678364612135596373533447719867384667516572262124225585623974278833981365494628646614588114147473559138853453189448624976774641922469183942857695986376428944876851497914443873513862319484181787593572987444669767939526294424531262999564948571142342741129862311311313166798363442745792896227642881893134498151552326647933689596516859342242244584714818773791567187322217164347852843751875979415198165627534263527828414549217234322361937785185174993256753483876378332521824515977173397535784236923629636713469151526399149548322849831431526219478653861754364155275865511643923249858589466142474763778413826829226663398467569555747267195129525138917561785436449855933951538973995881954521124753369223898312843734771532342383282987422334196585128526526324291777689689492346231786335851551413876834969878" | |
set total=0 | |
for i=1:1:$l(input) { | |
set l=$e(input,i) | |
set m=$e(input,$s(i=$l(input):1,1:i+1)) | |
if l=m set total=total+l | |
} | |
write !,"Total : ",total | |
} | |
ClassMethod Day1PartB() | |
{ | |
set input="892195969991735837915273868729548694237967495115412399373194562526947585337233793568278265279199883197167634791293177986152566236718332617536487236879747167999983363832257912445756887314879229925864477761357139855548522513798899853896612387146687716264599943289416326727256525173953861534244979466587895429399159924916364476319573895566795393368411672387263615582128377676293612892723762237191146714286233543514411813323197995953854871628225358543514157867372265718724276911699514971458844849349726276329135118243155698271218844347387457343656446381799296893222256198484465873714311777937421161581798189554141474236239447612421883232173914183732126332838194648583472419154369952477422666389517569944428464617457124369349242479612422673241361777576466946622932243728551273284837934497511114334421486262244982914734452113946361245377351849815584855691778894798219822463298387771923329337634394654439458564233259451453345316753241438267739439225497515276522424441532462541528195782818326918562247278496495764435386667383577543385186827269732261223156824351164841648424564925198783625721396988984481558391866483955533972212164693898955412719161648411279149413443192896864258215498543827458438871355879336892721675937111952479183496982825163456282747678364612135596373533447719867384667516572262124225585623974278833981365494628646614588114147473559138853453189448624976774641922469183942857695986376428944876851497914443873513862319484181787593572987444669767939526294424531262999564948571142342741129862311311313166798363442745792896227642881893134498151552326647933689596516859342242244584714818773791567187322217164347852843751875979415198165627534263527828414549217234322361937785185174993256753483876378332521824515977173397535784236923629636713469151526399149548322849831431526219478653861754364155275865511643923249858589466142474763778413826829226663398467569555747267195129525138917561785436449855933951538973995881954521124753369223898312843734771532342383282987422334196585128526526324291777689689492346231786335851551413876834969878" | |
set total=0 | |
set len=$l(input) | |
for i=1:1:$l(input) { | |
set j=i+(len/2) | |
if j>len set j=j-len | |
set l=$e(input,i) | |
set m=$e(input,j) | |
if l=m set total=total+l | |
} | |
write !,"Total : ",total | |
} | |
/* DAY 2 | |
.------, | |
.\/. |______| | |
_\_}{_/_ _|_Ll___|_ | |
/ }{ \ [__________] .\/. | |
'/\' / \ _\_\/_/_ | |
() o o () / /\ \ | |
\ ~~~ . / '/\' | |
_\/ \ '...' / \/_ | |
\\ {`------'} // | |
\\ /`---/',`\\ // | |
\/' o | |\ \`// | |
/' | | \/ /\ | |
__,. -- ~~ ~| o `\| |~ ~~ -- . __ | |
| | | |
jgs \ o / | |
`._ _.' | |
^~- . - ~^ | |
*/ | |
ClassMethod Day2Part1() | |
{ | |
set total=0 | |
set file=##class(%File).%New(..#FOLDER_"day1b.txt") | |
do file.Open("R") | |
set line=file.ReadLine() | |
while line'="" { | |
set min=9999999999,max=0 | |
for i=1:1:$l(line,$c(9)) { | |
set num=$p(line,$c(9),i) | |
if num<min set min=num | |
if num>max set max=num | |
} | |
set diff=max-min | |
set total=total+diff | |
set line=file.ReadLine() | |
} | |
write !,"Total :",total | |
} | |
ClassMethod Day2Part2() | |
{ | |
set total=0 | |
set file=##class(%File).%New(..#FOLDER_"day2b.txt") | |
do file.Open("R") | |
set line=file.ReadLine() | |
while line'="" { | |
set edv="" | |
for i=1:1:$l(line,$c(9)) { | |
set num1=$p(line,$c(9),i) | |
for j=1:1:$l(line,$c(9)) { | |
if i=j continue | |
set num2=$p(line,$c(9),j) | |
if num2>num1 set sum=num2/num1 | |
if num1>num2 set sum=num1/num2 | |
if num1=num2 set sum=num2/num1 | |
if sum#1=0 set edv=sum | |
} | |
} | |
set total=total+edv | |
set line=file.ReadLine() | |
} | |
write !,"Total :",total | |
} | |
/* DAY 3 | |
.__. .=========. | |
.(\\//). .-[ Caché ] | |
.(\\()//)./ '=========' | |
.----(\)\/(/)----. | |
| ///\\\ | | |
| ///||\\\ | | |
| //`||||`\\ | | |
| |||| | | |
| |||| | | |
| |||| | | |
| |||| | | |
| |||| | | |
| |||| | | |
jgs '------====------' | |
*/ | |
ClassMethod Day3Part1(input = 368078) | |
{ | |
set (x,y)=0,(inc,dir,m)=1 | |
for { | |
for i=1:1:inc { | |
set m=m+1 | |
set x=$s(dir=1:x+1,dir=3:x-1,1:x),y=$s(dir=2:y+1,dir=4:y-1,1:y) | |
if m=input return $zabs(x)+$zabs(y) | |
} | |
if m=input quit | |
set dir=$s(dir=4:1,1:dir+1) | |
if 13[dir set inc=inc+1 | |
} | |
} | |
ClassMethod Day3Part2(input = 368078) | |
{ | |
set (x,y)=0,(inc,dir,g(0,0))=1 | |
for { | |
for i=1:1:inc { | |
set x=$s(dir=1:x+1,dir=3:x-1,1:x),y=$s(dir=2:y+1,dir=4:y-1,1:y) | |
set g(x,y)=$g(g(x,y))+$g(g(x,y+1))+$g(g(x,y-1))+$g(g(x+1,y))+$g(g(x+1,y+1))+$g(g(x+1,y-1))+$g(g(x-1,y))+$g(g(x-1,y+1))+$g(g(x-1,y-1)) | |
if g(x,y)>input return g(x,y) | |
} | |
set dir=$s(dir=4:1,1:dir+1) | |
if 13[dir set inc=inc+1 | |
} | |
} | |
ClassMethod Day3Part2LOL(t = 368078) | |
{ | |
s (x,y)=0,d=7,g(0,0)=1,a="+1 -1" f i=1:1 {s e=$s(d=7:1,1:d+2),d=$s($g(g(x+$e(a,e,e+2),y+$e(a,e-2,e)))="":e,1:d),x=x+$e(a,d,d+2),y=y+$e(a,d-2,d),g(x,y)=$g(g(x,y+1))+$g(g(x,y-1))+$g(g(x+1,y))+$g(g(x+1,y+1))+$g(g(x+1,y-1))+$g(g(x-1,y))+$g(g(x-1,y+1))+$g(g(x-1,y-1)) i g(x,y)>t ret g(x,y)} | |
} | |
/* DAY 4 | |
|\.-./| | |
/= =\ | |
/= e e =\ | |
>\=_ Y _=/< | |
(,,)^(,,) | |
|.:.:.:.| | |
| | | |
|, /( | | |
|)\ )/ | | |
|`-;o` | | |
| )\ | | |
; \/.'\ | |
jgs / / | | |
.' \ / | |
.' ;-' | |
/'. .'` | |
| \ / | |
'./_.' | |
*/ | |
ClassMethod Day4Part1() | |
{ | |
set total=0 | |
set file=##class(%File).%New(..#FOLDER_"day4a.txt") | |
do file.Open("R") | |
set line=file.ReadLine() | |
while line'="" { | |
kill phrases | |
set valid=1 | |
for i=1:1:$l(line," ") { | |
set phrase=$piece(line," ",i) | |
if $data(phrases(phrase)) set valid=0 | |
set phrases(phrase)="" | |
} | |
if valid set total=total+1 | |
set line=file.ReadLine() | |
} | |
write !,"No Valid :",total | |
} | |
ClassMethod Day4Part2() | |
{ | |
set total=0 | |
set file=##class(%File).%New(..#FOLDER_"day4b.txt") | |
do file.Open("R") | |
set line=file.ReadLine() | |
while line'="" { | |
kill phrases | |
set valid=1 | |
for i=1:1:$l(line," ") { | |
set p1=$piece(line," ",i),p2="" | |
for j=97:1:122 { | |
for k=1:1:$l(p1) if $e(p1,k)=$c(j) set p2=p2_$c(j) | |
} | |
if $data(phrases(p2)) set valid=0 | |
set phrases(p2)="" | |
} | |
if valid set total=total+1 | |
set line=file.ReadLine() | |
} | |
write !,"No Valid :",total | |
} | |
/* DAY 5 | |
_____ | |
.'~ ~ ~`. | |
| a a | | |
`. ~ .' | |
.----'(>o<)`----. | |
( S S ) | |
`---. o .---' | |
; o : | |
; o : | |
/ \ | |
jgs / /\ \ | |
.-' ~~ / \ ~~ `-. | |
`.___.' `.___.' | |
*/ | |
ClassMethod Day5Part1() | |
{ | |
set p=1,input="1,1,0,-1,-3,0,-5,-1,2,0,-1,-3,-9,-5,-1,-9,2,2,-13,-7,-13,-18,0,0,-21,-10,-2,-12,-18,-4,-27,-24,-16,-10,-24,-12,-5,-31,-17,-10,-22,-16,-3,-10,-5,-37,-16,-4,-8,-1,-44,-12,-38,-42,-27,-9,-52,-13,-12,-36,-26,2,-48,-2,-3,-17,1,-51,-47,-68,-42,0,-53,-47,-34,-17,-15,-10,-76,-53,-58,-24,-62,-78,-11,-5,-71,-52,-41,-84,-57,-63,-88,-11,-61,-55,-85,-61,-87,-57,-46,-94,-19,-31,-84,-60,-7,-31,-25,-90,-108,-79,-25,-41,-96,-88,-3,-67,-91,-28,-19,-103,-88,-70,-18,-64,-59,-49,-88,-110,-83,-68,-17,-61,-33,-88,-29,-56,-78,-20,-108,-45,-46,-51,-59,-1,-92,-40,-101,-131,-141,-59,-35,-26,-14,-22,-52,-108,-47,-70,0,-125,-88,-15,-80,-71,-23,-125,-54,-100,-155,-105,-114,-151,-97,-9,-69,-88,-31,-165,-45,-146,-101,-155,-75,-60,-98,-90,-125,-19,-97,-166,-12,-55,-99,-86,-42,-111,-189,-134,-36,-3,-103,-10,-32,-135,-66,1,-37,-170,-194,-60,-99,-211,-68,-73,-107,-102,0,-11,-110,-202,-136,-222,-82,-137,-11,-121,-47,-49,-115,-7,-208,-102,-86,-176,-84,-107,-133,-17,-71,-103,-112,-184,-104,-22,-129,-223,-63,-11,-199,-142,-245,-157,-125,-160,-111,-209,-229,-88,-233,-137,-149,-204,-223,-93,-198,-123,-167,-250,-166,-234,-114,-1,-265,-144,-86,-65,-32,-131,2,-156,-217,-199,-27,-134,-112,-12,-39,-17,-223,-117,-44,-102,-201,-21,-156,-8,-5,-266,-133,-63,-279,-296,-92,-154,-100,-10,-123,-293,-66,-142,-128,-28,-175,-166,-70,-203,-38,-61,-50,-10,-25,-89,-98,-233,-39,-295,-105,-29,-36,-98,-67,-92,-229,-173,-216,-78,-331,-319,-296,-112,-151,-212,-65,-124,-33,-310,-11,-22,-32,-227,-23,-2,-208,-165,-217,-22,-207,-203,-277,-49,-342,-23,-148,-191,-42,-348,-90,-161,-190,-93,-337,-329,-276,-285,-327,-134,-366,-132,-310,-93,-244,-306,-197,-77,-353,-80,-337,-369,-353,-2,-330,0,-212,-167,-318,-61,-272,-369,-51,-294,-363,-92,-260,-146,0,-351,-154,-194,-30,-74,-155,-226,-21,-316,-20,-326,-105,-311,-232,-223,-250,-35,-308,-14,-93,-17,-422,-354,-377,-283,-413,-19,-245,-152,-179,-173,-97,0,-406,-176,-97,-402,-76,-236,-444,-233,-38,-33,-362,-190,-15,-267,-163,-240,-272,-449,-163,-415,-416,-1,-12,-103,-150,-238,-464,-461,-351,-64,-198,-318,-246,-157,-449,-401,-39,-382,-269,-389,-209,-241,-177,-156,-157,-141,-190,-470,-422,-447,-111,-463,-400,-334,-323,-188,-249,-380,-141,-120,-391,-311,-26,-460,-438,-18,-127,-133,-201,-429,-391,-99,0,-335,-373,-367,-463,-224,-390,-299,-233,-411,-244,-5,-73,-377,-413,-172,-497,-120,-87,-262,-198,-112,-162,-446,-469,-111,-364,-284,-252,-212,-358,-507,-48,-74,-96,-518,-34,-290,-234,-472,-294,-5,-334,-355,-462,-334,-494,-549,-121,-482,-548,-14,-340,-410,-441,-559,-282,-384,-88,-453,-323,-465,-483,-2,-481,-333,-483,-176,-250,-167,-312,-550,-185,-365,-108,-17,-326,-488,-440,-122,-505,-465,-54,-241,-20,-397,-48,-44,-187,-548,-174,-461,-238,-581,-409,-582,-140,-191,-60,-147,-538,-5,-116,-62,-165,-334,0,-578,-264,-396,-589,-354,-276,-283,-238,-616,-202,-59,-529,-346,-196,-247,-247,-622,-523,-65,-525,-563,-210,-211,-569,-340,-391,-211,-324,-515,-234,-241,-576,-478,-392,-307,-202,-648,-485,-460,-22,-42,-383,-440,-378,-340,-303,-167,-608,-92,-167,-217,-355,-126,-669,-576,-7,-568,-526,-577,-163,-566,-561,-217,-413,-275,-225,-472,-626,-667,-21,-179,-299,-204,-73,-172,-8,-373,-344,-551,-487,0,-154,-658,-145,-428,-589,-116,-266,-174,-109,-148,-471,-120,-623,-455,-257,-486,-677,-51,-63,-531,-326,-180,-321,-460,-652,-542,-225,-574,-362,-195,-422,-200,-479,-302,-573,-652,-543,-77,-202,-96,-265,-717,-715,-587,-710,-135,-263,-61,-197,-426,-10,-675,-465,-58,-525,-432,-348,-378,-474,-22,-497,-438,-612,-67,-235,-255,-236,-566,-386,-604,-366,-16,-105,-713,-697,-138,-743,-405,-744,-168,-754,-627,-201,-38,-121,-252,-240,-756,-350,-678,-507,-780,-647,-136,-644,-404,-722,-680,-326,-421,-105,-792,-407,-672,-179,-250,-59,-761,-775,-103,-779,-682,-278,-689,-735,-738,-498,-28,-484,-36,-482,-310,-397,-437,-229,-744,-699,-470,-371,-115,-766,-147,-182,-646,-540,-40,-202,-322,-289,-828,-784,-121,-366,-220,-36,-646,-567,-301,-168,-26,-190,-138,-390,-130,-448,-242,-274,-65,-784,-319,-179,-332,-327,-698,-837,-691,-113,-251,-143,-755,-791,-725,-849,-194,-570,-449,-186,-354,-524,-54,-846,-516,-325,-515,-453,-703,-530,-1,-869,-401,-503,-641,-822,-694,-667,-537,-285,-711,-73,-746,-764,-737,-475,-476,-456,-845,-556,-737,-524,-869,-646,-898,-692,-97,-248,-32,-884,-486,-113,-348,-517,-417,-39,-726,-580,0,-858,-370,-672,-726,-599,-475,-87,-336,-384,-619,2,-235,-629,-774,-905,-727,-232,-389,-626,-240,-780,-392,-900,-911,-592,-625,-424,-274,-231,-327,-714,-729,-537,-526,-8,-468,-809,-566,-786,-798,-245,-958,-652,-610,-703,-207,-727,-930,-883,-959,-204,-976,-568,-121,-503,-910,-134,-619,-558,-340,-24,-16,-780,-797,-594,-441,-886,-420,-639,-979,-711,-745,-916,-152,-700,-116,-523,0,-756,-194,-609,-151,-14,-133,-768,-630,-917,-46,-60,-485,-201,-440,-386,-101,-283,-980,-144,-337,-599,-202,-776,-470,-49,-278,-270,-21,-409,-84,-562,-191,-53,-390,-300,-706,-284,-778,-714,-632,-702,-375,-903,-1019,-475,-353,-950,-410" | |
for i=1:1:$l(input,",") set a(i)=$piece(input,",",i) | |
for i=1:1 set a(p)=a(p)+1,p=p+a(p)-1 quit:'$d(a(p)) | |
write "Result: ",i | |
} | |
ClassMethod Day5Part2() | |
{ | |
set p=1,input="1,1,0,-1,-3,0,-5,-1,2,0,-1,-3,-9,-5,-1,-9,2,2,-13,-7,-13,-18,0,0,-21,-10,-2,-12,-18,-4,-27,-24,-16,-10,-24,-12,-5,-31,-17,-10,-22,-16,-3,-10,-5,-37,-16,-4,-8,-1,-44,-12,-38,-42,-27,-9,-52,-13,-12,-36,-26,2,-48,-2,-3,-17,1,-51,-47,-68,-42,0,-53,-47,-34,-17,-15,-10,-76,-53,-58,-24,-62,-78,-11,-5,-71,-52,-41,-84,-57,-63,-88,-11,-61,-55,-85,-61,-87,-57,-46,-94,-19,-31,-84,-60,-7,-31,-25,-90,-108,-79,-25,-41,-96,-88,-3,-67,-91,-28,-19,-103,-88,-70,-18,-64,-59,-49,-88,-110,-83,-68,-17,-61,-33,-88,-29,-56,-78,-20,-108,-45,-46,-51,-59,-1,-92,-40,-101,-131,-141,-59,-35,-26,-14,-22,-52,-108,-47,-70,0,-125,-88,-15,-80,-71,-23,-125,-54,-100,-155,-105,-114,-151,-97,-9,-69,-88,-31,-165,-45,-146,-101,-155,-75,-60,-98,-90,-125,-19,-97,-166,-12,-55,-99,-86,-42,-111,-189,-134,-36,-3,-103,-10,-32,-135,-66,1,-37,-170,-194,-60,-99,-211,-68,-73,-107,-102,0,-11,-110,-202,-136,-222,-82,-137,-11,-121,-47,-49,-115,-7,-208,-102,-86,-176,-84,-107,-133,-17,-71,-103,-112,-184,-104,-22,-129,-223,-63,-11,-199,-142,-245,-157,-125,-160,-111,-209,-229,-88,-233,-137,-149,-204,-223,-93,-198,-123,-167,-250,-166,-234,-114,-1,-265,-144,-86,-65,-32,-131,2,-156,-217,-199,-27,-134,-112,-12,-39,-17,-223,-117,-44,-102,-201,-21,-156,-8,-5,-266,-133,-63,-279,-296,-92,-154,-100,-10,-123,-293,-66,-142,-128,-28,-175,-166,-70,-203,-38,-61,-50,-10,-25,-89,-98,-233,-39,-295,-105,-29,-36,-98,-67,-92,-229,-173,-216,-78,-331,-319,-296,-112,-151,-212,-65,-124,-33,-310,-11,-22,-32,-227,-23,-2,-208,-165,-217,-22,-207,-203,-277,-49,-342,-23,-148,-191,-42,-348,-90,-161,-190,-93,-337,-329,-276,-285,-327,-134,-366,-132,-310,-93,-244,-306,-197,-77,-353,-80,-337,-369,-353,-2,-330,0,-212,-167,-318,-61,-272,-369,-51,-294,-363,-92,-260,-146,0,-351,-154,-194,-30,-74,-155,-226,-21,-316,-20,-326,-105,-311,-232,-223,-250,-35,-308,-14,-93,-17,-422,-354,-377,-283,-413,-19,-245,-152,-179,-173,-97,0,-406,-176,-97,-402,-76,-236,-444,-233,-38,-33,-362,-190,-15,-267,-163,-240,-272,-449,-163,-415,-416,-1,-12,-103,-150,-238,-464,-461,-351,-64,-198,-318,-246,-157,-449,-401,-39,-382,-269,-389,-209,-241,-177,-156,-157,-141,-190,-470,-422,-447,-111,-463,-400,-334,-323,-188,-249,-380,-141,-120,-391,-311,-26,-460,-438,-18,-127,-133,-201,-429,-391,-99,0,-335,-373,-367,-463,-224,-390,-299,-233,-411,-244,-5,-73,-377,-413,-172,-497,-120,-87,-262,-198,-112,-162,-446,-469,-111,-364,-284,-252,-212,-358,-507,-48,-74,-96,-518,-34,-290,-234,-472,-294,-5,-334,-355,-462,-334,-494,-549,-121,-482,-548,-14,-340,-410,-441,-559,-282,-384,-88,-453,-323,-465,-483,-2,-481,-333,-483,-176,-250,-167,-312,-550,-185,-365,-108,-17,-326,-488,-440,-122,-505,-465,-54,-241,-20,-397,-48,-44,-187,-548,-174,-461,-238,-581,-409,-582,-140,-191,-60,-147,-538,-5,-116,-62,-165,-334,0,-578,-264,-396,-589,-354,-276,-283,-238,-616,-202,-59,-529,-346,-196,-247,-247,-622,-523,-65,-525,-563,-210,-211,-569,-340,-391,-211,-324,-515,-234,-241,-576,-478,-392,-307,-202,-648,-485,-460,-22,-42,-383,-440,-378,-340,-303,-167,-608,-92,-167,-217,-355,-126,-669,-576,-7,-568,-526,-577,-163,-566,-561,-217,-413,-275,-225,-472,-626,-667,-21,-179,-299,-204,-73,-172,-8,-373,-344,-551,-487,0,-154,-658,-145,-428,-589,-116,-266,-174,-109,-148,-471,-120,-623,-455,-257,-486,-677,-51,-63,-531,-326,-180,-321,-460,-652,-542,-225,-574,-362,-195,-422,-200,-479,-302,-573,-652,-543,-77,-202,-96,-265,-717,-715,-587,-710,-135,-263,-61,-197,-426,-10,-675,-465,-58,-525,-432,-348,-378,-474,-22,-497,-438,-612,-67,-235,-255,-236,-566,-386,-604,-366,-16,-105,-713,-697,-138,-743,-405,-744,-168,-754,-627,-201,-38,-121,-252,-240,-756,-350,-678,-507,-780,-647,-136,-644,-404,-722,-680,-326,-421,-105,-792,-407,-672,-179,-250,-59,-761,-775,-103,-779,-682,-278,-689,-735,-738,-498,-28,-484,-36,-482,-310,-397,-437,-229,-744,-699,-470,-371,-115,-766,-147,-182,-646,-540,-40,-202,-322,-289,-828,-784,-121,-366,-220,-36,-646,-567,-301,-168,-26,-190,-138,-390,-130,-448,-242,-274,-65,-784,-319,-179,-332,-327,-698,-837,-691,-113,-251,-143,-755,-791,-725,-849,-194,-570,-449,-186,-354,-524,-54,-846,-516,-325,-515,-453,-703,-530,-1,-869,-401,-503,-641,-822,-694,-667,-537,-285,-711,-73,-746,-764,-737,-475,-476,-456,-845,-556,-737,-524,-869,-646,-898,-692,-97,-248,-32,-884,-486,-113,-348,-517,-417,-39,-726,-580,0,-858,-370,-672,-726,-599,-475,-87,-336,-384,-619,2,-235,-629,-774,-905,-727,-232,-389,-626,-240,-780,-392,-900,-911,-592,-625,-424,-274,-231,-327,-714,-729,-537,-526,-8,-468,-809,-566,-786,-798,-245,-958,-652,-610,-703,-207,-727,-930,-883,-959,-204,-976,-568,-121,-503,-910,-134,-619,-558,-340,-24,-16,-780,-797,-594,-441,-886,-420,-639,-979,-711,-745,-916,-152,-700,-116,-523,0,-756,-194,-609,-151,-14,-133,-768,-630,-917,-46,-60,-485,-201,-440,-386,-101,-283,-980,-144,-337,-599,-202,-776,-470,-49,-278,-270,-21,-409,-84,-562,-191,-53,-390,-300,-706,-284,-778,-714,-632,-702,-375,-903,-1019,-475,-353,-950,-410" | |
for i=1:1:$l(input,",") set a(i)=$piece(input,",",i) | |
for i=1:1 set j=$s(a(p)>2:-1,1:1),a(p)=a(p)+j,p=p+a(p)-j quit:'$d(a(p)) | |
write "Result: ",i | |
} | |
/* DAY 6 | |
/`\ | |
| ( | |
| | |
| | |
| | |
| | |
| | |
| | |
.--'--. | |
| | | |
_.--""`````""--._ | |
.'\/ \/ '. | |
.' -|` `|- '. | |
/ ,_\| |/_, \ | |
/ # \ / \ | |
; # .-.._)---(_.--. ; | |
| \_.-/ \-._/ | | |
| | a a | | | |
| \ /`\ | | |
; | | '. ; | |
\ \0/\ '/`\ / | |
\ |__.' / / | |
'. / _.' .' | |
'._ '---' _.' | |
jgs '--.._____..--' | |
*/ | |
ClassMethod Day6Part1() | |
{ | |
set input="10,3,15,10,5,15,5,15,9,2,5,8,5,2,3,6",len=$l(input,","),seen(input)="" | |
for i=1:1:len set a(i)=$piece(input,",",i) | |
for j=1:1 { | |
set high=0,pos="" | |
for k=1:1:len if a(k)>high set pos=k,high=a(k) | |
set blocks=a(pos),a(pos)=0 | |
for l=1:1:blocks set pos=$s(pos=len:1,1:pos+1),a(pos)=a(pos)+1 | |
set tmp="" | |
for m=1:1:len set tmp=tmp_a(m)_$s(m<len:",",1:"") | |
if $d(seen(tmp)) quit | |
set seen(tmp)="" | |
} | |
write "Result: ",j | |
} | |
ClassMethod Day6Part2() | |
{ | |
set input="10,3,15,10,5,15,5,15,9,2,5,8,5,2,3,6",len=$l(input,","),seen(input)="",inLoop=0 | |
for i=1:1:len set a(i)=$piece(input,",",i) | |
for j=1:1 { | |
set high=0,pos="" | |
for k=1:1:len if a(k)>high set pos=k,high=a(k) | |
set blocks=a(pos),a(pos)=0 | |
for l=1:1:blocks set pos=$s(pos=len:1,1:pos+1),a(pos)=a(pos)+1 | |
set tmp="" | |
for m=1:1:len set tmp=tmp_a(m)_$s(m<len:",",1:"") | |
if inLoop,$d(seen(tmp)) quit | |
if $d(seen(tmp)) set j=0,inLoop=1 kill seen | |
set seen(tmp)="" | |
} | |
write "Result: ",j | |
} | |
/* DAY 7 | |
.--._.--.--.__.--.--.__.--.--.__.--.--._.--. | |
_(_ _Y_ _Y_ _Y_ _Y_ _)_ | |
[___] [___] [___] [___] [___] [___] | |
/:' \ /:' \ /:' \ /:' \ /:' \ /:' \ | |
|:: | |:: | |:: | |:: | |:: | |:: | | |
\::. / \::. / \::. / \::. / \::. / \::. / | |
jgs \::./ \::./ \::./ \::./ \::./ \::./ | |
'=' '=' '=' '=' '=' '=' | |
*/ | |
ClassMethod Day7Part1() | |
{ | |
while ..FileUtil("day7a.txt",.file,.line) { | |
set line=$tr(line," ",""),pro=$p(line,"("),map(pro)=$p($p(line,"(",2),")"),chi=$p(line,"->",2) | |
if chi'="" for i=1:1:$l(chi,",") set map(pro,$p(chi,",",i))="",idx($p(chi,",",i))=pro | |
set root="" for set root=$o(map(root)) q:'$d(idx(root)) | |
} | |
write !,"Root :",root | |
} | |
ClassMethod Day7Part2() | |
{ | |
kill | |
while ..FileUtil("day7a.txt",.file,.line) { | |
set line=$tr(line," ",""),pro=$p(line,"("),map(pro)=$p($p(line,"(",2),")"),chi=$p(line,"->",2) | |
if chi'="" for i=1:1:$l(chi,",") set map(pro,$p(chi,",",i))="",idx($p(chi,",",i))=pro | |
set root="" for set root=$o(map(root)) q:'$d(idx(root)) | |
} | |
set %t(root)=map(root) | |
do ..BuildTree(.map,root,root) | |
//calculate totals | |
for { set k1=$o(%t($g(k1)),-1) q:k1="" for i=2:1:$l(k1,".") { set ($p(%t($p(k1,".",1,i)),"~",2),%t($p(k1,".",1,i-1),$p(k1,".",i))) = $p(%t($p(k1,".",1,i)),"~",2) + %t(k1) }} | |
//find imbalance | |
for { | |
set k1=$o(%t($g(k1)),-1) q:k1="" | |
kill x,y | |
for { | |
set k2=$o(%t(k1,$get(k2)),-1) q:k2="" | |
set i=$i(x(%t(k1,k2))),y(%t(k1,k2))=k2 | |
} | |
set v1=$order(x("")),v2=$order(x(""),-1) | |
if v1'=v2,$g(correction)="" { | |
set good=$s(x(v1)=1:y(v2),1:y(v1)) | |
set bad=$s(x(v1)=1:y(v1),1:y(v2)) | |
set correction=$p(%t(k1_"."_bad),"~")+(%t(k1,good)-%t(k1,bad)) | |
} | |
} | |
zw %t | |
write !,"Correction:",correction | |
} | |
ClassMethod BuildTree(ByRef m, n, p) | |
{ | |
for { set c=$o(m(n,$g(c))) quit:c="" set p2=p_"."_c,@("%t("""_p2_""")")=m(c) do ..BuildTree(.m,c,p2) } | |
} | |
/* DAY 8 | |
____ | |
.-" +' "-. | |
/.'.'A_'*`.\ | |
|:.*'/\-\. ':| | |
|:.'.||"|.'*:| | |
\:~^~^~^~^:/ | |
/`-....-'\ | |
jgs / \ | |
`-.,____,.-' | |
*/ | |
ClassMethod Day8() [ CodeMode = objectgenerator ] | |
{ | |
//get instructions | |
while ..FileUtil("day8a.txt",.file,.line) { set instructions($i(instructions))=line } | |
//extract variables | |
for { set i=$o(instructions($g(i))) q:i="" set vars($p(instructions(i)," ",5))="" } | |
//initialise variables | |
set code=" set (",comma="" | |
for { set var=$o(vars($g(var))) q:var="" set code=code_comma_var,comma="," } | |
set code=code_")=0" | |
do %code.WriteLine(code) | |
do %code.WriteLine(" set (max,top)=0") | |
//cosify instructions | |
for { | |
set i=$o(instructions($g(i))) q:i="" | |
set instruction=instructions(i) | |
set instruction=$replace(instruction,"inc","+") | |
set instruction=$replace(instruction,"dec","-") | |
set instruction=$replace(instruction,"!","'") | |
set instruction=$replace(instruction,"==","=") | |
set instruction=" "_$p(instruction," ",4,*)_" set "_$p(instruction," ",1,3) | |
set var=$p(instruction," ",7) | |
set $p(instruction," ",7)=var_" = "_var | |
do %code.WriteLine(instruction) | |
do %code.WriteLine(" if "_var_">max set max="_var) | |
} | |
//find largest register | |
set code=" for reg=",comma="" | |
for { | |
set var=$o(vars($g(var))) q:var="" | |
do %code.WriteLine(" if "_var_">top set top="_var) | |
} | |
//output result | |
do %code.WriteLine(" write !,""Part 1 Result: ""_top") | |
do %code.WriteLine(" write !,""Part 2 Result: ""_max") | |
} | |
/* Day 9 | |
___,@ | |
/ < | |
,_ / \ _, | |
? \`/______\`/ | |
,_(_). |; (e e) ;| | |
\___ \ \/\ 7 /\/ _\8/_ | |
\/\ \'=='/ | /| /| | |
\ \___)--(_______|//|//| | |
\___ () _____/|/_|/_| | |
/ () \ `----' | |
/ () \ | |
'-.______.-' | |
jgs _ |_||_| _ | |
(@____) || (____@) | |
\______||______/ | |
*/ | |
ClassMethod Day9() | |
{ | |
set es=0,gf=0,gr=0,gc=0,gb=0 | |
set input="{{{},{{{{<e""""a!!io<""!!!!""!'!!""u!>},<""o!!}i>,<!>!i<!!!!oi!>},<>},{},{{<!>,<{!u!!!>,<!!'<!>!,,!!""!e'o}>}}},{},{<!!!!""a""<!!eo,!>}!!!>,io!>'!o>}},{{{<!!!'ou!!!>!oe!>!<!!i>,{<!>},<uoue>}},{},{{<}}>,<""'',!!}{!!i{>}}},{{{{<'o!>>,<!>!{u}<e!>a<au!!o!>,<a!!""""a!!!>"">},{{<i{!>,<""!>e!!'!!!!!>},<'o!!!,!e<o<>},{{}}}},{{<e'!!!!!!i""a!>,<,>},{<'!!!><!}!!{!>},<,""u>}}},{{{{<a{o!!!!!>!><<!!!>},<>}},{<!!""!>e>,{<!>},<""}a""''!!!!!!!>o<}!!,>}}},{{{<!,}!""}!!!>,<'!!!!e!>},<!>},<{!>},<,,!!}}!!u>},{{}}},{{{<i!>,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<!!!>,{oi{!!,!e!!!<>},{{},{}},{{<e<<!>,<!>,<!!!>},<}""{e<!euue""!""o>},{<e!!!!!>oa>}}}},{{{<!>,<'<!!!>eo!>,<!aa},>,<'""!!!!!>!!e""!!!>'}!!>},{{{<""!>},<{a!!'!!!>!!""!'a!!!!!>!!u>},{<'>}}},{{<a!>i!>},<!'e!>!>!!!><e!>!>},<"">},{<<>}}},{{<<u!i}!>,<!!!>>},{}},{{<ao'u!>},<'u{',uo>,<!!a'{ue,>},{}}},{{<!>!!e!>,<e>,{{<!>},<{'!>,<!!!>'a,!!!>!'!>,<<!>!!!<!>,<<{"">}}},{<!>},<!}oii!o""!>,<>}}},{{<<!>,<}!""!>!>},<!!!>u>}}},{{<ei!!>}},{{{<!>>,{<>}},{{<!,oa}!!!>o{>},{}},{}},{{<"">}},{<o!!!>""uaou!>,""'>,{<!>},<<o"",!!!>!>u!e!>,<ui!>},<<>,<,!}}}""!!{e!>,<aeaia'!<>}}}}}},{{{}},{{<!>},<!!!>!!!>,o,o!!o!!!><>}},{{<}'!!!>!>!!a}>,{}},{}}}}},{{{{{{<>},{<eui'a!!<!>,<ie!!<}!u!>},<!>},<{!>,<!!>}},{{}},{<!!!>"">,<aou!!,!>,<}""{ee>}},{{}}},{{{{<!!!!""uou>}},<<'""!o,e{a!>},<!>,<"">},{{<<!>},<!>},<!>},<i!uu<u!!!!ooie!>},<!>{o>},<a>},{{{},<>},{{<o!!!>ao!!{}{u!>},<,i""!!>}}}},{{<"">},{{<!!!><!>},<'!!!>""!>},<""!>,<,""""!}ua!>""a>}}},{{{},<<!!!>!>,<a!!!>!>},<'oe!!!>,<!>,<!!!!!>!!!!!!i'!uieo>},{{<!!!>!>},<!!o'i}o!!!!ae!!{""!>>,<!>,<!>},<<e,,!!>},{{<!!!!!>u!!!>{!!oi!>>},{}},{{<a""!eii!!!aa,,',!>,<io>},{<!!o!>},<,>}}}}},{{},{{{<i!!!!!>,<!>},<'""}!!!>}u""o!>,<""!}<<!!>},{{<io!>,<!!!!a!!!>e!!!>!,!!!>ae!a!!""<!!}!>,<e>}}},{<<""!>},<!!>,{<u}>}},{{},{<!oo'!>i!>},<!>,,!!'<!!!>e>}}},{{{<!!!>'{>},<!>,<!>},<}!o>},{<}e!!!>!>,'!>,<!!>,{}},{{},<>}},{}},{{{{<'!!!!!>o!!!,!>,<""'>}}},{{{<!>},<>}},{},{{<e!u""'>,{}}}}}},{{{{{{<!<'u}u<!!"">},{{<""""ie!""{>}}}},{<}!!!!e<'ioa!>},<""!>},<!eo!>},<!>,<!!u>}},{},{{<<<>,{<!{!>},<!!{!!,!>!a!>""{!!!>!{!!!!iei<>,{{<!!a!u'!!i!aeu!!'!>},<'u!!u"">},{{<!!!>},<,""oe!<{!,u!!!>!""!!!>>}}}}},{{<iiia>},<<!!!>!!!!,>},{{<!><!!u>},{<!!!>,<'!>""!>,<>}}}},{{{{},{{{<aeu!>,<{e!!!>!!!!!"">},<<!!!>},<""!>u!'{',>},<!!!!!>a!""o"",!a!'!u}!>},<""a!>},<>}},{<>,<u!>},<{!!!>,o!!aa""!!'!!!!""!!!>ie>}},{{{<!!a!>,<!!u>}},{{{{<!{'!!!!!><{!>ii>}}},<o!!!>!!!>e!!{!>,u!!o!!!!o>},{{<>}}},{{{{<{!!!!i""i<o!!""!!ui}}>,<!<!>""ui""!!<!>o!>},<!!}!>'"",>},{<!!e!>>}},{{{{{<!!ouee}o!""!!e!<a!>},<e,}!!'>},<{o<,o""<a!!!>i!!!>},<,!!!'!!o!>,<u!>>},<<""!>,<{o{!}i!!<>}}},{{{{<!!{!!!>'a'""!ei>},{<!!!!!>,<,!!!>'""e!{<!>,<>}}}}}},{{<""!!!>ai'>},{{{<!>,<""ou""u!>}!!'ue!>},<'o}!>},<a!a>}},<i!>},<""i,u!!!>!!!!!>i""{!!!>>}}},{{{{<!a!!!>!o}!!!>},eo!!!>!>},<!>!>},<!>"",!!!!u,>,<!>!!ie,o<',<}!>""oe!>,<!!>},{{<!!!>!i{u>},<u!!i!>},<'o!}eu{}!e>},{{<""<u!>!>,<<!!o'!!!!!!!!!!e!,!!!!'!!!>,'!!!>>},<e'!!o>}},{},{{{{{<""!!!>!!!>}o!>},<u}u}!!e!!!>!!e!!e!!!>>}}}},<!>,<o!!eo!!""!!!>>}},{{{{<{'!iu!>,<}!>},<}>},{<'i>}},{<}ea!!{,o!!!>,<'}oi<,!}a"">,<!!!>,<!!!!u,""<i>}},{{<!!!>aei{!>,<!>,<'e<>},{}},{{{},<!>,<>}}},{{<>,<o!>,<i!>},<>}}},{{{{<,""oo!>},<!!!>i<'!!{!>a!!i""!""!!>,<!!i!>i!!a!!!!!>{>}},{{<a>}}},{{{<e{!!!!'>,{<!!o""{,!!!!>}},{{<iia{e<<a!!!!!!'>},<!!!>},<!!o!!!>,<!>},<""!!!!!!!>!!!>!!!!uau<>},{<i""a!!!>a!>{oo,!>},<a!!!>!!ii<}>,{<""!ia!><o!!!ao!!oe,,i'>}}},{{{<""o,!>,!a!!e>},{},{{{<>},<!>},<auii!!!><{>},{<!ia<iu'!u!>!!!>},<!>},<o""!!,>}}},{<!!!>},<!!!!!>'!>},<<!!,""!!{}<>,<o!!!>!>!>}!!!>!>!!!>!>,<!>,<i!!uu<ou"">},{{<!>u!>!{,a!}!>,<},i!>,<!!!!""""a!!!>,<>}}},{},{{},{<}!>e!!>,<!o!>!!!>},<!""!!u!!!>!!'u!>,<!>>}}},{{{{{<!!{""<u}!!!!!>!!o!i""!!!>!>i!!<}o!>},<!!'>}},<<{<>},{{{<!>},<o!>},<i!!!>!>,<'!>},<>}},{},{{<!>{}!>,<!!,,!!,!!"">},{}}},{{{{{<""!!,}{a!!>},<,!{eau>},{<!o!oo!i}!>,<!o>}},{{{},{}}}},{<ao>},{<,!!!>a!>,<'>,{}}}},{{<!a'!!!!!,!{!>!>,<}!>},<!!""!!!>}<,>},{{<>},{}},{<""""a!!!>>}}},{},{{{{<!>a!>},<<!!ii!!!>!!!,!!>},{<!!oe!{!>},<a'!>,<!!a!,!>>}},{{<!!>},{{<<ouuu,o"",a<!!!}!>},<{{!>o!>,<>},<!!!>,<}o>}},{{<!>},<u!!!!o>,{}}}},{{{{{<a,>},{<!a!!<ii""<!""!!!>!!!>!>,<!!!>,aaa!!!>!>,<!!<>}}},{{<!!!>!!'e{!,"",!!!>ii!>"">},{{},<}u{!!!>!!!>!!""!!!>}!!"">}}},{{<!!u<<e!>iu!!!>!>},<!>,<!>,<>},{},{{<i'!>""!!!!!>u!!!!!>!>,i>},<i{u!<,}!!}a!>,!>!>!!{""!!a>}},{{},{}},{{{<!!o!!!!!<u!>,<}!e>},{<a,!>},<!!!!!>!>,<!{!!!>!>!ao""!a>}},{{{{{<>}},{{},<>},{}},{},{<}e>,{}}}},{}}},{{{<}""!!!>e!!!><>}},{{<'!!!!""u'}aou,a>,{<<e!!,'e""""!>!>,<{!>},<!!o!>oa>,{{},<u,!!'!!!><"">}}},{{<'!!!>e{!>},<!eo!i!><"",>},{{<!!!>a,u!>!>,<}u!!}!>},<>},<"",!>},<""!a!!""!>!>},<>}},{<o!!""a!>!!}eiii{>,<!!!>!>!>}!>!!!>,<!>!!!!!!i>}},{{{<e}!>,<{!!a!>!>,<!!aoo!>,<ai!>},<>},{<""o}'""!uo<!{'!!!>{'o'""{>,{}}},{<!!""'""!!}!>}>}}},{{{{{<!>},<e!>},<>},{}},{<{'>},{<o!!e!>,<>,{{}}}},{{},{<u,o!!!!i!!!>},<""!>,<{>},{}},{{{<!>"">,<'!!,{!>!!!>,>}},{{{<{<!>},<!""!>},<'>,<!>o!!!!!!""<oe{""<!>!>,<!!aa!>},<>},{<e}""<!>},<!>ie!e!!""{auu<oie>}}}},{{{<}>},<uo!!<{""!!}e'o!>,<a!>},<!>,<!!!>!!!>,<>}}},{{{<<!!!!!!!>!>!>}}{{!!o""e>}},{{}},{<!>},<!!!a!!'!!!>!>e>}},{{},{},{{<>}}},{{{<!!!>u!!!>eo!o}u!}!{!>},<}'i!>},<>,<,!!!>},<'!!!!!!!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"">}},{<!!!>i!>},<}!!!>,<'!!!>,<a!>,<,!!!!au!>,<o""""e>,{<<!>,<!>,<{'>}}},{{<!!ou!!'!>},!!!>ao!!!>>,{<e<<a!{,a{!!!>!>,<!!}!>},<!!!>!>!>!>>}},{<!!{!!!a<!eu!!'!>!!!>!>}>,<,,,{>},{<!!!!!>,!!>}}},{{{{{<euu!!i""{>},{{},<o{!>!}""ea!!!>>}},{{},{<!>,<!!oe}!>},<'{}!!!i!!!>""!>},<!>},<ie!>,<!!>}},{<o>}},{{{<!>},<e!!oe!>,<e!!!>'a!>u!!<,!!!>>},{<!>},<i>}},{{<!>},<}i!!!!!>e!!!!!>o>},{<>}},{}}},{{{{{<!>i}e'!!!>},<o{!""!!!!<!!!<{!o>},<{!>,<<a,{i!,!!!>!>,<>}},{{{<!'!!!>!<{,""o!>,<!!!>!!o>},{<!>i{'!!!!!i'!>,<!!!>}a!!!>},<>}}}}}}}}" | |
for i=1:1:$l(input) { | |
set c=$e(input,i) | |
if c="<",gf=0 set gf=1 continue | |
if 'es { | |
if c="!" set es=1 continue | |
if c=">",es=0 set gf='gf | |
if c="{",'gf set gr=gr+1 | |
if c="}",'gf set gc=gc+gr,gr=gr-1 | |
if gf set gb=gb+1 | |
} else { | |
set es=0 | |
} | |
} | |
w !,"Total Groups:",gc | |
w !,"Total Garbage:",gb | |
} | |
/* | |
_____ | |
.-"` `'. | |
/, \ | |
/ /``'--..--'``\ | |
| \__.__.__,___/ | |
\_ {/ e e \} | |
{ `}() (__) ()| | |
`/,_.-")("-._,\ | |
{ `--`==`--` } | |
.'{ } }'. \/ \/ | |
.' { } } \ -|` `|- | |
/ { { } ; ,_\| |/_, | |
; , '-..____..-' , | \ / | |
| ; : ; | .-.._)---(_.--. | |
| <`;._ _:_ _.| .-\\_.-/_ _ \-._/ | |
| | `'|.-.|'` (\ \_ |a a | | |
\_.'`}`'-.._||_||_..-'\\ _.'_} \ /`\ | |
{_.'`_) '-;-' \{_.' `_)| | '. | |
| \--..__ : __..--'``\\ \\0/\ '/`\_...--"""-. | |
\___/ ``` _/ \___/ |__.'`()/ `\. | |
'-;-..._____...-;-' / ()_.' . ;`\ | |
| | | ()_.-' . |-' | |
| | | \ , ; ; | |
\ _ _ _|_ _ _ / ;-, /___..,-`\ ; | |
/` ` ` | ` ` `\ | / /' \ \ ; | |
\_._._/ \_._._/ |/ / \ \ | | |
|= | | =| / / `> > / | |
jgs .-'-. | | .-'-. / / \ / / /` | |
/ | | \ /_/ \/\ /_/_/ | |
\____,__/ \__,____/ /_( |/ /_/_( | |
ASCII ART PROVIDED BY : http://www.chris.com/ascii/joan/www.geocities.com/SoHo/7373/xmas.html#elfgift | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment