From 9b626fae46e2498be034b88e91cb560e8ee14465 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 6 Dec 2016 08:57:27 -0800 Subject: [PATCH] [2016][rust][6.0] --- 2016/input/day_06.txt | 598 ++++++++++++++++++++++++++++++++++++++++ 2016/rust/src/day_06.rs | 44 +++ 2016/rust/src/lib.rs | 1 + 2016/rust/src/main.rs | 2 +- 4 files changed, 644 insertions(+), 1 deletion(-) create mode 100644 2016/input/day_06.txt create mode 100644 2016/rust/src/day_06.rs diff --git a/2016/input/day_06.txt b/2016/input/day_06.txt new file mode 100644 index 0000000..291b1ed --- /dev/null +++ b/2016/input/day_06.txt @@ -0,0 +1,598 @@ +eqvmfqnf +jvkezmqt +zcssqwlw +cuacncgg +ikmpzpoh +dzpzobdl +qlsnuhuq +fwqnoklz +cibgplfq +ktsqfcrv +vcknjnnx +upaiaprz +bpqmolbq +dflhnpnk +heqjflch +cmewgodc +aaorgxkn +plekphpw +fcofrbnm +bmnrygtb +rqsqsqio +rnlntwxa +cxjqqfyl +jxjnxchb +kfgutxmi +cbciszxd +irakoonu +pcgfnycg +fgeivexo +ujxdaehw +ejkvrych +nhlklbgr +etjuhgry +mkgkmykm +teuhrfto +juqfslbn +tbwxabzi +ngdnwsey +amcibkyo +xlvxwqpj +vdbzuvkh +gkagbzep +kqxzkeip +bxccztho +vqrywqlc +jbzhecjc +ozkulgxo +uiwbofuk +vfwhdnao +tycxucwd +jvhuljfs +xxhqhruc +upnndiiz +andxywil +lowofbqv +iroqzrry +nmkkqqjb +daijrfna +jmcstxlq +jdefvuaa +nkbmowfi +agotazda +kufoymrn +yijwfjyi +hyqvaouj +soueuhln +oomsbkmh +buadtssf +rvgpeeza +hjiymcmd +ebgivdap +xzieipbg +ttpudwqt +hndwuncw +wqypfkvf +jqxuaipm +fzwlgxxq +ddshbtya +ardlcgyi +soznvuyw +vyizuolp +ckfaxyvs +nbsjkibi +lsrkrdzp +oqoffwxa +bdugjlsm +rtcsylfd +fezoiliq +zwpaphcb +sdlouhyf +cfejwvls +xehddxku +edhrtdcv +ehouagvy +hoyxjfsj +quggpnpx +muqbijbe +rcnniddd +kzfeiaui +sywienef +xpxftuvq +dtbhnslt +mpcpkmfa +wysutlci +fmqomicz +mhshprxr +uxwfcftt +ehbonsrl +pjobilxx +chiebfox +lqfxgyqg +vupcjatm +wfljafhc +iygojeny +gqxmgneu +nhlwllak +xnkqpulv +awijbvef +pbcrrwqo +dobsejtb +dqdoapkc +hngrxdtx +dodsxysb +bmtyelak +cctuwwvt +rytlmoyr +fqnbuxdi +irrqladc +wnvtsneg +ugqqdmlj +nljnjiod +knidxxzh +dfymoqgt +fwgtjafh +fpdioivz +tqbewmti +mcqtbbee +pivfrpou +tdyguuos +eldmvvmi +oaiqnizz +fyqpxgwa +lzcxsazq +zhsoljwz +qnzafmjl +oopnnndl +cozehoor +bspuwzxm +ubtunnep +smdhpvxr +nsvxiwje +mmqcklsm +hhxaciaq +zzgoxhws +fvntouun +skxzmzyg +znptwuqu +aknwvojo +wftmjrsf +gahrordj +oegnykag +lvlqswph +qsowvoem +sjspasfp +ygjohzfd +jeuxigsi +lgxdtudx +qadlkrel +lpfxosdq +sgaoqkzr +rtlvuhfv +ftbbsgbn +kjxttiqu +gylikswu +lquhgmrs +hxrjagjm +epxxekgx +uwwlcbrx +feincdjp +uyxhfhsc +nojuykoh +psjuuqwu +gtlohqkz +sbzsbgrw +nbhwuxfb +phmtunrh +zmfbkvgv +mjumfpia +gkubcshe +jmavrhyd +cgffkftg +msurhdct +bvchukal +psxaluvg +tvgwjhhp +chyizcxv +dumebzkd +cjpzbkzk +ngrgseyn +xmwcmaaz +puyrbiup +xxkpznis +rguwrpua +jmolhvnn +kpeqtlan +zzgvoxlp +erbintcn +kcykvysv +ixildajc +tnvgihwe +iqwgozpj +txkgyflb +vsyzebrw +ehnbcjef +hfevkbhf +wihlqtmp +vmrmnygo +ulvsuvsn +wgxnwihd +lexgbpsv +kxqcjoeb +daodpsbb +azyqmyhv +mvzcatwb +jtvqkjrv +rtdsaqqd +xrhzmnzl +wgfiwjrh +hgrgqqxm +nwwcxoyq +qlqyhpzs +ovujfily +pzvyeryk +strswprn +nrxclypc +sfusjxzi +pclbdadw +sjhggndb +xjcutuyt +qjjjeytj +qqjrkdlb +pyzodjdh +brnmlkmi +lgipidfp +ttrfbjry +iidwekro +vnwlnyma +ylxatduo +eiokdbqr +laezjjte +kkjhfsvp +buaegtpg +vzgqletc +pkdseade +nvpyxokq +yiysgxpe +xqhtubam +lcstpvke +nnskqssg +mkrbdovg +camkeppm +iqjvotay +bodlfgkj +jiigwvzc +ixpghywy +qlzyjgue +ugyjqtzn +odeuuiir +yfhianfx +seewayqj +lstpeuja +paqqnxsr +guwkidny +susussgu +ezcayehr +tdzgvcqf +vckcnsio +obawbapm +ipebazzk +tmcpmiou +hpdlfwor +ygxlfzzr +ltyxhtbx +olzqonbx +grsxreqs +bvkjcoux +fxtuxuub +fcbxdenm +smilcfvz +ewbndkiz +httsnfqu +ghorvefw +anevvqir +sajdzwho +becdemdn +vxktmxsj +xyawkeuw +pdefbxmh +yejymgfr +mipvhnsc +tjdyqpzd +rbvqirmd +mscuflvd +draqqcda +xfegqcjg +auypywpb +gitgzstq +zveqbzgt +wxrpedre +haptyecu +tkeexmhe +ujijprbd +xjiyczwq +ehpygnrr +guvejwyt +zmtsftky +wqtklwiz +lwlessio +lrknmhzd +pkdkwevt +ncryoeth +hjsqtpxu +ivmqrwok +qozgijgu +ueujvbbe +nfxgrmsd +zeetrgdl +drfbcgxo +rjjeraeb +hshozlgv +sfgvrnez +zaoctlsa +hebtzqvy +qckvuyif +wxyszmev +ddxfwklt +jqlzpfvu +wimoefwx +kabvtrno +pbebkvkm +govfwjof +xfjkvoup +fuzxcese +zbavvmyy +mwvkrnjg +gtkyelff +bffyzhnt +vlffqryw +ofncqcqw +cnzzrjjj +txpzvykz +ukkgeavq +wdnieioq +avosnedk +ipaavrqp +eeuurfat +sfhhwqzw +vjzopzad +kdbjonqz +uaksjfuc +lumpaomf +ysebmwel +dobryhxj +oaymjqwh +qjfflojj +zqmfgwre +uimjngfs +ihwelccg +yetrodjy +aifvwtws +xiyruzqr +anuvhykm +lelbjsno +csjwqotd +pptsysey +joptcdmq +tghbxpmq +jduwbxiy +obcdlahg +dxwrzytc +axfrxlgz +gepnmvel +ztmcynch +otnicgga +bdzobaoe +vkljxwnm +qvhmitgh +yflyxbjn +qshihqki +debaxqpw +fhfcjogj +huwpnaxx +jpwnrjbc +waylsrcm +aurdpcqc +yanpouht +ybwbpcak +uzvvspnj +tftluckv +uwmditoa +wsndxybi +dotcxasi +lxgmptwn +bpdmcbgt +dpjqvvck +jmgwudli +rimvxcoa +vdlacqbl +qtzwuqny +olzuzuuq +grlyyegi +mhgtadti +yrfdffzj +wbxadryy +bhaniozq +jdishqcx +kmiatkjj +asmxdrmv +riqdknna +fsuetmeg +iikajhgb +ioswsaws +yygpvtfb +egjoltik +bypcbzpk +zaumpggx +sdizezlv +xoyallwy +gicvajdl +qzowhuxa +iyftbzns +srzjxhve +xwasqzay +qznuxpqj +mlnjztxf +rxkcymao +huvxpllx +fmnrqasq +mwwigmka +yovjkmou +kvdrltte +nymvepew +vnrjykzc +unoegpvv +trrejbob +zwsdnqnb +ljsztmgl +tiznomfv +zxtxholt +csufzpiw +jgbjpucz +mpakkeil +ixmbvvbi +ejkhcxjj +zaokljpl +oeocaxdv +ytlpsbcx +hpfserxf +nzregysc +etevckof +bcqkqdvb +xzdhhick +gystpgoo +ciiyzxxr +kwstdxnn +ztregxhx +qhvkjoqe +ugirgwax +nhukpdut +yfiibmmd +cwkayjcp +ebmlabrp +kvjhyrag +wbphpfkc +ucqvhibs +dwuavsyy +jwrdsobl +hytijctt +plcumjhv +hwexsihm +ppmfzgqt +moumyuiw +zvgbsabj +yraygmws +vopzuhor +hafhljwp +gmqpchdg +yyahpihs +xvqakyyp +deamarun +yunihcvw +gcdjqqmu +kctibuxy +gcvlcfhc +ydwoxfvg +epszfvuh +xjjvwpbz +gzpdnthj +mnkrjgwz +ldfwvvfq +tydqesvl +envwzaqv +xvwyzkpe +rmpgcjeo +pkupgxup +ekqizsjl +agvenhgu +vscaqtri +rwfjrjpg +imthkcta +sjpmwqmg +fptfgekn +ohbwdbjm +ccfrphaj +gyeaqkog +onybscve +qztmoant +abjnbrpd +zompdzuf +bamomvbw +kzmmgexu +wzoxohtn +wvgmvwdt +nlgkxmbu +vyoddxyf +phmrizhk +zhksysjf +atcfvzlx +iyabqkly +rnwidjpm +cgwddumw +fcoylnzw +lsxosfra +vbcdgfiw +aenlmdgh +fvtmormn +rllxkznc +asocydmo +zcltimlr +hrqmccpt +dfmlsvtz +ntuhkbws +oziqleds +wkzbguis +coapfihl +irzpsuql +uxaowrls +tdbefhcf +wsyusuph +lpbdrmyn +slrzkkms +wqvzwiyq +vinahrsd +thsnmqjr +kwrzmakz +ifhclifl +wkqahikb +rwnchlkr +rkhpdbbk +vqnzigbf +olzziafs +qcylpbtk +fzhtmgji +qvnyctmb +ouolgwup +xkbrykjx +apbamszk +mlrlmpoh +kdneakuk +rrhhrtfk +cbgzlbgz +mfxencal +bkctqwpe +rjdxhqof +ogcbntmp +bbftqdfk +kikdidvm +mnjgwven +yurxwsge +qlrdtzad +jalffvnu +tayfycwr +jhivnvaw +yuvffepz +mwhczdkv +xltzklis +iellkyqk +krpktxhh +rkawdywu +pqqitomj +nrhhtvtv +gwerzhwc +qlsgifir +ssvyspem +udnnmvxk +albkdbsh +obxcrucu +dnyytrcx \ No newline at end of file diff --git a/2016/rust/src/day_06.rs b/2016/rust/src/day_06.rs new file mode 100644 index 0000000..aa00f90 --- /dev/null +++ b/2016/rust/src/day_06.rs @@ -0,0 +1,44 @@ +use std::collections::HashMap; + +use errors::*; + +pub fn solve(input: &str) -> Result { + let mut counters = HashMap::new(); + for line in input.lines() { + for (i, c) in line.chars().enumerate() { + let mut col = counters.entry(i).or_insert_with(|| HashMap::new()); + *col.entry(c).or_insert(0) += 1 + } + } + + let mut counters: Vec<_> = counters.iter().collect(); + counters.sort_by_key(|&(idx, _)| idx); + Ok(counters.iter() + .map(|&(_, col)| { + let mut v: Vec<_> = col.iter().collect(); + v.sort_by_key(|&(_, count)| count); + v.iter().map(|&(chr, _)| *chr).last().unwrap() + }) + .collect()) +} + +#[test] +fn test_solve() { + let input = "eedadn +drvtee +eandsr +raavrd +atevrs +tsrnev +sdttsa +rasrtv +nssdts +ntnada +svetve +tesnvt +vntsnd +vrdear +dvrsen +enarar"; + assert_eq!(solve(input).unwrap(), "easter".to_string()); +} diff --git a/2016/rust/src/lib.rs b/2016/rust/src/lib.rs index cef1563..b9cc037 100644 --- a/2016/rust/src/lib.rs +++ b/2016/rust/src/lib.rs @@ -11,3 +11,4 @@ pub mod day_02; pub mod day_03; pub mod day_04; pub mod day_05; +pub mod day_06; diff --git a/2016/rust/src/main.rs b/2016/rust/src/main.rs index 99c3f8f..ad71ce8 100644 --- a/2016/rust/src/main.rs +++ b/2016/rust/src/main.rs @@ -10,7 +10,7 @@ fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).ok(); - let solution = day_05::solve(&input)?; + let solution = day_06::solve(&input)?; println!("{}", solution); Ok(())