From cc4b2d86b0ca50120a1c9c16eebc2019819feb2f Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Tue, 12 Dec 2017 21:05:25 +1100 Subject: [PATCH] Add day 9 solution --- 2017/day/9/Cargo.lock | 4 ++ 2017/day/9/Cargo.toml | 6 ++ 2017/day/9/input | 1 + 2017/day/9/problem.txt | 46 +++++++++++++++ 2017/day/9/src/main.rs | 125 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 2017/day/9/Cargo.lock create mode 100644 2017/day/9/Cargo.toml create mode 100644 2017/day/9/input create mode 100644 2017/day/9/problem.txt create mode 100644 2017/day/9/src/main.rs diff --git a/2017/day/9/Cargo.lock b/2017/day/9/Cargo.lock new file mode 100644 index 0000000..c803c5b --- /dev/null +++ b/2017/day/9/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "day9" +version = "0.1.0" + diff --git a/2017/day/9/Cargo.toml b/2017/day/9/Cargo.toml new file mode 100644 index 0000000..d272a42 --- /dev/null +++ b/2017/day/9/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day9" +version = "0.1.0" +authors = ["Wesley Moore "] + +[dependencies] diff --git a/2017/day/9/input b/2017/day/9/input new file mode 100644 index 0000000..eb4d605 --- /dev/null +++ b/2017/day/9/input @@ -0,0 +1 @@ +{{{{{!>'!!!>!!!!!!!>u!!!!!>},<'>,e{o!!!>!'>}},{{{},!'!!a}!!!>,!!!!!i!!,e!>,},}},{{},{{},},!i>},{>,{a>}}},{{{{,u!!,}!!!>!!"'!!!>,i!!e>},},ii{!>},,">}},{},<{!!!>!>},ou!!!!!>!"!!!!!!!>!!>,{},,<"ui!!,u'!>,!!o!!a>}},{{<"!!<,},!!"},}}}}},{{{{{{{{{!>,<,>},{,<,}!>},},<,!!!>,!!!>'>}},{{<{}!!e!!!!>},{,,<""a!!!>},}},{,!eia'!>},,,{}}},{<,oo>,{{},!>},<''>,{<{e!!!>!!!>}>}},{{}}}},{{>}}},{{{{,,}},{{}},{{{{o!!!>!!"o!!!>>}},{<'>}},{}}},{{,i>}},{}}},{{{!>},{!"i!}oie>},{,<,">}}},{{{},{{{{{{<{uu{'!!>},{<>,}},{{{,,,}},,}},{}}},<'i!!ueiu,!>},},!!<"}!!!>,},<>}}}},{{{{<,!>},<',!!',ei!>!>},i!!}ee,>,{{}}},{{{<'a'!!e!"i!>o!!!>!!!>!!!>{!!!>,<,>},},{,<{!!!!!>!!,!!!>>,{<,!!>}},{,!>}e!>},}{'!!!>o>}},{}},{{{,{<,}"!>!!!>}o!>,<>}}},{{{{{,,},{o>}},,,<}},{},{{<,<>},{"o!!aue,>,},},<}}},{},,},!!a,e!!!!!>,<>,{!>},}}}},{{{{{},!>,,{!!!!o!>},u!>,i!o!>!e''!>!>i>,{{<,u'!>i"o!!"}>}}}}},{}},{"}{!>},},,,<"!>,<"u>},{{}}},{{{{{>,u,,o}"{>},{,<<,!!!>,!>o!,!>,}}},{{{!>},,,{}},{!!i>,{{},{},<'{},{{!>,<>}}}},{{<,},{{{}},},,<{!!!!!>"o!!<,e!o!!!!!>},},<>},{},<>}},{{<'!>!>!>,<>},<"io!!!''!!!>!!o!!o!!!>,<!>,<>}},{}},{{{<'i!!!'}!!!>!>!!u!!!u!>oo!>},<>},{,!>,},}}}},{{<{i!!iu!,!!'!!!!{"!!!>>,{}},{{<",!>a{a!!{i!>,},<}u!>,!!oii>},{{<'u!!"!!!>}a!!e!aa!>,!!!>,<<>},},<"}"!!!>i!>,<>}},{{,{<'}"!!!o!>},}},{,,{<{!>,<"!>,<,!!,!!,e!!{{a,!!!!!>},<}}}},{{<}!>'!!{,,e!>,},>},{{{{{{}}},{}},{{}}}}}}},{{{{},},!!!!i}e!!},!>,<{!>,>},{<'!'''!>o"},!!e{!"o!>,{!>u>,{}}},{{{,!>!!o!!}iou>}},{{{},,,a<>},{,},<{i!!o>,,}}}}},{{{{},},,<,!!!!!!,!!!>,}},{{},{<,{},<{!,!!u!!!!!!!!!>},,!!!>i!!{,}}},{o!>',{<"!>!>!>},<'{o{e!>,<,a}!!i>}}},{{},{},{},,e!!!!!!!!e}!!!!a!!'}">}},{{{{},!>},},!!!>i}!>,<<>},{},{{{},{},}},{,<'!!!>{!!>}}},{{},{'""!o!>,<>,!!!>ue!!!>i{'!u<,!,>},{{}}},{{{},,,i}},!>,},{{},},>}}},{{<"}},,<>,'!!!'u!!!!!u!!}>},{{!>},<}>},!!,a','>},{{,{}}}}},{{{{{{}}},{{{{{!>,<>}},{{}}},{<}!>,<,{i!!}!>},>},{{{{,"!!!>u},,{,i"a}!!}a!>i},!!a!!!>>}}},{{},{}},{{{{,<"u},}},{}},{{{<">,},!!u>},{,<{>,{{<"ie!}!>a!e>,{}}}},{<}i''ua{!>},<>}},{{},{},!>},!>},<,},<,a,>}}}}},{{},{{<,"u{>},{}}}}},{{<,!!i!!i!!!!"a"!!!>!>,<>,,<}},{!!ou>,<},<}u!!!!!>{!!,!>,,<>}},{{{{!>},">},!i"!>,<"i}!>!>!>a>}}},{{{{,!>e!!>},{},{{{},{}},{}}},{{{},<>,<"'<}},{{"iaa,a>}}},{{{}},{{}},{}}},{{{},{}},{{}},{{{{<},<{a!!!>!!!>}ua!!!!!>a>},{ae!!!>'>}},{<>}},{{},,<>,<{,"ea>}},{,{{},<}!!{!>},},!>,<{!>},,}}}},{{,<>}},{{{,},{},{!>'!!u!!!!'!>,,},<},!!!!'>}},{},{{{{<},},{<}{!>},,"''!!!>ao!!!>ue>,,<,,}o!!ea}>}},{{eo,a!>!>},<},<"!u!{i!!!!e!>,<,!!u>},<{}>}}}}}},{{{}}}},{{{<,au'!>},,},<>,},<{!!!>!>!!o'"!>!,"}!">}},{{!>!!!>",!!!!!!!!!!!},<>,{>}},{{{}}},{{i!!!>!>},!>e!!!>,},},{}}},{{<>},{{"!>,<'!!!>,!>},<},,<>},<o<"!!!!e}}!!!!}!!!>!!">},{{<,e>,i{},<}!!!>>},{{<"e""!}u"!!!>!>,},{!>},'!!e!!!>!>,,<{iau!>},,{u{e!!"}u!!}},{}}}},{{{{{},<>,{}"!!!>},!!!!!>!!!>},!>,}}}},{{{{<{i!!uu',",u>},,<"!!,i,!!a!>!!o!>,},<>},<,o!!!>o!>o>},{},{<'u!>,,{!>},},{'>}}}},{{{},<,!>>,{<""a'oa!>,<>,{},<>}}},{,!!!>,<>}},{{{!!!>a!!!o!!!>!!'e!>,<}o{!>},,<,'>},oa!>,},{},<>}},{}},{{{{<,{!!o!>i>}},{,<,"o!>},}},{,'>,},<},"!!!!o},{}}}},{{{{{},ua,!>o"}e!>},},{{<,!!!>!!!>,,<},{a{i!>},}}},{{{<>,{,},<>}},{{}}},{{{<>}},{{<'!>,},<",!!o}}{!>},>},{{{{<'}!!!>,{a>},{}},{o'!u"!!!>,!a!!!>>}},{{<'!!!>,<'"}>}},{}},{{e,o,{<<">}},{},{{{},{{<{e!!!>{!!!>},<"!"!!!>!>},<>},{{>}}},{{{<'!>},<,!!e>}}}}}},{{{{!>,<",!>,,{{<}!>,<!>},<,'{,}!>{uiu,!!i">},u>}},{{!!!!!!!!!>ae}'"!ua,>},<}!>},}}ui!}u>},{{},{}}}},{{},{,o!!!!o'!!!!!>{u!>,},<'i,!!}}}},{{{i>}},{{{{{}e,""!{!!!!""!>!!!>ea>}}},,!!!>!,<}>},{{<'!!!'!>ee!>,<>,},<""!!!>},,e>}},{},'"!!!>!!},},<>}}},{{{{{},,,},},<<<>}},{!>},<,,<'},},oe,!!<>}},{{{{,'a!!!>,},{<'!>},,!>},}}},{{},,{{{},}},},},<<!"e!>},<}i>}}},{<{>,{},,<}{a!>,},,{!>,}}}},{{<'!<},{{<<"}'!>},<},{>}},{{{},{{,,<}!>!!!>e!!{>}}},{},{{,},},iaeo>},{{{{,<<'o!>,},<'i!!!>},<">},{}},<,>},{{},},<>,{}},{},!>},<{!!!>i!>ao!>i>}},{{}}},{e<{o"!!!!!>'>,{}}}}},{{{{},},<>},iauiui!>},<>},{,>}}}}},{{{},{}eoei!!!>u!>},">,{{{},<}!>},!!ie!,!!!i!oi!!!>},>}}}}},{{<}!!e!iieu!!'>},{{,>,<}o!!!>>}},{{!!u!!!>>}}},{{},<},<},,!!!<'u,!!o!!i,{,<}!>,!>,!!!>!!!!}u"}i>}},{{{{<{e!>,},{{{{<>},{<"e!>},}}},,<,}!!!>!!!!!>,}}},{},{{},{!!!!!!!>,o!'!>,<>,!>,<{!!e!!,!>!!e!>,i!!<{>},{}}}},{{{}},{{{!>!!!!!!"!!!!>}},{},{!!!!!>'oaii!!!>e!>,!!!>o!>},a>,'!!i}u'{e!'!>e!>'!}!!>}},{{!>},}'!!!>>,{}}}}}},{{{{{},{{<}u!!!!i}}}},{{{ioe!!>,<''!!'e}!>>},{}},{{<'!,o>},{{}}},{{}}},{{{{{},",},{{{},{}},{{!>,<",},{}a!>ae!!!>o!!u!!"e!!<'o{>,},<{>}},{{{<{}eeoua!!!>},}},{!!}!!!!!>!u>},{{{!>,<'a!>}!>!!<,u"!>!,{e<>},{{u"'>,},}}},{<,eo'}o!'{>,i!!a"!!!>!>},<}!a!!!>!!!!!>,}}}}},{{{u!!o'!!}!!!!!>!!!>>},},},{{<,!>!i!!,},!>,},<>,<<"e!>!>!>,,o!>,},},{{}}},{}}},{{{{},{},{<"!"<"!,!!!!!>eau!>,<,>}}}},{{{{{{}},,!>,!!!>!!!>!<<<>},{,{!>"i!o,!!{!>},}},{<"ia,i>,<'!>ioi!>},<>}},{{{<>},},{},{{,<'u,>}}}},{{{,},<,!>,<,i!>>},{{{<},}!!",!>!!!><>}}},{{},{{{},!!a>},{{},{}}},<}a!!!,'a',!>u>},{{ia{!!o!!!>},,},"!>,},{,!!,!>,!>>,{<}i>}},{{},{{<''!!e},e{!e>}}}}}},{{{{{<"u!>!!!!>,},<}!>},i!}'>}}},{{{{{{<,,!eaa!u!!oie!<,!!!>!>},,{u{!!i>},{<",{}}},{{},{},<'!!!!,!!!>!!",>}}},{}}}},{{{},{<{!!!>,,!!e!>,a"!u!!!!e!>,<{!!!!!',<>}},{{},{<"!,!>},<{a!>},<}}>}},{{<}!!"!>,<}!!i""'!!!>{>,},,<{!u!!'},{{{{{}},{!'u>,{<'u!!!>,,{>}}},{{"!!!>'}e!>,<}>},,<}{!!!>!!!!"!"!>!!!!,}<<>}}}}}}},{{{},{{{{<,!!!>,!>},,},<>}}},{},<>}},{}},{},{},{{},{{},!!!>,>,{}},{},{{{},<,>},{<!!!!o>,{u!>},<,!!!!oo!!!>!!u"!>}!>,<>}},{}}},{}}}},{{{{{{<i!>!oi}oeuu>},{{<,{!>!>!!!>!!!>},!!!>!!!>!!,'!},o!}>}}},{{a!!iu{!e>},{{{<{!!{!!o!,!!!>>},{},},<"oi!"!!!>!>},<>}},{},},{,},>,}},{{},{{{},{}},{{!!!!!!{!"{e}e!!,!>ae!!'},!>},},<>}}}}},{{},<>},{!><,!!!>},}}},{{<{},<'i!"{!>},,,,<{,!{},!>e!!!!!!!>!","ua!}!!<'!!u'>},{{{{!>,},},<'}o,<>},{<'!a!!{"u!e!>,<>}},{!!i!{{o!!!!!>,,},<,!!}>},{{{{,i""{!!!>},,{}},{{,o!>}"!!o,!!>},{},<"u}!>"!ae!{!<>}},{{,},{u>}}},{{},{}}},{!!!><",{}!>ee!>,}}}}},{{{},!!o!!!!{{!!!>!>"a!>!!!!!!>},!!!!!>!!!>e>},{{}!!{ie,!!!!},<,}>,i!>,<,!!"!>},<}!>o!"oo'o!>},<>},{{<{{!!!>ua'ei'!!<>},{}}}}},{{{{{{}}}}},{{},{{iu'!>>}},{{},},,<>},{}}},{{{{{<}},<"}'!oe!>,,},<{o<}},{},<>,<>}},{{}},{{{{!>},<'i<"!",>}},{,!!i!",!>,},{{"{aia!!!>,}}},{{},},<,,!!}'!!!!ae"!>,<"i!>,,{{{<,!{o},,!oi!!!>!u<'"e!!,{i>}},{}}a!,o!!a!{a>}}},{}},{{{<{!>,,<}{!!!>!!!>,,},{,,!>},!!!>e,>,{},!>,,},,,,>,{}}}},{{},i!>,<>},{{{{{},{!!"'{!!,'}>}},{{},{}}},{{<'a"!>e!>},<',>},!>,,<,,eu!!!>!!u!>,<>},{{{{<,!},<{!!!>},<{}e>}},{}},{{{{"o{uu!>},<>},},!!!'!!i!>!"a!!}!>,<"'!'!>>},<{!!!>,a!!!!{""!>"!!"'u!!!!!>>}}}},{{,},<'!!"!"!>>},{}!>!>},<}}"ao!!!!ua!!{!><">},{{!>},,<{!>!><>}}}}}}},{{{{<'}u!>,<{!!,}!>},<'!"'{!>},>}}},{{{<{a!!!>u!>!>!!!>ae}!>!>},<{!!ua>},{{}}},{{<,!!!>},!!!>>},{<}!!!uu{,!!!!i!>},<{!!!>},}},{{!!!>a!!}!!>},{{{{}},{,,{a!>a>,<,,"!!a!!>}},{!>},oa!!{!!!>a}a!!{>},{{},,{,,o!!e!>,>}},{<,!>},<"{}}}"},,,<},<>,{}},{},<}!!!ea{!!!>,<'uui>,!>,,<>}}}}}},{{{{{{{}},{<,!>},},,<>}},{},{!>!!!>ii!>!'"},},!!>}},{{{{{<,,!i,,ae{!!!,!>!!!>},}>,{{<}!!!>!!!>'!!!>"!{{!>!!!>>}}},{,<{oia}ueue!!!>eai>}},{{},!!!!!!ei!io}!!!>!!ue>},{<}!!!>!>i}!!!>,u!>,!>,<"o!>,,},,<>}}},{{eo,o!'!!!>'}}},{{{{{!>,!!!!!>}>}},!>'}}!!!>!>!>,!u>},{,},<'''!>},<">}},{<<,iiu!'iu!><>,{<,!!{e!!!>o!ai'!!'!!!!{a!>>}},{{},<,i{!>"}>},<'!!!>u'ao!!}},{{{,<'{"a'!>,},>,},{}},{{<'!,e!>},},{},{{{<,,},a{>},{{},'!u!>,<>},<}!!!!eai!!!>,!>!!!!!>>}},{!!a{oo,i>}}},{{{}},{},{,<{'a!!'a!!!>{},}}},{{{},,!!'>},{{},,<{!>},<,>}},{<",!>,<'!>,!!u!!{'{!>},<}!!{!oa!!!!e'!>>,{,},,,<{!>!!!!!!!>>}},{{<>},{{,!>,<>}}}}},{{{{{{<>}},},,<,!>},<>},{{},<>},{{<',!,ioe!>u>,{}o!>},<}>}},{{<{a'e,i!>"u>},{{{},,i,eo!!!!!>},>},{}}}}}}},{},{{},{{{{{},{,}}},{{<>},{{{},<>}},<!>!!"{,uei!>},<}>}},{o'}!!a!!o!eu>}},{<>,>},{,!,u!!}'!{ee!!i!>,!!!>!>>}}}},{{},{,!!,}o{>},{,<>,!!a!>!!!>u!>,},,,},}}},{{{},,{}},{}},{}},{{{{<,e!!,!>,},<,!!!>a!,!!'ie!>,},<>},{{},,!e!!!>!!!e"}uu!>},},{{},{{{,},!!!>e'u!!!>o!!u!>},<}>},{}}}},{{{,<{'!!i!>,<>},{{}}},{}}},{{<>,<,,>},<{>}},{,,<,o'!!!!!!!>"a!!eeu!o,!>},},{{},},{}}},{{,<'o>},{{},{}}}},{{{{},<>},{<{!>},'e>,{{}}}},{{{{{{,,,>},{}},{}},{{},<',i!!"<>}},{{{,},!!!>{!>},},{}},{{}'iou!{u!!!!!!}!u,{<{!!'oa}!!!>!!!!,ii!>,}},{{{<{a}o}!,!!!!!>,<'}{>}},{{{!!i"eeeuo!>},<!!!!!>!>,<>},<{!!'>},,<<}},{{<'!>ao!{u!!!>"!i{}i'u,},>,{!!iuee!!!>'!!!>,<>}},!>},,,'e'a}},{{{o}i!>!!u}>}}}}},{{{o!>,,<>,{}},<}}"!>,,>}},{{<>,!>'!!!>!>!>,},{<}}!!!>!!!>!!!>},!!{!{!!}o!}>,<}i!!"!!!>,<,,!!!!!>>},{{'!!}!!!>!!!!!>>}}}}},{{{}},{{{{,}},}}}},{{{},{{{{!>}uieo!!!>!>,<"o>},<}!>}!>,<>}},{{',},},},{}}},{{"o!!!>!!!>",e">,<{}i!!!>!!!,!!u!!,"}!>,,},{},{{{{a!}e!!e"!>},},{{<"a""!>},}!>},<}'!!u!!!!!>!>},<>}}},{{},<}>},{{},<<{"!!!!ui!!{>},<"!iui!!!>!!!>'"!!!!,!!o''!>},<}u!!!>{>}},{{},{}}}}},{{<"o!>},<,!}!!!>",{,}},{{},{{<<}!!o!{!i,,!>},!>},,<>},{,}},{},<<<,>,{{{{!!'u!>,},,<>}},!!>}}},{}},{{},<,!>ei'!e!!!>},'aui>,{}}},{{{{{,<"oia!!e!!!>!!{!!u!>,<>,},{o!o{>}},{<',!!{",<>,{!>},<''!!!>>}},{{}}},{{{},{{{!!!!!!a,e!',!!!>u"i!,i!e>},{{<{<}>},{,{>}}},{{},{,>},{}},{{{{!>,,{!>},ii!!!>u!!oa}}"">}},{,<>}},{,{{>}}},{,<{!>},!!!!>,{{<,{{"!>},<,u!>!>},<}'{!!!ao>},{},<>}}}}}},{{{{<{o'oi!>,},},},{,,>}}},{{{,},},<,,{!>},u!>,,,,<'!>,},,},{{,<"!>},!!aa!!o'!>},},<>,{{}}}}},{{{<!>i!>,<"''!>!!}>,{<,,!!!!!>},<"!>!!!!!>,}}}},{{},,{<}!>,<}'e!!"},<>}},{{},<{!!!>!!!>,oa"!>,<}''!!!>,}},{},!!!!>,{},<{a"u}!>},,}}},{}},{{{}},{{<"!>},},>},>},{{},{!>,"!!!>o>}}},{{{},,,<,"a!>,,},{{{}}}},{{},{{{{<}}}!!!!!>,},{}},{!!!!!>!a!!!>!!,},<,},{{},<>}},{{a<{!!!!'}!>oi!!,{{{{}}a"!!,"!!!>!>,a'!!e>,{<>,{<{ue!!!!!>!!}!!!>o>,{,}!>!!>},!>},},<}<'>}}}}},},{}}},{<>},{}i>}},{{},{<}!>,},<<">,{>},{{{<'>},<>}}},{{{,}},{},{{{<'u}>}},{<}i!>},<}!}!>i<>}}}},{{{{<>},{},<"!!e}u!!!>},<'!!>,{{,,<'!>,<,}!!!!!{!>a!!!!ea>}}},{{,<},<{ao}>},<>}},{{{{,<>},{<}}},{<,u!>},,<}i>}},{{,<,!!!>o!>!>},<"{oa>,{{,,!{!>},<"}i!!!o!!!>>}}},{<,o!!!i!a{,>}}}},{{>,!>},}},{{{},,},,{<"!!!>!>,<>}}},{{},{},<,<,!a!>,,},<"!!!>{>}}},{{},!>},<>},{{{{!'!!!!!>e!>},},,!!'!!!!,i!>o!!!!!>{!'"u}>}},{{},{{{{!!!>>}},!{}a!!!!!>},},{},{<>,<{!>i"uo}o!!"!!{>}}}}}}},{{{{<,e!!}">},},,,<'!>},<!!>},{{},{}}},{{<,<{},{{},{<},<}a!!{!><>,{!>},<,oai!>!>},}}},{{<"u!>,<},,!!e!{!>},}}},{{<}!!},,,!>},},},<>},{"a'!!}!!{"{>,{{,<'>},{,,<"u!>,<{'">}}}}},{{!!!!!>'!!,}!>>,{{{}},,!!!>!>"ii>}},{{{<'u!!!>!!!>,<>},}}}}},{{{{,}},{{{}},{{{,},!>,",'oe<>},{,{<','a!!!>a!!,{<}!!,!>},,a>}}},{{<}>}}},{{{},{"!>!!ou!}i!!oo!>},<'!!!!!>>}}}},{!!u}!>,!>i!!!!!!,"!!,!>},,{<}a'ua!>o!>},},}}},{,},'!!"!>,<>,{}}},{{{}}}}}},{{{<>,{}},{},<'>}},{},{{{{{{}},{{},,},<"!!i'"u}a!"e>}}},},{,!>},,{{}}},{{},,,,!>},}},{{{{},{<>}},!!!!!>!>,<'!!',ea'!!o!}}!!}>},{{a{!!,!!""oue{o"!>!!}>,{}},{}}},{{{},!>,!!">},{{{},,<,i}}}}}}}},{{{{{<"e}uu!!,!!i!!!>!>},<"!>>,{<}!!!>!>,},},o>}}},{{{{,{{{<,>},},,<}!!!>},},<{a>}}},{{ie}i}}},{u!e,e!!!!!>e"e!!!!!>ue{{!!"!>},},{{{<,!a!>!,!>},<,,e!!,!,},{{{!!!!!!>},'}!>,e'"o!>!>"{ou}}!!}>}}}},{{{,!!!>!>,i!>,,<}>,{}},{<>}},{{{,u'!o>},{<}!!e!!!>>}}},{{!>},<>}}},{{{},{{{{}}},<'!'a!<'{e,,!!{a'!!}>}},{<,>,!!>}}},{{{{},{<>},{{},<"!}{!!'{!!!}e"o!>,<}!>!}ou,!!<>}}},{{<<}!>},<>},{{!>,o,""eu!!'u!!i>}}},{{},,,},<',o,,{a!!!!o,<>},{{<'!>,,,<>},{}}}},{{{{}},{{<}!!e!!}!}}!!!>{{>}}},{{},{{{{{{"iu!>},{,{}}},{},{}},{{,,}},{},<{i!>},,{<,!eo!!}>}}},{{{{>},,,<{!,e{}aoo!!{{}>},{},},}},{{{},{}}}},{},,,{a!{{!!"!!!>,,{!!!>!!!""!>,a>}}}},{!>},},,},<"a"!!!>,!!!>>}},{{{},},{{!!!'!>},<{!>,,'!!!!o>},{{!!!>!>,<"!'!!!>!!!!{"a!!!>io},},<>}}},{{{!!!>},},,{,">}},{{!!a!>,},},u">}},{{{}},{,},<>,{{},!!!!{o}}!>},<>},{{}}}}}},{{{<"!!!>!>,},<,a!'}!!}!>},}}}}},{{{},{{u!>{!!i>},{{{!!!>},},o>},{}}},{{{!o!!!>!>!>},,}},{<{e!>"!>,!a!!!>,!!!>{,,<>}}}},{{{{{<}u>},,<>},{!>},<}{!!"oeu>}},{{<,"'u}!>!<{'o>,<{!!}!>,!!!!!!,!>,,"!>,},},<<>},{},<'!!!>!>!>},<}}},{{{<>},<>}}},{{{{,<}''!>},>},{<{!>u!eu{!!!>}'e>}},{<,{!e!!}!!!>,<,i>}},{},{}}},{{{{},{}},{{{}},{{<,<{!!a},},}}},{{},},{{,{},,},,>}},{}}}},{},{{{{},{<"!!e!!"!>},<"}!><{}"!>>,{{uo!!,o!!!!io!!!>'>}}},{{{}},{,,!!i!>e!>},}}},{}},{{},{{{},{""!>,!!!>i!>>}}},{{{,o!!!>o!>{,'u}!!u',!>},<}>}},{}}}},{{{}},{{{<!!!>,>},<{i"},},},{{!>},<'>},},{,},<{iu}'!>}!!<'i>,},{>}},{<>,{}}}}},{{{},{{{},{{!!!>!!!>'>,<{,'!>!!}!>u<}!!,!!i!!!ei}>},>}}}},{{<'!!!>!!o!>,<}',!>o},,{,!>},<>}},{<{!!,!!{}},{{{{{!!!!e!!!>!>!>!!!>!>'>}},{}},{>,""!,!>},},!>{,!>'o>},{}},{{,{a,!}!>,iaa>}},{<>}},{{{}}}}},{{{{{!>},<{e>},{,,,>,{}}},{{},{{},<"uoaa!!,}>}}},{,,}},{{{!,!!u!!!>',<,!>!!>},{uo!!'ai{a!>>,{}},{{!!!>!>>}}},{{{{!>},}},},<,<'o!!!!,uiu>},{},!!!!!}'>},{}}},{{,!""!!!>,'!>},<{o!!}!o<>,{<"o!!"!!uu>}},{},{{}}},{{},{{{},<{!!!!,!>,<>,{}},{{{!>},<<<>}},{{}}},{{},!!ae!>,<>},,!>!>},<'i!!>},{u!<'>}},{{{!>,u"}!!"!!i!>!e,i!!{,>},>},{{}}},{{{{,i"i!!!>}!!"!!!!!>},},<">}},{!>},,<{!>,<,oe!!!>!>!>,>}}}},{{{{{,<{!!o>,{<{,!>e}!e!>,<>}},{},{},<,!>u,!>,ae'>,{},<'!!o!>},!>,},<'i{!!o>}}},{{{<"!!{}"!!,,!>},,{<>,{}}}},{{},>}},{{e!!!>},,i!>!>},u}!!e>},{a'i!!au!{u!>},},}}}}},{{{{{},,},a!>},<}>}},{{,<'!!!>},u>},{{!!!!!!!!!!!>!>},,{o'>}}}}},{{{<'!!!>!>o{""},!>},<{>},{!!u!>},},"u!>"!}!>{a!!!>},<}>},{{},}"i{>,{}},{{{,<,o!!!>,}},{a<>}},{!!{}!!<{}!>!>,}}},{{{}}},{o"u!{u"{!>,<'!!!!!>!>!>},<>,!!,i!>!>},a>}},{{<,>,{}},{{>},{{{}},}}}},{{},{{ai!>,u!!!>,,,{}}},{},{{{{u!>,,<}a!!,!>},,<>},{}},{,{!>!>},},<{a>,o!>!!{e!>,<}!!!>>}},{},{{{<>}},{{{e!>oi!>,<>}},{}}}}},{{{{{{{{},},,},,!>ie"ae>},{,!!!>,>}},,<,!!!>e!!,!>,},,},{{!!}"e}{!oe!'}!>!>a,>},{},<>}},{,'''!{!!!>'!!!!!>"!>},}},{,!eo>,{{{,,!!!>!>!>,,<>},e!a}ao!i!>aau,!!!!!>e>},{>,{}}}}},{},{{},{!!{,!>!!u}!!!>,<>}}}}}},{{{},{{{}}},{}},{{{{,<'!i>},<{aa!>,<},<a!>>},{{<},},<{!!eea!>,<>},{}},{},<"eo!!!!o,a!!"u!!>}},{{{<}}!>,},},{,!>!'e<<!>,<>}},{<}},'!>e!!!>!!!>!a},e}!>},>},{<,e>,{,o!!i!>"!>>,{<'}o!!u!>},<},,}}}},{{{{{{!>},<"io>}},{<'!e{!>!>},,,}}},,},<'i!!!>i{>},{{{{,},},!!!>!>},}}}},{{{{},{{},!o!>},,<'"e<}!!>}},{{}}},{{<{,!!!,!!!>},<"!>!!!>},"'"'!!!>!!!>!>,<>}},{{},{}}}}}},{{{{,<'{u"u>},{},<{!>},ii!>},"a}}},{{{{{}},{<"i!!{>,{{{},}},!!""!>a!>},<"oa>}},{{},{,<<},!!u,,!!!>!!!!,!!!{',{!>,},{{<},<}"">,,">},{}}}},{{{<{{!!"!>},<""{!o!>},,!>i!!!>!>,<}>},{,{},,,<>}}},ie>},{,!>},,{},i{>}}},{{!}!>a'>,{{<"a}'eo!!!>,!!!>,<{",!>!>>}}},{},{!!}>,{}}},{{{{{},{{}}},{{}},{{{{>},<}ao!!,'!!u!>,<'}{!!!>o!>},<},{{},},!i!>},<!!!!!>!>,<>}},{{{{},{}},{,<"!!e!!!!!>,'!!}>}},{!>,<>}}},{},{{<,>},{{},{{}}}}}}},{{},{{<,{e!>},}}},{{{{<{!>},<>,{<}"!>!>,,},}}},{u<>,{}}},{{<'oa!>},<>},!>,,!>},>}},{{,o!!oe!!{!>,<"e!!!>!>>}}}},{{{},},<}!!a!!!>e!!,!!!>,!!!>!>},<},<>},{!>},,<,<>,{{<'''>}}},{{{o'!>i{!>},},},{{},{{<>},{{{<",},!!!!o!>},,},{<}!!,!>ii,}}}}},{{,!>},,<>,,!i!>},<'i>},{<!eiu}!>,},},<>}}},{{}},{{},>},{,"!!!!!>!i!!!>!>!><{ae!!!>o!>},<>}}}},{{{}!!!>u"o''"!ai!>,,{{!!!!,!>},<{!>,{},<'i!<'>},{>}}},,i>},{{!!!>"!>},a>}}}},{{{{{,,<'!>,<,<">},,},,!!o!!o!!!!o!!!!>},{{<'u!>a!>,<>},!i<}aouu'<,>},{{{"!!!>,}ea!!}!>!>,!>!ai}!!}>},{{{},}},{<,!!!!!!!><>}},{{},<'e>,,!i,!!!>ea>},{{<,>,o!u,i!>u!!!!u!!!!!!!>},<}{!!>}},{{<}!>,,>}}}},{},{,<},,}}},{{{},},,!>!!!!"{>}},{}},{{{<e!ooa!!!>},<",!>},},{<}}u{!!"!>},<"!!o!!!>,u!!a!!!>},<>}},{{},'{"!>},<}!>,"e>},{{},<>,{!!u>}},{},,!!i!>,}},!!!!e",>},{{<}!!!>!>},,{{<"ou!!{{!>,<''euu>}}},{{},{}}}}}},{{{{,,,'!!>}},{{,{<{}oe}!o!>!!!!>}},{{}},{{<,<{{,!!!>},<'e!!!!!!,!!!>!!!!!!!!>}}}},{{},{{}},{{},<}!>,},}}},{{{<<}o!!!>!}!}>},<"i"ei<}!!!!ae,!>,!!u>},{{{"{o!!!>!!!>ii!!!!!}!!"!!u!!!>,e!!<>},{'ou!'""!"i!!!>,>}},,<},<"!>,<>}},{{}}}}},{{{{{},<'e!!'>},{{!e,!>},<,'!>},!!!>},<,!!a,ie!!o!>},,{!!!!!>!>},!!oi>}},{o!!!>e!>,,,!!a"!!,{a,>}}},{{a!!!!!>!!!>>},{{{}!ueae!>!>{o!!!!!>!!"!!!>!>!ua>}},}>}},{{{{<'u,!e!{"!!{!!{"''"a}{u!}>},,},},},},}},{{{,ui!!!>!>}i},{{{,},<"!,'!!!!aa'!!!!,>}},{!>},{!!!!">}}},{{<'u!!{!}{>,,<}e}!>},<>}},{!>,,{<>}}},{{<{!>},,<,>},{{{},{},<{u!>,<'au>}},{{<{a!o,!!{{"!>!!!>!>},<'{'<>}}}},{}},{{{{{!>,<<'ei!,!!!>iu!>e!!!>!!>}},,},,!!!>},},{{},{!>!}},{{{},{},{<}"!>,!!}'!>},!!!>i!!>,{<},ei!!!>!>,}}},{}}}}},{{{<}>},{eu>,{!!!>},o"u!!>,<}!!!>i!!!!!!!>!>},}},{{},{<'e'!>!>},!!i!!!>!!!!"{<}>}}},{{,<{i>,{{"!!!>>}}},{{,,!!!>"!},,e>}},{{{{,<>},{,}},!>,<u>},{},{{{,,<,!>,,<>},{}},{}}}},{{{{<>},{,{{{o!>},<}e}a"{e!!!>,,},<>}}}}}},{{{<,!{>}},{}},{}}}},{{{{},{{<!!!!!!!>!>},},},<,!!!>'!!!!!>,!!!>''">,{{},{<{}{'!>>}}}},{}},{{{}},{{{<>}},{},<>}}},{},{{{{},{>}}},{{{},,},<{aoi'!!>}}}},{{{{{},{<'!>}!!!>,i!o!!!>i!!!>},<"!>,!>!!{!>,,,},{},!!e>,{<},!!!>!>,},!>!!>}}},{{'!!!>!!e!!!,'>}}},{{{}},{{{},<>},<}e!'i>},{{{ue!!!>},<{uu!!!>}!!{'>,{{!e!>,''!}",!a'>}}},{{"!!!>},<}{!!}>},{},},<},,,}}},{{,{<}i!!!>!>,!!,!!!>{>,},,e!>,}}}}},{!>,,u{eu!>},,}},{{{},<'!!'ii,"!!uu!>!'e>}}},{{{{,<,>},<>},{}}}},{{!!,!>},,{}},{{}}}},{{{<{!!'e!!!>!>},"o!!,!>},<>},{{},,<'!!!>a{!!,e!!!!!>a!>,!,<>}}},{{{o>,{,'a{!!!>,>}},{{{<,oiu{!!!!!!!>},},{<}}}},{},<""!!!>!>,<,ooe!!{!!!>},,<>}},{{<>},{},{{{,,!>},<,>},{},!!<'u>}},{{},<>}}},{{,,},i"!!!!{!!!!}ao!>},<}!!'i!!!!!!>},{{},a!"!!u!!"a!!e>},,,<}!!e!>},},},{{!!!>}}!!!!!>i!>},},<">,<{!!u!!,a'o{!>,},{{<,<{>},{{{o!>!>e}i">},{{!>,<},},{,'!!}o!!!>!!!>a!>,<!!!!!!{!>>}}},<{},{},<}e'e{>}},{{<'!>,},!!!>oi'!!!>},<'o<>},{{{!>!!!>!>},},,},{}},{!!!>!>}},{},<<}!!aa"!>},<"!>}a{!>},!uo>}}}}}}},{{{{<{!}>},{{}},{}},{},{{<,!>"!!!>!>,},<}i!'u'!!!>!>!>},<{a>,{!!!>!>,!a",!>},},}},{<{u!>{,!>!!,o!i!!!>!!!!"uo"!>,},<,!i>}}},{{{<},,<,>,<,!!!!!>}o!>,!>,<"io!>},<}!',"!o>},{<}!!{'{!!!!<{!ai!!!>"!},{},,a!>,!>},},aa>,{},<}!!o'"i!!u<}a>}}},{{{{{<>},{<<}uoa,'!e!!e!!!>!{o!!!i>}}},{eou!!!>!a!!!ei}!{u!!!a!!!,,,}},{{,},{{{},{}}}}}},{{},{{{{<'!!e!i!>u!>},{!!uu"!>},,{}}},{{}}},{{,<'!>,,<,',!>,<>,{{{e}"!!i<>}},},!>},}},{<"!a',"a>}}},{{{<<,!>},,},<u>},{{{}},{o!>,!>,<>,<>},{}},{{},{<"!>,,{<>}}}},{{{<{!"!>i"!!}},{<>,}},{{{<{!!!>oe!'!!!!!>!>!>},,!!!e{a>}},{{<"!>,u!!,!>a{,{},,<,,'!,!o!>},}},},}!"'"o!!o!>}>},{'ue!!!>,<'ia}{!>},,<{o,<>}},{{{{{<>}},},!>},i>},{{},{{},<}{o!>,!!!>,!!!>!>,}}},{{{,a"!!i!>},},{}},{,!!!>{ue!e,!>,,,,<>}}},{{},>}}}}},{{{<,>,<{!>},<{!,{,>},{<!>!!!>a!>},,>,,o!!"!>a!!!>,!!!>>},{<{o{uuo<,o!!!>!!!>!!!>}>,{}}}},{{},{{{},{}},{{},},<>},},},a!!e!>i>}},{{{{{{{{{u!!!>!!!>!ui'{!>},<>}},{}},{}}},{>},{}},{{{{}},{{{<}uei!>},,,<>}},{{i!!!>},!>},},},,!!!>i!!!>oe}!o>},{{{!>,ee!!!a!>!!!>>}}}},{{!!<,{}}},{{{},i!!'!>!!!!!>!>,<">},{{<'!!!!!>u!>,!!o!>,<>}},{{},{}}},{{{{},{{{,}}},{,},<>}},{{{!!>}},{,!!{!>,<>}},{{{}},{{{{},<>},<{!!!>,},{{<{<<>},,!!e!!!>!>!!>}}},{{,},{{{<}!!!>!>,},}},{!>,<}aua}!>},<}!!!>!!!o'>,{<'",}"}>}}}}}},{{{},>},{{!>"'!!!<}!io!!!!u!!!>!>>}}},{}},{{}}}},{{{<>},{{>}},{{'>}}},{{{<{!!!>e!>!!!>e"!,}u>},{}>,'!"ae},{{,<"!>},},>},{}}},{{{{<>}},{e>,{{,<"!}'u!>,!"",!!!>>},{,},},,,!!!>>}}},{{<}'{!!a!!!>!!o!>!{!>},},{<{!!!>{>}}},{},{{{{{}},{{{},{}},{}>,{{<<},!>,<,ea!oi!!'a!!!"!!!>!>,u>},<>}}}},{{<>}},{{{{,<{!e!>,},{!>},<"!"o',ua'"!>},}},{},{{!!'u!e!>,<"!>,<>}},{{{!!"!"o!>!>,>},<,a},,>},{{}},{{{<}'!!!!!>},<}{>}}}}}},{{<}e{!!ieia"a!>!eeu!!i!>>,{"i>}},{{<'<,!'!!!>!>},,>},{{<"!ou>,!,!!>}}},{{<}u!o>},!>,}}},{{{!!!ii!!!>>},{},>,<"oi}"o'!>!'!>!u>},{{<!!"o!!i!!,e}{!!"i!!!><>},{}}}}},{{{{{},!>'>}},{{<'>},{<,!!eie!>},},!!!>'"!!!!>,ou<>},{{}}},{{{{!>},!}"}!>},<}!!u>,<"!>,<"!!"o!>},<>},{{}}}}}},{{{"!>!!!>oi{!!!!},!>"<}>},{{<}!!ee!>!!!!ea!!!!!!!><,!>>},,,iii{a}a!o>}},{,},'!!!>'!!!>},,{,,!{{,!{u!>,<}!!!!!!,>}},{}},{{{,<,}a!!o!e}!!!>>}},{{<'!>},!>a!>,'>}}},{{{{<}!>,},<>}},{<}!!!>!!!>!!e!>,}},{{<}"i,i{!>,<<,}!>}!},<!i>},{}}}},{{{,}}}},{{{<>},{}}},{{},{},{{{},{<'!ou{>}},!>!>},<{!>,}}},{{!!"!!!>!>,!!!>!>,<{u!!!>},"!!>}},{{{!},},},,<}>},{{{},{{'{a,o!!ii">}},{},<},!',,{{}}}},{},{{!>},<,!!!>}!>}!!ou!}ia'i>,},!>!>},,},},e">}},{<{!!auo!>,},<,<'!!!>ie}"u>}}},{{<>,{{}}},{{{{},>},{!>},<{!>},},<,!>},<'>}},{},{<"!!!!i!!{"o!!a}!o!!!>!>'>}}},{{,<>,{,,,!<,<">}},{<<'>}}}}}} diff --git a/2017/day/9/problem.txt b/2017/day/9/problem.txt new file mode 100644 index 0000000..be8f22e --- /dev/null +++ b/2017/day/9/problem.txt @@ -0,0 +1,46 @@ +--- Day 9: Stream Processing --- + +A large stream blocks your path. According to the locals, it's not safe to cross the stream at the moment because it's full of garbage. You look down at the stream; rather than water, you discover that it's a stream of characters. + +You sit for a while and record part of the stream (your puzzle input). The characters represent groups - sequences that begin with { and end with }. Within a group, there are zero or more other things, separated by commas: either another group or garbage. Since groups can contain other groups, a } only closes the most-recently-opened unclosed group - that is, they are nestable. Your puzzle input represents a single, large group which itself contains many smaller ones. + +Sometimes, instead of a group, you will find garbage. Garbage begins with < and ends with >. Between those angle brackets, almost any character can appear, including { and }. Within garbage, < has no special meaning. + +In a futile attempt to clean up the garbage, some program has canceled some of the characters within it using !: inside garbage, any character that comes after ! should be ignored, including <, >, and even another !. + +You don't see any characters that deviate from these rules. Outside garbage, you only find well-formed groups, and garbage always terminates according to the rules above. + +Here are some self-contained pieces of garbage: + + <>, empty garbage. + , garbage containing random characters. + <<<<>, because the extra < are ignored. + <{!>}>, because the first > is canceled. + , because the second ! is canceled, allowing the > to terminate the garbage. + >, because the second ! and the first > are canceled. + <{o"i!a,<{i, which ends at the first >. + +Here are some examples of whole streams and the number of groups they contain: + + {}, 1 group. + {{{}}}, 3 groups. + {{},{}}, also 3 groups. + {{{},{},{{}}}}, 6 groups. + {<{},{},{{}}>}, 1 group (which itself contains garbage). + {,,,}, 1 group. + {{},{},{},{}}, 5 groups. + {{},{},{},{}}, 2 groups (since all but the last > are canceled). + +Your goal is to find the total score for all groups in your input. Each group is assigned a score which is one more than the score of the group that immediately contains it. (The outermost group gets a score of 1.) + + {}, score of 1. + {{{}}}, score of 1 + 2 + 3 = 6. + {{},{}}, score of 1 + 2 + 2 = 5. + {{{},{},{{}}}}, score of 1 + 2 + 3 + 3 + 3 + 4 = 16. + {,,,}, score of 1. + {{},{},{},{}}, score of 1 + 2 + 2 + 2 + 2 = 9. + {{},{},{},{}}, score of 1 + 2 + 2 + 2 + 2 = 9. + {{},{},{},{}}, score of 1 + 2 = 3. + +What is the total score for all groups in your input? + diff --git a/2017/day/9/src/main.rs b/2017/day/9/src/main.rs new file mode 100644 index 0000000..cc9da92 --- /dev/null +++ b/2017/day/9/src/main.rs @@ -0,0 +1,125 @@ +use std::fs::File; +use std::io::{Read, BufReader}; +use std::char; + +#[derive(Debug, Copy, Clone)] +enum Flags { + InGarbage, + CancelNext, + CancelNextInGarbage, + Normal +} + +#[derive(Debug)] +struct State { + group_depth: usize, + flags: Flags, +} + +fn main() { + let file = File::open("input").expect("unable to open input file"); + let reader = BufReader::new(file); + + println!("{}", stream(reader)); +} + +fn stream(reader: R) -> usize where R: Read { + let mut state = State { group_depth: 0, flags: Flags::Normal }; + let mut score = 0; + + for byte in reader.bytes() { + state = match (state.flags, byte.ok().and_then(|b| char::from_u32(b as u32))) { + (Flags::CancelNext, _) => State { group_depth: state.group_depth, flags: Flags::Normal }, + (Flags::CancelNextInGarbage, _) => State { group_depth: state.group_depth, flags: Flags::InGarbage }, + (Flags::Normal, Some('{')) => State { group_depth: state.group_depth + 1, flags: Flags::Normal }, + (Flags::Normal, Some('}')) => { + score += state.group_depth; + State { group_depth: state.group_depth - 1, flags: Flags::Normal } + }, + (Flags::Normal, Some('<')) => State { group_depth: state.group_depth, flags: Flags::InGarbage }, + (Flags::InGarbage, Some('>')) => State { group_depth: state.group_depth, flags: Flags::Normal }, + (Flags::InGarbage, Some('!')) => State { group_depth: state.group_depth, flags: Flags::CancelNextInGarbage }, + (Flags::Normal, Some('!')) => State { group_depth: state.group_depth, flags: Flags::CancelNext }, + (_, Some(_)) => state, + (_, None) => panic!("error reading/converting byte") + }; + + // println!("{:?}", state); + } + + score +} + +// {}, score of 1. +#[test] +fn test_empty() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{}"); + assert_eq!(stream(cursor), 1); +} + +// {{{}}}, score of 1 + 2 + 3 = 6. +#[test] +fn test_empty_nested() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{{{}}}"); + assert_eq!(stream(cursor), 6); +} + +// {{},{}}, score of 1 + 2 + 2 = 5. +#[test] +fn test_empty_empty() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{{},{}}"); + assert_eq!(stream(cursor), 5); +} + +// {{{},{},{{}}}}, score of 1 + 2 + 3 + 3 + 3 + 4 = 16. +#[test] +fn test_empty_empty_nested_empty() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{{{},{},{{}}}}"); + assert_eq!(stream(cursor), 16); +} + +// {,,,}, score of 1. +#[test] +fn test_four_garbage() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{,,,}"); + assert_eq!(stream(cursor), 1); +} + +// {{},{},{},{}}, score of 1 + 2 + 2 + 2 + 2 = 9. +#[test] +fn test_groups_with_garbage() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{{},{},{},{}}"); + assert_eq!(stream(cursor), 9); +} + +// {{},{},{},{}}, score of 1 + 2 + 2 + 2 + 2 = 9. +#[test] +fn test_groups_with_cancellations() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{{},{},{},{}}"); + assert_eq!(stream(cursor), 9); +} + +// {{},{},{},{}}, score of 1 + 2 = 3. +#[test] +fn test_groups_with_garbage_exclamation() { + use std::io::Cursor; + + let cursor = Cursor::new(b"{{},{},{},{}}"); + assert_eq!(stream(cursor), 3); +} + +