From c02550850331a9b3b8f70a722aabdd74c446ce84 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 9 Dec 2017 10:31:25 +0100 Subject: Day 9 --- 2017/9.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2017/9.in | 1 + 2 files changed, 44 insertions(+) create mode 100644 2017/9.c create mode 100644 2017/9.in diff --git a/2017/9.c b/2017/9.c new file mode 100644 index 0000000..3e30c16 --- /dev/null +++ b/2017/9.c @@ -0,0 +1,43 @@ +#include +#include + + +int main(void){ + freopen("9.in","r",stdin); + + int c; + int depth=0,score=0,removed=0; + bool garbage=false; + while((c=getchar())!=EOF){ + if(garbage){ + switch(c){ + case '!': + if(garbage)getchar(); + break; + case '>': + garbage=false; + break; + default: + if(garbage)removed++; + } + } else { + switch(c){ + case '{': + if(!garbage){ + depth++; + score+=depth; + } + break; + case '}': + if(!garbage)depth--; + break; + case '<': + garbage=true; + break; + } + } + } + + printf("%d\n",score); + printf("%d\n",removed); +} diff --git a/2017/9.in b/2017/9.in new file mode 100644 index 0000000..d89a1b0 --- /dev/null +++ b/2017/9.in @@ -0,0 +1 @@ +{{{{{},"oo},{{{}},{},<'>,{"u!!!>!!!>,<"!>,},<}!!}!!!>{>}},{{<"!>}}!'!!u!!!!e!!!>>}}}},{{{>}},{{{<{{!!,>},{},<>}}},{<,o!!!""a!>},},<<}>,{,},<"!!!>u>}}},{{{<}{!<{i!>>}},{{}},{{},,,!!,}}},{{},{{{}}},{{,{}}},{{,<{'}!!},a,!>!!!>{!!e>},{{,,<'e}!!!>!!!>e'!!u{>},<",'i!!!>{>},{},}}},{{{{{>}}}},{},{{{{{{},{{,<>}}},{,},}},{},{{a"!!!!!>},<>,{">}},{{{{},{,!!!>},},u"ae>},{},<'e!>>}},{},!>i,u>,{}},{<'>}},{{},!!!>>},},}}}},{{{{{}}},>},{}}},{{{{,<,,},,!>,<}}},{{},{}},{{},{},},uoa{,<>}}},{{<'!>},>}},{{{"}!!!>!>u<'i!!}'!!!>>},a{!{>}}}},{{{{<{i}e!>},<}!!,,!>},a!!!>!,{>,{{,<>},<{e!!!>"!!o!>,<'a!>},!>>}},{"!>,,,!!e>}},{}},{{{<}eue!a}{"{'''!>},<">},{}},{{}},{{},{{{}},{<'!!,ie"e!!!!!>">}}}}},{{{o!!!>eiee!>"!!!!!!ie>,!>!,!!u!!o!!!>!!!>,<'"!!u!!}u}<}!>,<}>},{},!>,<{}!>,,<>},{<>,<},<{>}},{{{},!!e!>u>,!>},},!!!!!!i,!io>},{{{}}}},{{<{,ii!!!>!>,{a!e>},{}}}}},{{{{{,!!!!a",!!,!>,!>,},{<"!>,}},{{},{{!!!>>},<>},{{{},{}},!!!>},,!>},!>}},{<<},,<'eoiua}'>,}},{{>,{{}!>!!a>},{{{"i!!ae,'>}}}}},{!>i!>,<}!>!u!<'o!>u!!!>!>e>,{}},{{{{},<{u,}""!o!>},,<>}},,,,eea,!!!>i,,ue,ie>},{}}},{{<'e",!!!>!>,'!>{i!,!!!>},<''!>>,},<}uu!>"a"}!!},,}o!!o"'>}}},{{{{},{}},{},{{{{<"uo!!!>!>,<"!>e,<',au'}>,{}},},"!!}a!!!>,u},{}},{},{{<}"!!e!>,<{!!!>!!,!e"!>},},,},{{i!!!>{},},}}}}},{},{{{{{{},},{}},{{{},{>}},{<}a"u!!"'!!,},<>},{<>,<}!>!>o}}!!o{!>},<>}}},{},a!!!>!>},}!>,<>,{<{!!e!>,<"!!u!!!>"!!!>!a!!a!>i>}},{{{},<}u!!!>!!!>!>},},<>}}}},{{<}!>,!!!!!!"},<>},,u!!!>,>},{{{}}}},{{{<,>}}},{{!>,<>}}}},{{{{>},{{<'i!!!!!>,,<}e,<'>},{}},{<{}},{{{},,<},<,!>,<<>},{}},{{,!>},!!!!!!o"{!>},<>},<,i{i!>,}},{{},{{},{{{{,}}},,,<"}i!!">}}},{{{},,{<}!!{{!>,,<>}}},{{},<,u!!o!!u>},{{<>},<'!>,},e!,e!!{>}}},{{{{<'ao>,{!!""!>!u!>,a!,{u!!i!!!!!>>}},{{{{},"'>}},<>}}},{{{{!>,<>}},{}}},{{{{iaui!,!!}>},},!>u>},{<"u{""u!,!!!>>}},{a!o''!u!>,},,<>,<}<,!!o!>},<}{}{!>},<{">},{{,!{e<"!!,!>,<">,{<'!},!!!>'a}">}},},},!>,<>}}},{{{{,<'!>,<>},,<,!"i!>},<}>},{{{>,{>}},{!!,<>}},{,<}<}!o{u>,{}}}},{{{}},{<"!>!ai!><'e!'!>!>>,{,!>!!ae!!'e!!!>e>}},{{,<>},,<{{aau!<{u>}},{{{{{},{!!!>u!!"""o{!>},,{<}!!>}}},{{<'}o,ie">}},{},,!!ia!>,<">,}},{{{{,},,},<}a!>},a>},!!,!!ie,!>o"!>,,},{{},{},<{a!!!>"{>}},{{,<"{!>i,!<>,<}}},{{},{>}},{{},{ii!!!>!!,>},{},<}>}}},{{!!u!>,"o<<}!>uu!!u{!!u!"!!!>>},{{o>},},<{au!!!>!>},},,},}}},{{},io!!!!i>}}}},{{{{{{},<>,<'e!a!!!o}}<"!!!>,"}!>a!!!>"e>},{{!!{"},,!>,aa>},{}},{!>},,<"{"!!!!!!!!!>>,{<"!!!i!>},}}},{{},{{{oe<{!!},{,<<'e!"!>!>},},<{!!o!>,!!u}!!e!!>}},{{<}o"!>},},!!},},}}},{{{{<'!,!!!!ii>,<!!!!!>!>},!!'!>,!!!>>},!>,ao!!!!!>!>},<<>}},{{{,a!>},>},!!>},{,<,>},{{<}!}!>,!!!>'!!a!>},<>}}},{<>}}},{{{{{,,},"!>},a!!!>!!!>!>!!,u!>>},{<<""!!,!>},<'{}}}}},{{{{<}!>,,!>},'i",!>},,<{!>,,},<>,{<!>,!>},<>,'!>,<{<,<>}},{{},{,!>!!!>!>},<,i{o!!!>"!!e!>,}}},{{},{{},,!!>},{}},{{{{<}'e,}>},<>},{{!>},<"!>},,<{>}},{{<>,<{{!ei'!>},<<{!>,!!">}}},{{,<{!!{}i!>,<{!>",!!!>!!!!!>!ou>,{{{{}}}}},{<{'!'<}}>,},{<{{a>}},{{{<>,},u!!!>'>},{{{},},<'!!!>o!>,,<{u!!{!"{!!!!!>>},{<,{!a>}},{{<}>},{,u'!>},!!!>>}}}},{{{},{,<},},,,<>}},{{{},{}},{},,},,!>},<>}},{<'a,!>,!!!>,<'!>,<<"u>}},{{"u!!!><'!!!>{>},{<'!>,<}>}},{{!!!!i,!>!!},<'!>},,{{!>!>!!!!"i>}}}},{{},},<}!!!>"!!e>,ia!>,"!>!!!>i!!!!!!u!eu"a!!,!>},<>},{<{o!>,<<"{!!!>!!o!>},>,{<ui!>},<'e!>,<>}},{<>,<',!>iaoi!u>}}},{{e"e!!!>},<,u!!e!>,,i!!oi<>}}},{{{},!!!>i!!!!e!!,"u>},{}},{{{},{{},{},}},{{<"o!>},},,},{}}}},{{{!ei!!{!!},{}},{{},{},},u<>}}}},{{{!!!>"!>!!ua>},{{{!">,{}!!!!!>!!a!!'!o',!!!!!>!!>}},{{{{,!>,!!i!!ea!!!>!!!>'>,{},,e},}}}}},{},{}}},{{{{{!{!>i}!"'!!!>iau!>},}},{},{}},{{{}}}}},{{{},{,},,auo!>">}},{{{}}}}}},{{{{{{!>},oe!!!!'!>},<"!!!>>},{!!"'!>,},,<>},{}}},{,,{{}}},{{},e>}}},{{,eu{"!!}a>}},{{{{!>},}},{{{,,,},!!!>!>,},,u,!>o}"!a>}},{'!!{eo'!>},!>,!!!>{,,!!!">,{<"ioau}'!!!!!!!>!!!>i">}}},{{{<{!!uo{i!>},<,}>}},},}}}}},{{{{{!!i>},<>},{{{},<{!!,!!a""i!!}{>}}},{{{},,,}!!!u"e!!!o>},{,},e,!>,oo>,{}},{<}}!>},!!!>!>},}},{{u{!!e>},{{},}>},{{{{},{}},{<"'!!!>!ae'a!!!!o!!!>a!}!>,<>}}}},{{o"i!!!>"!!!!!!!>!!!!!>},<}!!>},{}}},{{<'!>,"!!!>},},,<>},{e!>},}'>},{{<}"u!!!>!!,"i!>e>},<",u>}}}},{{{{,<{"!!a!>,<"ou!!,a!!!>},}},{{{{,!!!!eue{!>},,{<>}}},{oo!!u!>,!!!>,}},<"eo"!,!!!>>},{{}}},{{{<>}},{!!!>!>},<},<}o!!!>uui,"!!"i}>},{{!!<{eu!>,,{{{!!!u!!!!!>!o!>,},{,!"}o'!!!}},{<{e!!!>!!!},!>,<"">}}}}},{{{}}}}},{{{{<}!!!>eo!!!>a!e'>,{!">}},{{>},{,{},}!!<"u!!!>},<>}}}}},{{{<>}},{!!{},},{{},{},<}!>,e}!>u!{o{!>,,{{},,},{}}}}},{{{{}},{{!>!!{!>},<,>,{<}e,!!!>>}},{}},{{{<{!>,},,},{!>,!>,<'"!>!'!>!!i,>}}},{{{{{,,,{{>}}},{{{{},,}!>,>},{{{<,!!!>,}},{{{{},,,!!!!!>!!!>}},{}},{,<>}}},{{,{,aa!!u!!o!!{u>,{{{<{!!!>>}},>}},{<,!>},,!}"!>}!>},<"i!!!>>}}},{{u!>},,},!>},},,"!>!!e!>,<',!!>}}},{,}},{{<}!>},<}e}!!!>!ua'>},ooe,u'!!!'>}},{}},{{{o""'>,{,}},{<'!!!>,!<>}}},{{{<,o!>,},,<}a,!>}!>},,}},{<{{,!>,<>,{{}}}},{{{{{{},},''!!!,'o!{>}}},{,<{!!!!""!!!!!>'!!oa{{!>,},<>,{<",!!!>!!a!!!>},!!"ii,,{{<'!!!!!>!>},},,<"!!!>a'!!!!<'>}}}},{!!!>},<,u'u!>},,<<,!!!>oai>,{}},{{},}},{{},<{!'!>,!>{!!!!!>u!!'>}}},{{{<>},{"{o!!!>!!!>},}},{{{{{{<{!!a{<!!!>!!!>,!!!>>,<}"e,!oae''!>,},},<'>},<}!>,<<{a!!uo!>!>,,},<{>}},{{{<,"i!>,!!!>o!oa!>,},,}ao"{u!!!>'!!!>a>},{,<,i!>,},},<}!!!>u!>},,},!!!>},<{"!!!>,<u!>!!!>!>},},{{<{!>'!!<"!!!!>}}},{{<>},{{e!>,},}>},},{<'!!a!>},},{>}}},{},{},,}!!!!!>!>},<"!>},,<>}},{{{{}},{{{{}},{}},{{},{},a!!!!i!!,'!>},<}>,<"'!>'>},{}}},{{!"a!>,e,<,!!!>!>>}}},{{,"!>,<,,{}},{}},{}},{}}},{{{'au!!"{!>,<>,},{{{u!{'!o{'!!!>!!"!}!e"!>},}},<,!>,},{{{},{}!!!>u"!a,<,"{!>},,>}}}}},{{{}!!}!>,},<>,{<,!>},!!}}e"!}>}},{{{,{<u!>,<>}}},{{{u!>,,,<,}!"'"e>},<},}}},{{{u'uu<>}},{},{{},{!!!!u}iio!>>,{{{!>,<{!!!!!>,u!>a!>,},},!}!,ea>}}}},{{{{,,<>,{!>}!!o!!!>}},{,"!!!><>},{},,},<'!!>}},{,u{},{!{iie{!>},<,<>,{{!!}iu'!!!>e}!!!!o!>!!!>,<,,}}},{{<"i'{!i!>a!!{!>,},<>},{,}}},{,{}}},{{{},{<">}},{"!!!>i">},{{{{}}},{}}}}},{{{{}}},{{},{{,{}},{{},{{},e}{e>}},{{{<<,e'a!!!>},!!!!!>e>}},{{{},!>!>,!!!!!>}!>,>},}},{,}!!<}!!!!!>ae,,!{}}},{{{{},,,,<>},{<}!!!>>,},<}e!>,,<>}},{{{},{}},{},{}},{{{!""},{<},<'aau!>},,<}i'!>!!>}},{{,<{"!!!!!!!!!>,<}},{{<'i!!<>,,{!!{!!!!!!a{!>},<>}}},{{{},{{{{!>},<>},{{}}},{{{<''!!!>ai!!a!>!>,<>}}}}},{{,},<,!!,!}!>},<>,,<{!!!>!!io!e!>,,>},,}'{o!!,},!>!>},}}}},{{{{<,,!!i!>,o!>,<>},<}!!!>},,<}!!>},{{{,!!!>,e>}},{!!!>!!},!>,!!!>},<'!>,<>}},{,u!!!>i>,{<'u!!}oe!e!!">}}},{,!!!!!!ou}a>},{{},{},!,i">}}},{{{}}},{{!>},<>},{}}}},{{<,u'!{!!'!>!!!>}>},{{},{<,!!!!!>},}}}}},{{{{{,}}},{{,,,},<,>},{{{}},{<,<>},{{<<<,u!!",!"'!!!!!!,{}}}},{}}},{{{{o,!!!!!e!>,}},{{<>,{,<,!i!!!>""u!}}!!!>!}},{},<}{!!!>,}}},{{},{{},<,!>,,{,{,<}oo>}}},{!>,,<>}},{,{{{}}}}},{{<}u!a}!!!,!,"e>},{{<>},{{<"!>,,,!>"eu{i!!}!>},<,>},},!>"!!}},{{{,u!!'i>}},ii!!!>}{!><{!>e'!!!!!}{}!>!io!>>}},{{{<>},{!>!!!!!>,{u>}},{{<>},{}},{{!>,,<>},{}}}},{{{{<,!!!>i!>},<'!!!u!!!>i},}},{{i!'>},{{{{},{{}}},{!!}!>,},<,,<'>,{<'"i!!ae{o}!>!,a>}}},{,<}}'!o!><{>,{!>},<'a"a,!>},,{{}}}}},{<{i!!u!>},},!oo>,{!!'i'uo>}}},{}}}},{{{{{{{{!>,},<,i!o!>,<>},,oii,!>},<}}!}},{},{!!i!>e!>},!>},<>,{ii}",!!!e!>,}}},{<>},{{,},<{!,e'!!!>,!!iu>,o!!u,!>!>,,<"i!!e!},{'>}}},{{{{},{!!!>',oao}}},,,},>},{{}},{{!!!>"!>!!i!!!>!!!>i!e>,{<,,>,{}}}}},{{{{{uu>},{<>}},{},{{},{{<"e!!i,<"o!!!>,<}u>}},{{<>},{<>}}}},{{},{{,},!!,e{>},},<},{{}}},{{{},<,!!!>},},>},{{{a!>,<}e!!!>{>}},},<'u>},{{<,ua!!aoo}!!{!!!!!>!!"eau}}!>>},{}}}},{{}}},{{{}},{<,!u!>!>,,<''!!!>!>},<'a'!!aou!!!><>,}},{{{,},{,},,},!!!>""!>,}},{}},{{},{{{<{!i!!!!e},<>}},{!!!>'!!",e}u!>},,,<>,{<'e!}!!,,<"o!>>}}}},{{{},<{!!'u>},,<!!'!>!!!>,,,},{,,},,<,">},{<<{!>},<}'!!!!!!!>!!'!'o!,!!u>}},{{{"!u}!>,},<"u!>!!">},{}},{{},aa!>oa!!o!!!>!!},{}},{{},{!>},<>,{<'"!>!!!,u!!oo!>,<>}}},{{{},!>},<}!!!>a<"{a!!!>!!,>},<{>},{{,<"!!!>>}}}},{{<}eu}u!>},},}},{{{{{<},,<',{o"{'!!i>},{}},{},{{{<{!e,<'o{>},{!>},e!"{!>},<{!!'u!>},},{},<'>}}},{{},},<,au!!{>},{{{,<>}},{!!!!!>},,,},<>}}}}}},{{{!!u!!!>!>},},{},{u,!>,<}}!!!>,<>}},{{<}!>,<'>,{}},{!>!!oi!!!>"o"!!ie{>,{{,,<}!>},<}!>,"!>,!!!>!!!>},,}}}},{{{a!>},,<}!!!>},!>},}}}},{{{{<"!e"!!!>!>,!>,,<>}},{{},{}},{{'o,ia!>},},{,{<"'!>},<>}}}},{{{{}},{{,!>,},io>},<}!!!>,'}!>},<,!!!!aa>},{{},<}!!,o!i,!>,},<}<}!>e>,{<},<"!!<>}},{{{{},<}o!!"!>>,{},},<>}},,e!>,<'!!!!!>!!!>,>},},o!>,>},<,!!!>u>}}},{{{{},<{a!>a>},},,<"i!!!>i!ai<>}},{{{}}}}}}} -- cgit v1.2.3-70-g09d2