From d7f603546349671e29d25bc65c4eab34121eb8ed Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Tue, 6 Dec 2016 08:55:46 +0000 Subject: [PATCH] Day 6 --- advent06.hs | 42 ++++ advent06.txt | 624 +++++++++++++++++++++++++++++++++++++++++++++++++++ day06.html | 156 +++++++++++++ 3 files changed, 822 insertions(+) create mode 100644 advent06.hs create mode 100644 advent06.txt create mode 100644 day06.html diff --git a/advent06.hs b/advent06.hs new file mode 100644 index 0000000..4d99fd2 --- /dev/null +++ b/advent06.hs @@ -0,0 +1,42 @@ +module Main(main) where + +import Data.List (last, intersperse, sortBy, intercalate, isInfixOf, transpose) +import Data.List.Split (splitOn) +import Data.Char (isLetter, ord, chr) +import qualified Data.Map.Lazy as Map + + +input = "cxdnnyjw" + +main :: IO () +main = do + text <- readFile "advent06.txt" + let message = lines text + part1 message + part2 message + + +part1 :: [String] -> IO () +part1 message = do + print $ map (fst) $ map (mostCommon) $ map (countedLetters) $ transpose message + +part2 :: [String] -> IO () +part2 message = do + print $ map (fst) $ map (leastCommon) $ map (countedLetters) $ transpose message + + + +countedLetters :: String -> Map.Map Char Int +countedLetters name = Map.fromListWith (+) [(c, 1) | c <- filter (isLetter) name] + +mostCommon = Map.foldlWithKey (mostCommonP) ('a', 0) + +mostCommonP (letter0, count0) letter count + | count > count0 = (letter, count) + | otherwise = (letter0, count0) + +leastCommon = Map.foldlWithKey (leastCommonP) ('a', maxBound :: Int) + +leastCommonP (letter0, count0) letter count + | count < count0 = (letter, count) + | otherwise = (letter0, count0) \ No newline at end of file diff --git a/advent06.txt b/advent06.txt new file mode 100644 index 0000000..4a1a2a6 --- /dev/null +++ b/advent06.txt @@ -0,0 +1,624 @@ +focdealm +ggsipflx +rvibwxbm +vqrfyyrh +hsjtzpgs +ozymxpoy +jiecwags +lztseufl +dfwibwsn +skiuhnwl +kamgzqog +axeqncwa +gobivxto +nwgoryhd +tzrlitrq +uzoldxbv +zsteobha +pfcgdqkg +prcqlunp +iwivemkh +vpkilupm +ewuznabz +veaptost +cyvirffe +ejhhqfng +ibsqztgg +xzczkboh +bckhbodf +vbycgonv +esmoyyku +unccgdgj +cqwnqlzs +edoqmykb +bkvzlhyq +yzrspisn +zlzibhca +povnweaf +muyfegxe +oaojqfrl +gwesjxws +rjknfyeh +dkquvctc +cfuzhxoj +tdzzzfqc +lzjzsyni +wjfxckkf +xmhyjhop +kmtllzxs +yohearbj +ilmvyxgn +erczytzw +kuetjsba +vwkpollq +tujwluzc +jlvedjcp +acmoaoji +gqoliyen +agckavhf +ottamfdm +jxwlyotw +tdpsrapj +carwwmqc +ykaipjdj +zdfrbduu +vwiiosud +uoixglbw +yegbwxjb +wbpqqqfv +wpynmyqi +aqdkscgd +oghnbnnf +duftexbb +ttvbofay +jferymwy +hqzimpiq +sifyogml +nymxqbws +dhdlhhqp +urtuhcrj +giwcunfq +fxgretsl +maihqkpk +pdxfkcru +xixtthag +vuzxqzzi +wxxeleug +xpopxkzo +hgcsyuad +xcbydxnx +kxocfakp +erxdajeq +tliakzhh +iygbbuxs +qlgqthpp +duzzptwk +gfnqdotc +kjayxeqf +fehitfar +yemshppn +igtczmmw +gfajhxch +bslzmgwo +xpmhmirx +yhlwlupt +nymajupw +tlhgdefw +bqkudizc +lucrhmnm +svkoaqzz +luggfivf +ckawtiwy +eeivawhj +qdmmmvdl +quezzzqa +oimsfsuo +jdvcknqu +aupohqbk +llwsasnz +zlpljtjl +xfylqxlv +zqppxkul +varoizrq +yxryqwso +gsscetca +gcbdgqyo +hsdnvteo +pxtoreoc +rwjdkwzs +zdgofynf +polyntkx +jhulgrnf +ycbzpdpw +bzvdbwsy +vydjbucs +rxadwwuo +ccnvzjak +nombazjc +lbxwdasr +cbdlkiha +sdomdvow +phjnkkkp +nmtmrnyz +nxsvmcwk +hqimjvir +vmjhhuuv +zilhgqlb +gfgbibgg +imxxugfe +wtaffkbj +lyguqvjs +pejslhls +qjnefwii +oanqnnnc +kcjyfwxm +zoxjwxmw +ihmokcrm +uebsbhfr +fxvjiorr +ebjiucyt +ofutlokv +mdfnsuyr +dzviwqdk +umwyaijz +hdqwfalt +qtyrouwh +lkzcrtwa +dtqvwzke +buplmmca +xxepjuvj +omyotlar +ytndbwhi +sbntigym +mphrnsme +xiymeoxr +kcujxcih +bydnchgk +snwdjlip +yljsymtv +tyhbpoab +zlqhvzxl +akbtnzop +xnpjmysj +znhednen +vbcsocrm +ywjajour +ejngbqev +rstykfhc +cbcnoexq +mzlxvxwj +vfdqaalp +nbszzozr +dqpyojid +hfuqilbl +uoackeup +shqkcsmr +jbdasroe +fmlkvsnt +cnomxkvk +unbsfncq +bnzxltxe +bbadfyin +skmhtmhn +xkypwglb +flbfiioo +fzywneyg +srngxbut +qtodeuxg +xvawfqli +nyfmrdsn +rdjysbxj +spmezvvj +ofoivcuc +touzgqzx +mfqyzagc +dmaurbdv +gqnrlyuw +wuppusoh +qgstihuy +uldnlrpi +xaskgwim +djjrphid +qjhmctyu +osfenjdn +zvoahhkk +xiuyatyn +fepobmjh +kmugpjpw +aikpozqs +kmgmazif +gbzlodzb +hrocqadn +noekklwb +vzwhnkvx +osrspxsc +iekmqgua +xeehndee +quttqjav +htoptweo +cyicmwba +jltlwlyy +qvccdkig +bibggekq +kwfwvrfg +eycwlcup +murgcddl +lyukeubx +twbpzoyg +dkcvzele +fozhtmcz +frugeivm +qjbhpdpr +tgkkeroo +ryuvgqgc +jhixykqn +wsebmcrn +wohtjpgu +isflpxxt +xggwmamk +tfwdsrfe +cpjvcghr +fekhexdb +zcwzqofh +awnfiqzu +ihekvqby +rqaqajij +cumouwzx +ccyrflxd +rredygrk +patcpktn +mjnwuefa +tuhgyfsw +mjpxrgkx +hupfjqxo +mgkclcrf +jkmkhkci +nkcrwgqd +apmfiqpg +pxiawshv +ledhpfaz +btikmkwj +jwosopir +mgxftcte +phkbcdex +uakftnbh +fnkmdecn +swrvbjwj +hphskevf +trnpfdmy +odvmmqss +akvqgemq +zyqlkwdm +nbnaqjsa +mbnogzyt +mchaxjxu +tcqqerqz +ayylasgq +zqbrjfli +ccjjnfat +lvlpdjqu +luiabalt +qsvkepvz +dtyobsiy +jkulvrnc +thwjbzkh +vvhrwbkx +fhxejrff +bacuriaz +grmtyude +feynnckb +hfdepyjn +lvsfflyc +xfrgfgeh +vqqybtba +ntlfjqjt +zadauvmg +itukkpqf +mrnnfgmf +hpjqvppo +dshgwmgb +pzxeoymv +nlokvrio +cgcaxffl +dvimsnxu +iczcvwho +lkxumswj +satmovog +ujwknitl +halkgpaa +pnttnodc +adsvsumi +jwerfpko +yhsjqytk +vpevemez +yvjmltwj +vdoeippw +siouxait +ftrspdpx +hptwqlmz +haewgrft +watbdvqz +eiptzrvr +msvbioso +dnjeoucg +qixvmlem +mqquklfq +sszagakl +khfbexqb +uysydrlc +inawynse +whuonlhq +eshukapj +vtrepdxm +pgjjcisd +puiunlts +replddlv +emjyyhmd +aahwhond +laneyzsj +jnlkdpyb +sqxrctuo +wmmyybvl +ldyvqldz +bzbrsdjr +ekxwhzte +gnpqywzz +afsfbtte +ggkbrgds +dlawfrbp +opypolpc +cqpxcfgh +ynmtlgvl +slfmicyv +ooguwxjc +tewmtlty +wcdwansw +ktercyvw +qrgxrzne +wvbhflls +dpfjwbmm +uigmcaow +ejzhkxic +fbewvcoh +jxbtcmwn +ywiktjqn +rftnjqpp +yalixnnw +srdsiwgy +pdpdrynx +ioroheqp +vpvvnmad +tqksxfsp +snzxciua +nrhtoskm +crfvapzk +wndbcxvf +syffkzmv +nneibkaf +unuvhnli +ujhdjkvs +gmyqgvdr +jedfxwje +bcshopnu +xgiprhyv +onibkkoq +riguljez +yodzrfeu +ogbwakaa +ymrltbxa +ourmuhrx +yxwixtuv +ptnxdvdm +oskvgexz +fbigwiaw +xctckzmy +khwiyvmw +qbqbtxpr +kavzlngz +bbklqvzt +rwlzppbq +upirhhca +ezlaqdgo +ieuynchi +qmjtojzq +qrricseq +hxkrsfmw +nssfpnws +tiaziudb +rvskpahe +pplmppvi +jxpyidio +teudseap +aclyhavi +yqafhkyd +drjhcqgu +zvfcfbjc +sqfuuezn +gwtsupqk +czakgbiy +wknfzbyj +ooxwycji +wxymanlx +ewbtpqtl +jmwnxydh +ceqdllqb +jhdbejmt +mazzsanu +uypyqlvh +itnrzbie +miuegdjz +tqxeipin +kbareizb +jgjxrycy +epshhech +oicruxsz +ptxgidha +bmgnvjtr +qvwzlmgq +cvwtdffi +ibzasmru +jfenrbjd +nrkgwvcz +hlmghdgd +emhdaicl +wdwrzocv +spwjcrud +dsgilvqn +phvmafqk +iiihsfff +uvcqgtyc +doxkrzzw +hktdpsbv +evqojani +kzapomdx +ewtbrdtb +rgshzyxq +ltinzxld +cazrrlcu +irfxunbt +rmqcsbvm +gddexbsb +qladhkpd +xlvzpmab +wirftlbu +fxfqjubx +sgogtrcb +zlqxxwfy +djgtbihr +gslssgsu +wytydgje +vmovsmdh +ogyiuirh +mtfxzrrx +kcpfbemc +blreqhel +zjsjqqyh +ciqwtpvk +yjcinpaa +wxbxagui +aqbjqmig +ybaeuhew +mjzpnttv +mevjcrqp +fpmgzgco +gklesvof +jzfssvvx +aynfmwhl +euosbnhf +lcebcalt +kvsuuyyt +ltranzur +nlledtpz +vqdrgckr +yodxnjpt +uyznwnni +ckczwqkp +uxtjgoee +otdoyaxg +lbccbfgi +mhzjujrp +cekkthvf +fbvpuhog +nzfannep +rnnqusey +aiocsiyy +uvcbtfwr +bzqirxrg +qnmfgshq +inyevvbn +wswvhglx +huxqxwwb +fdutjnfq +adajhsjk +ahllesij +tcfawzgu +zfdgmtry +byznvpfp +duunxdad +kgadxmdf +ptfaovzv +uhuvlivs +xcoqrmeu +nnnlvmga +zwrbykek +lvpumidd +hieivrnt +vrwqsvci +npbplsvm +ougzcgty +rzvgzooo +iehafkto +rzspzjne +dzvvhvld +fgkmmfda +xjsnnlmd +igvjrsuk +narcempo +xrhoiugu +ghxbpomr +waxtcbcg +tmqgsejx +dobaxhel +mpzgjyww +ehyfvnaz +zxrdlajd +hfquyvok +aqxxdcqv +vjbukram +rjvttibk +pryxgzrd +hcqpxgee +qjgqvoal +wmbuvcty +zpgxmdiu +foequjps +lmdjwyfj +mhqudwzv +lrzkttsw +owyatnru +gwppbbfb +fvlkdsjk +pwhlvjtb +zgldiibp +sokjzgvq +kfourwqm +nfqoyvsz +hdiwmrhk +nnapsbht +blqjjtwy +aknoauti +uhgowkyx +uypyjorh +blfeioot +kzbukpxk +kfmbxgle +zmegahum +upjouzrg +tkedvzfy +bxwxuutn +rrwxobjp +jdujkhox +jkycewdx +ivlbibns +qjshodxf +bektjeou +wotjfgfl +rjrcfiug +aklhubjf +kwpnaezt +lsqvzdom +pxzvorct +vcxazyzs +xsszjsjq +ydgfsukl +gqxpcrla +rvsoxkhy +rschupcm +ivlpikxi +etrnyvkh +byzymjms +qagdcqww +sxnausxs +giuitchj +qgolehtg +keeskeyb \ No newline at end of file diff --git a/day06.html b/day06.html new file mode 100644 index 0000000..58c5575 --- /dev/null +++ b/day06.html @@ -0,0 +1,156 @@ + + + + +Day 6 - Advent of Code 2016 + + + + + + +

Advent of Code

Neil Smith (AoC++) 12*

   int y=2016;

+ + + +
+

--- Day 6: Signals and Noise ---

Something is jamming your communications with Santa. Fortunately, your signal is only partially jammed, and protocol in situations like this is to switch to a simple repetition code to get the message through.

+

In this model, the same message is sent repeatedly. You've recorded the repeating message signal (your puzzle input), but the data seems quite corrupted - almost too badly to recover. Almost.

+

All you need to do is figure out which character is most frequent for each position. For example, suppose you had recorded the following messages:

+
eedadn
+drvtee
+eandsr
+raavrd
+atevrs
+tsrnev
+sdttsa
+rasrtv
+nssdts
+ntnada
+svetve
+tesnvt
+vntsnd
+vrdear
+dvrsen
+enarar
+
+

The most common character in the first column is e; in the second, a; in the third, s, and so on. Combining these characters returns the error-corrected message, easter.

+

Given the recording in your puzzle input, what is the error-corrected version of the message being sent?

+
+

Your puzzle answer was umejzgdw.

--- Part Two ---

Of course, that would be the message - if you hadn't agreed to use a modified repetition code instead.

+

In this modified code, the sender instead transmits what looks like random data, but for each character, the character they actually want to send is slightly less likely than the others. Even after signal-jamming noise, you can look at the letter distributions in each column and choose the least common letter to reconstruct the original message.

+

In the above example, the least common character in the first column is a; in the second, d, and so on. Repeating this process for the remaining characters produces the original message, advent.

+

Given the recording in your puzzle input and this new decoding methodology, what is the original message that Santa is trying to send?

+
+

Your puzzle answer was aovueakv.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file -- 2.34.1