From e33d3609a80e1131d79cb40e7b76c94fe6e632bd Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 6 Dec 2016 01:18:56 -0500 Subject: Day 6 (gross though) --- input/day06.txt | 546 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/bin/day06.rs | 95 ++++++++++ 2 files changed, 641 insertions(+) create mode 100644 input/day06.txt create mode 100644 src/bin/day06.rs diff --git a/input/day06.txt b/input/day06.txt new file mode 100644 index 0000000..d9d7b7e --- /dev/null +++ b/input/day06.txt @@ -0,0 +1,546 @@ +wxupppln +ducindyd +rhszlyfu +kouqvpue +nwntizie +feyhuurg +qlgzsmya +svwijujv +tcmsiuly +vyrnynvz +nmidjjxd +ciduttzr +nofnijfo +ghskpifp +yoyvsxct +aqwzgouh +ihhkdayn +lmwyapsl +nxkdwnoq +hdkcvjrr +ecxvdbeg +sfybsvuu +gygvlghh +ivokuftm +grolarfj +tgzpjlca +lojlcrks +bmxogggc +iablmcem +cractnta +mpdrqxea +bdvrqbky +zymlyyyk +dhengvth +vrvvfnoo +ibemygpu +yjetqqrc +yhvpkxxc +rqfzoakw +uihcznsn +blovcrpx +dkrfqpco +xytyahwu +corlghco +gisliobo +qifxxizh +uykqywcf +pfnpbllg +kqcmwcsf +jgfujsse +klmgeozq +gpzgmjfr +vievatyq +rkhlqzgy +ovtopmzu +ahjbkzaw +nvwfxfvb +nqzbysna +brexdapi +jvwutzmq +reoafhkr +aeharbyc +ymvjuqpn +odweptpx +mwfzfgrq +qnbgujqe +jdvavsiv +ufgsatep +utvtvndt +xyonbztr +ouyaeqni +epnaskiv +tqzwxasp +sxudjakj +ppbmajsr +spqcqqad +bulnhjfs +debyqzym +zledocps +hvtwwnim +wuvqjkmt +vixowhlc +synpjwrg +yprcuicv +wlbdrrhu +mhzvzeit +jfrtudaw +ntdgtxbf +mqvkbkha +avzhocnk +rvcnnzlb +ezhvbpxp +bgxeudlr +snncfbun +cceyydvf +ergghyiv +baywxxgm +rluoymdj +hjytmgxb +eivafblf +qotcsomv +zstlpdeo +imqwjhdd +kmlkbwnj +mquzlglq +lrasxxzn +afnrzblr +ljlrzwkv +wiiclwqv +tbammsoi +kitvjdiu +twxhwnvx +qwlrtrmz +nsabmidx +ysqxzaid +qtzxvuow +lpnzibay +fkyfkcwh +goaeengg +jcgyfqjd +avpldldh +lsefwwxg +cbnivbah +znidoakv +oiupmqhs +gzgzxwau +svimmpqp +czjofzkx +slvahvuj +hgghpwzi +qqytgtew +fcdzdijf +wfmyjjjg +oabukfam +bfpyjarh +opjjzuxp +dturiscs +ydzjxijm +ushhlffh +jrhbfhvn +ozjesxqs +psoazeho +czwpexgf +aubbucmc +fekhvfgp +blixqivh +dytoxjks +geipbnaw +fsygumdf +fnqhvkax +wueqmkxb +hjvpeuie +rirgrkxj +lhvunqnh +vxhcgtxy +ljiiqwhv +gmcdnvos +ziwsabrz +zdtgrffn +mwijrxpn +jpuxtkze +bbufxkvy +orbpbvyc +cwboyilk +nkjljrcy +ybdwckjk +iegfymei +pmocypny +tbvbuvrm +uovwjjpt +dzfpixwu +pywzrlzi +gckwatyi +jxapzmew +oeaiivqf +ejtsefkd +njxpqtwu +hgwcbrok +vmmgbadc +mssfzxhn +yhjfmfwu +iylhiddx +stjppdoy +tmtdnked +powalodl +orydpdet +wglrrtmz +cmhxagub +tzuntycz +cnfimria +egklaeoq +rqsjyvck +ixizedid +pbmrgvge +ggpasnuz +mmsxlhsg +iazvwofl +xdbigytq +hdubbpsh +yfuktmiv +qenfqhhq +dyknyhyr +tehlplwl +msxxytnl +mzzibilg +ekndtqhx +nrqgcebz +kxpoopht +uknlrvsq +tksvulfn +bzaerzkd +elzunecg +wqodfhhl +qarirobh +lbdihftv +jedokhkc +zoryeegh +hceufcgx +ivwexljx +tecynrtk +uludfkpg +ubnvcadx +tufdeiko +fhlgwysq +qkgecunv +nkhpoefm +vajmrmbj +mxbhzhij +zxknrpfa +izijmrgl +fhdecewz +nerazpwu +jpusqgni +cycyeavi +vdilxqje +ldsqnfam +dkqkfobn +ctlrvsbr +bkmfpzbe +fdklbgrf +cjjxzzlo +zjgotpci +jsekrolb +xudoqzpy +khzyxudb +pgfxhbwp +ghhqdkhc +bszyorop +qoctnrcu +zntexpro +yqtwijxo +ufgoduva +rfmvokel +izxdabdu +jjlcytsp +sqbzxmei +lbmfqhmk +iqugozxv +gqkerurs +obauqiol +vjiavpjg +xwifisoa +lgdsybve +ncktlbws +baaehiyx +kyxrplga +keeyjwjr +kfwsrsmy +obibcmpe +dvjjhtut +ocezenxs +vxswiuwj +moiacpci +tzougogf +jaldounz +jlsckwfb +dqnlxeua +aprfnbjb +btracexv +yirdccur +yilvotby +qjokslpd +tdxcpyrf +mebacfie +bxcgholo +zsjnmohj +rooztfuf +rowmbvgp +mneowyhw +qovodyoj +lgsoucpt +rnfupvcq +izgskidy +oxjjtsfm +hgdhcrzz +fbhkdukc +ofejcggd +fygdulih +qgycsnfp +yshnipvg +olwjdrxj +ijehiskz +anekcijz +ygsmtmun +nvytgoej +xxotdtic +eadmjgqy +mcnzfctc +nxcewnpp +ezsuldpm +aspbbhtr +absngjpy +bbjmxzvb +xdchcqbt +vskvdrmw +fbxwizhb +icmbajue +rqnbgeqq +friivchk +zwlqorza +tuuvdiqx +dvjyseai +zkixqvgt +qirzbtte +nwgtodef +hjgnilug +pmyrvary +pdoncpni +xdbuvkio +exdagchd +tmchwgzn +xgqriqne +hlnmloew +uqdjxgmt +ulaxldqc +kkaevjap +bxdqwdzt +soaclkqq +jqoqjwxw +vrlyksim +rapqania +adhkvmur +ryowhvbx +hcxtiwqk +jpikhedh +hdosvskq +vtskhlbv +xpykokqp +oxlenmhg +utjipbaw +xyqpsonc +frqgvezn +cijiklxw +xwsxtrcf +odareemq +derdtuxx +xopbgasq +kuzipuhf +eptbpoos +jtesgetv +vvqcxymr +wvmtuolf +avejonoy +wfwizbag +srplbnvs +gbkrhhsd +xupwhjjh +glztwxno +yyapmumi +hzcladvm +tqdyexyo +egsisfti +pjwrpcrl +zwigknsv +vnthscff +wnqggfbd +ihvysqha +wypfzkzu +cjjuwjef +yoraozqu +hrlphdth +vhyxlkdn +cgpzbsad +gfxnhjnj +kmthfrrc +ghgrjjud +bupqueob +nckvualr +qezqfqyo +fucsogtm +zcxhypdi +fxmjpddm +zsuvvyvt +klpsmvxe +aukywwyb +etbmrtvo +uxggmylj +qlptnyyb +awfxrlqk +qfiuksln +xmsuzsab +upzskbax +ejhlazkn +aspugswh +stfdbhna +kgnhzfwa +anbocatp +zsqfnlkl +mnkbtygk +muywfyze +vufematv +rjnravbb +qufwwqml +stgxdcrs +dotmpgqk +mpjgmlgn +nnbgfgbi +paqsvfuu +taqszxqw +lfemniuk +hnfqekvl +ddarkfez +iatzsfjg +gjbyfwoh +unebqbgq +eysosujo +smsklhaj +gczwketm +halhdycw +eccopazl +wjguoavc +nxffamig +qtaunyfg +cqvlyrhw +ktcnhgmy +srcwxxfe +wwjqduvj +jgwjrbct +persltzk +bijmwdsv +faqetgtt +mwpkdibg +kblrtgvk +iaxjyqaz +akvwlvkc +wngzqcmc +lzrmhunp +ibzpkhia +drqasqzz +ycmsgmot +tthiqsnt +pnmqmyyb +whbmhcaf +payffzst +vnmbdrfs +okftnixy +mlwwecbs +pxutbxdw +gbtjmosd +wlffksko +fidktsnm +ynkbzzyz +zrrcndqk +fppfsayu +sprbqnvy +dldjkbjf +pzkzptbg +hkfihnfz +vpqexioj +pgdarlwr +ywfhgmcy +xtcepwtx +pstjdxgc +subqgesj +rzcsmqcu +ecamlyqr +kmmtswus +ivasccbd +hftmycez +dcqnymdw +ruzghmqr +nkkgiamm +ysnwdqdi +amaezxgi +lgrdaimp +uwmrkqnl +trmrubbx +xonawvml +piynnxqn +fvrikggm +rindzfup +edoparoq +rfdnetab +oavtacxp +lwhqmzpk +ehcwrdru +ctgetlui +bctqhqlo +wrxxlmjk +uwhwjaps +jelhsowr +cbwowzwy +stqkyeqh +aypkelrt +comebmmj +geqllpks +sfdontwl +hppmvkyl +vuktowpp +ocoievzs +haxkfyjc +dhluejeb +wzixgwts +symyqsna +iuxrcerk +pzfqujow +urccnfyo +lwovilmr +lmpjjhwv +akobwxtn +tqbquptz +xkuzlhwz +waktkczt +kvyccfrb +wvhhelfl +vtujfdyl +lfhaepja +znlbuosa +jtmvruzq +dwzxsnpx +qhxmuwde +claqvmel +jjejbywd +zkxftxlw +zixnwvjk +mhsvljsj +fdyukgpx +kevizule +dkuyxtsm +rpondvew +xzwxowwe +uaqpjocu +xfysjhbz +kmcookjd +lkvcisxx +xsluniob \ No newline at end of file diff --git a/src/bin/day06.rs b/src/bin/day06.rs new file mode 100644 index 0000000..bdd9147 --- /dev/null +++ b/src/bin/day06.rs @@ -0,0 +1,95 @@ +use std::io::{self, Read}; + +struct Runs { + inner: I, + current: Option, + count: usize, +} + +impl From for Runs { + fn from(iter: I) -> Self { + Runs { + inner: iter, + current: None, + count: 0, + } + } +} + +// Gross. +impl> Iterator for Runs { + type Item = (T, usize); + + fn next(&mut self) -> Option<(T, usize)> { + for c in &mut self.inner { + match self.current { + None => { + self.current = Some(c); + self.count = 1; + }, + Some(r) if r == c => { + self.count += 1; + }, + Some(r) => { + self.current = Some(c); + let run = self.count; + self.count = 1; + return Some((r, run)); + }, + } + } + + self.current.take().map(|c| (c, self.count)) + } +} + +fn solve(input: &str) -> String { + let len = input.find('\n').unwrap_or(input.len()); + let mut columns = vec![Vec::new(); len]; + + for line in input.lines() { + for (i, c) in line.chars().enumerate() { + columns[i].push(c); + } + } + + columns.into_iter() + .map(|mut column| { + column.sort(); + Runs::from(column.into_iter()) + .max_by_key(|run| run.1) + .unwrap() + .0 + }) + .collect() +} + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + + println!("Part 1: {}", solve(&input)); +} + +#[test] +fn part1() { + let input = " +eedadn +drvtee +eandsr +raavrd +atevrs +tsrnev +sdttsa +rasrtv +nssdts +ntnada +svetve +tesnvt +vntsnd +vrdear +dvrsen +enarar +"; + assert_eq!("easter", solve(input.trim())); +} -- cgit 1.4.1