Day 6
authorNeil Smith <neil.git@njae.me.uk>
Tue, 6 Dec 2016 08:55:46 +0000 (08:55 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 6 Dec 2016 08:55:46 +0000 (08:55 +0000)
advent06.hs [new file with mode: 0644]
advent06.txt [new file with mode: 0644]
day06.html [new file with mode: 0644]

diff --git a/advent06.hs b/advent06.hs
new file mode 100644 (file)
index 0000000..4d99fd2
--- /dev/null
@@ -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 (file)
index 0000000..4a1a2a6
--- /dev/null
@@ -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 (file)
index 0000000..58c5575
--- /dev/null
@@ -0,0 +1,156 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 6 - Advent of Code 2016</title>
+<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
+<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
+<link rel="stylesheet" type="text/css" href="/static/style.css?7"/>
+<link rel="shortcut icon" href="/favicon.ico?2"/>
+</head><!--
+
+
+
+
+Oh, hello!  Funny seeing you here.
+
+I appreciate your enthusiasm, but you aren't going to find much down here.
+There certainly aren't clues to any of the puzzles.  The best surprises don't
+even appear in the source until you unlock them for real.
+
+Please be careful with automated requests; I'm not Google, and I can only take
+so much traffic.  Please be considerate so that everyone gets to play.
+
+If you're curious about how Advent of Code works, it's running on some custom
+Perl code. Other than a few integrations (auth, analytics, ads, social media),
+I built the whole thing myself, including the design, animations, prose, and
+all of the puzzles.
+
+The puzzles probably took the longest; the easiest ones were around 45 minutes
+each, but the harder ones took 2-3 hours, and a few even longer than that. A
+lot of effort went into building this thing - I hope you're enjoying playing it
+as much as I enjoyed making it for you!
+
+If you'd like to hang out, I'm @ericwastl on Twitter.
+
+- Eric Wastl
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-->
+<body>
+<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2016/about">[About]</a></li><li><a href="/2016/support">[AoC++]</a></li><li><a href="/2016/events">[Events]</a></li><li><a href="/2016/settings">[Settings]</a></li><li><a href="/2016/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <span class="supporter">(AoC++)</span> <span class="star-count">12*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">int y=</span><a href="/2016">2016</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2016">[Calendar]</a></li><li><a href="/2016/leaderboard">[Leaderboard]</a></li><li><a href="/2016/stats">[Stats]</a></li><li><a href="/2016/sponsors">[Sponsors]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2016/sponsors">sponsors</a> help make AoC possible:</div><p><a href="http://www.novetta.com/careers/#opportunities" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);">Novetta</a> - Unleash your imagination. Innovate at Novetta.</p></div>
+<div id="ad">
+<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
+<!-- Advent of Code Wide Skyscraper -->
+<ins class="adsbygoogle"
+     style="display:inline-block;width:160px;height:600px"
+     data-ad-client="ca-pub-9420604735624631"
+     data-ad-slot="8014013294"></ins>
+<script>
+(adsbygoogle = window.adsbygoogle || []).push({});
+</script>
+</div><!--/ad-->
+</div><!--/sidebar-->
+
+<main>
+<article class="day-desc"><h2>--- Day 6: Signals and Noise ---</h2><p>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 <a href="https://en.wikipedia.org/wiki/Repetition_code">repetition code</a> to get the message through.</p>
+<p>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. <em>Almost</em>.</p>
+<p>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:</p>
+<pre><code>eedadn
+drvtee
+eandsr
+raavrd
+atevrs
+tsrnev
+sdttsa
+rasrtv
+nssdts
+ntnada
+svetve
+tesnvt
+vntsnd
+vrdear
+dvrsen
+enarar
+</code></pre>
+<p>The most common character in the first column is <code>e</code>; in the second, <code>a</code>; in the third, <code>s</code>, and so on. Combining these characters returns the error-corrected message, <code>easter</code>.</p>
+<p>Given the recording in your puzzle input, <em>what is the error-corrected version</em> of the message being sent?</p>
+</article>
+<p>Your puzzle answer was <code>umejzgdw</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p>Of course, that <em>would</em> be the message - if you hadn't agreed to use a <em>modified repetition code</em> instead.</p>
+<p>In this <span title="*Please* don't try this at home.">modified code</span>, the sender instead transmits what looks like random data, but for each character, the character they actually want to send is <em>slightly less likely</em> than the others. Even after signal-jamming noise, you can look at the letter distributions in each column and choose the <em>least common</em> letter to reconstruct the original message.</p>
+<p>In the above example, the least common character in the first column is <code>a</code>; in the second, <code>d</code>, and so on. Repeating this process for the remaining characters produces the original message, <code>advent</code>.</p>
+<p>Given the recording in your puzzle input and this new decoding methodology, <em>what is the original message</em> that Santa is trying to send?</p>
+</article>
+<p>Your puzzle answer was <code>aovueakv</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
+<p>At this point, you should <a href="/2016">return to your advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="6/input" target="_blank">get your puzzle input</a>.</p>
+<p>You can also <span class="share">[Share<span class="share-content">on
+  <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Signals+and+Noise%22+%2D+Day+6+%2D+Advent+of+Code+2016&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F6&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F6" target="_blank">Google+</a>
+  <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F6&amp;title=I%27ve+completed+%22Signals+and+Noise%22+%2D+Day+6+%2D+Advent+of+Code+2016" target="_blank">Reddit</a
+></span>]</span> this puzzle.</p>
+</main>
+
+<!-- ga -->
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-69522494-1', 'auto');
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
\ No newline at end of file