Done day 3
authorNeil Smith <NeilNjae@users.noreply.github.com>
Sat, 3 Dec 2022 08:32:18 +0000 (08:32 +0000)
committerNeil Smith <NeilNjae@users.noreply.github.com>
Sat, 3 Dec 2022 08:52:52 +0000 (08:52 +0000)
advent-of-code22.cabal
advent03/Main.hs [new file with mode: 0644]
data/advent03.txt [new file with mode: 0644]
data/advent03a.txt [new file with mode: 0644]
problems/day03.html [new file with mode: 0644]

index 4da149943892651dee569ae23bb403c6e19c84cc..f310294d1bfbd437f8a80d421aec8af2dc7eebb2 100644 (file)
@@ -99,3 +99,8 @@ executable advent02
   import: common-extensions, build-directives
   main-is: advent02/Main.hs
   build-depends: text, attoparsec
+
+executable advent03
+  import: common-extensions, build-directives
+  main-is: advent03/Main.hs
+  build-depends: containers, split
diff --git a/advent03/Main.hs b/advent03/Main.hs
new file mode 100644 (file)
index 0000000..409ca33
--- /dev/null
@@ -0,0 +1,61 @@
+-- Writeup at https://work.njae.me.uk/2022/12/03/advent-of-code-2022-day-3/
+
+import System.Environment
+import Data.Char
+import qualified Data.Set as S
+import Data.List
+import Data.List.Split
+
+type Contents = S.Set Char
+data Rucksack = Rucksack String String deriving (Show, Eq)
+
+main :: IO ()
+main = 
+  do  dataFileName <- getDataFileName
+      text <- readFile dataFileName
+      let rucksacks = fmap mkRucksack $ lines text
+      print $ part1 rucksacks
+      print $ part2 rucksacks
+
+getDataFileName :: IO String
+getDataFileName =
+  do args <- getArgs
+     progName <- getProgName
+     let baseDataName =  if null args
+                         then progName
+                         else head args 
+     let dataFileName = "data/" ++ baseDataName ++ ".txt"
+     return dataFileName
+
+part1 :: [Rucksack] -> Int
+part1 = sum . fmap (priority . commonItem)
+
+part2 :: [Rucksack] -> Int
+part2 rucksacks = sum $ fmap priority badges
+  where groups = chunksOf 3 rucksacks
+        badges = fmap badgeOf groups
+
+merge :: Rucksack -> Contents
+merge (Rucksack contents1 contents2) = 
+  S.union (S.fromList contents1) (S.fromList contents2)
+
+badgeOf :: [Rucksack] -> Char
+badgeOf rucksacks = S.findMin $ intersections (fmap merge rucksacks)
+
+intersections :: [Contents] -> Contents
+intersections sets = foldl1' S.intersection sets
+
+
+mkRucksack :: String -> Rucksack
+mkRucksack contents = Rucksack (take n contents) (drop n contents)
+  where n = length contents `div` 2
+
+commonItem :: Rucksack -> Char
+commonItem (Rucksack contents1 contents2) = S.findMin (c1 `S.intersection` c2)
+  where c1 = S.fromList contents1
+        c2 = S.fromList contents2
+
+priority :: Char -> Int
+priority item 
+  | item >= 'a' = ord item - ord 'a' + 1
+  | otherwise = ord item - ord 'A' + 27
diff --git a/data/advent03.txt b/data/advent03.txt
new file mode 100644 (file)
index 0000000..3e41034
--- /dev/null
@@ -0,0 +1,300 @@
+wgqJtbJMqZVTwWPZZT
+LHcTGHQhzrTzBsZFPHFZWFFs
+RnLRClzGzRGLGLGCNRjTMjJfgmffSffMqNgp
+WPLgsfLmLgqZvZgSRR
+RbwHdbDdQFFFMvvMjbhqhZZS
+lzTdldBDszfGcRsr
+ZjnhJjMjnbdnbHdFLmmfFLmnCCWFFl
+PpNwtRsNsZSsRwCfzQQBfQszCBsC
+PpwcqqVZRtbggggjcgJJ
+ntczBcVcgnHzgBHnVntcBBFhgsmmmssqWNWNWqLvNhsqTN
+bSSGdSDZbGSGdDmLmGTvTGmLFFhm
+PlFbDpJDPbPdPbZQZDZlSCDBfMVRwBzBtBQzfzRHVMVRtH
+fDVrmmrvcmCcVpfcfGlswpPwsttMpjJMPPjjtP
+RgSTdndFLbJqqPssWWjPWjPjHS
+FqgzQnTqJRRQqLLhTCDhDCDmcmlvvlhcVm
+nnqVtHbfVHZVmtlvmHtZtrFSFTRRFhRccTbrLsLSGr
+cCNJQJPJQgjjMQdDrGGsRhTFGFRFSpMS
+gzdCwWdjNPgzcJgjwdZtVlHHmvvmZlvffHnz
+FFgsgwNwWvggQsMWDwvQQvQcccdcJZDtJGBtVGGGtcVlzt
+rjfTrbjpjRSRTbTpzldjjHBtJGBdltJG
+RbrPTfpCfmbpm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wDC
+rRhRhnnQPZhtZcZtdttZgqFWWVjssqQpppWpFpJW
+NWPhdWJPWVzVqQrqmSsPbrPP
+cZDRjGsffGsCDfffgjGgRQSrTcTmSlTrbnqmSSrlln
+fFGCjGCjLDLFRgfDHZvzLVWtvsWWBtzJNWMB
+qMVbtnmMMTpCppsR
+NffHGrWzWWgDBfTRhChCnSCWcnjT
+QrlQBPBrlPHrrQlrHFLqPnLvVvbVmVVJtq
+MVMpHMZLVCpMrfWjvWnfrJ
+hlblzDDzwlSlGtRhRlSdrfGGWnWWfFPjJjnfqWGF
+lmlhBRlDhhhDRRhwDmBpHJmsNCHmCgNHJCJLsc
+jvsLgmqLgHvbPPVbNjSCjC
+pwTcRpRWLRMLJJFwBBGWcFWNVlDDCSTVttNPblZZCVVDlP
+GcdhccpcpRpGRhGmfsHHzLQQHrmsnh
+FMmSRgtMltMnVgnmNvlrsJrsZWjspvsZJp
+QbdhqwqbNqdHbTdcbcpsrpvjfWfLJLfwJrWp
+DQBBQqQGccdTPGqqBNtFGRSMRSFGtnVSnnmM
+fPjGrfFrrprprdrbQPZwlcZwZmlJwH
+qvNnvWnvWDvSvqNtWSLWStqbcJBQwQJwQZHLBZbcmJbblb
+DMtvqSvvDtntCRfwzGCgdzzFjG
+TfdZgtmfDgqgvlLFFsFHvcvZ
+pphWQMVjQVVBWWjRlHlHnlcLDDhcnF
+JQwwWVPBwMJpJwpWwGBWNzrDzSSzfgTPqTSTTtSPgt
\ No newline at end of file
diff --git a/data/advent03a.txt b/data/advent03a.txt
new file mode 100644 (file)
index 0000000..9919ffa
--- /dev/null
@@ -0,0 +1,6 @@
+vJrwpWtwJgWrhcsFMMfFFhFp
+jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
+PmmdzqPrVvPwwTWBwg
+wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
+ttgJtRGJQctTZtZT
+CrZsJsPPZsGzwwsLwLmpwMDw
\ No newline at end of file
diff --git a/problems/day03.html b/problems/day03.html
new file mode 100644 (file)
index 0000000..986ad4f
--- /dev/null
@@ -0,0 +1,165 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 3 - Advent of Code 2022</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?30"/>
+<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
+<link rel="shortcut icon" href="/favicon.png"/>
+<script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
+</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 a massive company, 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, social media), I
+built the whole thing myself, including the design, animations, prose, and all
+of the puzzles.
+
+The puzzles are most of the work; preparing a new calendar and a new set of
+puzzles each year takes all of my free time for 4-5 months. 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="/2022/about">[About]</a></li><li><a href="/2022/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2022/settings">[Settings]</a></li><li><a href="/2022/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2022/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">6*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=</span><a href="/2022">2022</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2022">[Calendar]</a></li><li><a href="/2022/support">[AoC++]</a></li><li><a href="/2022/sponsors">[Sponsors]</a></li><li><a href="/2022/leaderboard">[Leaderboard]</a></li><li><a href="/2022/stats">[Stats]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2022/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.retool.com" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Retool</a> - Quickly build CRUD apps, admin panels, recurring jobs, and dashboards with JavaScript. Run in our cloud or yours. Free for small teams.</div></div>
+</div><!--/sidebar-->
+
+<main>
+<article class="day-desc"><h2>--- Day 3: Rucksack Reorganization ---</h2><p>One Elf has the important job of loading all of the <a href="https://en.wikipedia.org/wiki/Rucksack" target="_blank">rucksacks</a> with supplies for the <span title="Where there's jungle, there's hijinxs.">jungle</span> journey. Unfortunately, that Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged.</p>
+<p>Each rucksack has two large <em>compartments</em>. All items of a given type are meant to go into exactly one of the two compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack.</p>
+<p>The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, <code>a</code> and <code>A</code> refer to different types of items).</p>
+<p>The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same number of items in each of its two compartments, so the first half of the characters represent items in the first compartment, while the second half of the characters represent items in the second compartment.</p>
+<p>For example, suppose you have the following list of contents from six rucksacks:</p>
+<pre><code>vJrwpWtwJgWrhcsFMMfFFhFp
+jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
+PmmdzqPrVvPwwTWBwg
+wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
+ttgJtRGJQctTZtZT
+CrZsJsPPZsGzwwsLwLmpwMDw
+</code></pre>
+<ul>
+<li>The first rucksack contains the items <code>vJrwpWtwJgWrhcsFMMfFFhFp</code>, which means its first compartment contains the items <code>vJrwpWtwJgWr</code>, while the second compartment contains the items <code>hcsFMMfFFhFp</code>. The only item type that appears in both compartments is lowercase <code><em>p</em></code>.</li>
+<li>The second rucksack's compartments contain <code>jqHRNqRjqzjGDLGL</code> and <code>rsFMfFZSrLrFZsSL</code>. The only item type that appears in both compartments is uppercase <code><em>L</em></code>.</li>
+<li>The third rucksack's compartments contain <code>PmmdzqPrV</code> and <code>vPwwTWBwg</code>; the only common item type is uppercase <code><em>P</em></code>.</li>
+<li>The fourth rucksack's compartments only share item type <code><em>v</em></code>.</li>
+<li>The fifth rucksack's compartments only share item type <code><em>t</em></code>.</li>
+<li>The sixth rucksack's compartments only share item type <code><em>s</em></code>.</li>
+</ul>
+<p>To help prioritize item rearrangement, every item type can be converted to a <em>priority</em>:</p>
+<ul>
+<li>Lowercase item types <code>a</code> through <code>z</code> have priorities 1 through 26.</li>
+<li>Uppercase item types <code>A</code> through <code>Z</code> have priorities 27 through 52.</li>
+</ul>
+<p>In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (<code>p</code>), 38 (<code>L</code>), 42 (<code>P</code>), 22 (<code>v</code>), 20 (<code>t</code>), and 19 (<code>s</code>); the sum of these is <code><em>157</em></code>.</p>
+<p>Find the item type that appears in both compartments of each rucksack. <em>What is the sum of the priorities of those item types?</em></p>
+</article>
+<p>Your puzzle answer was <code>7727</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>As you finish identifying the misplaced items, the Elves come to you with another issue.</p>
+<p>For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For efficiency, within each group of three Elves, the badge is the <em>only item type carried by all three Elves</em>. That is, if a group's badge is item type <code>B</code>, then all three Elves will have item type <code>B</code> somewhere in their rucksack, and at most two of the Elves will be carrying any other item type.</p>
+<p>The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need to be pulled out of the rucksacks so the new authenticity stickers can be attached.</p>
+<p>Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type is the right one is by finding the one item type that is <em>common between all three Elves</em> in each group.</p>
+<p>Every set of three lines in your list corresponds to a single group, but each group can have a different badge item type. So, in the above example, the first group's rucksacks are the first three lines:</p>
+<pre><code>vJrwpWtwJgWrhcsFMMfFFhFp
+jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
+PmmdzqPrVvPwwTWBwg
+</pre></code>
+<p>And the second group's rucksacks are the next three lines:</p>
+<pre><code>wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
+ttgJtRGJQctTZtZT
+CrZsJsPPZsGzwwsLwLmpwMDw
+</code></pre>
+<p>In the first group, the only item type that appears in all three rucksacks is lowercase <code>r</code>; this must be their badges. In the second group, their badge item type must be <code>Z</code>.</p>
+<p>Priorities for these items must still be found to organize the sticker attachment efforts: here, they are 18 (<code>r</code>) for the first group and 52 (<code>Z</code>) for the second group. The sum of these is <code><em>70</em></code>.</p>
+<p>Find the item type that corresponds to the badges of each three-Elf group. <em>What is the sum of the priorities of those item types?</em></p>
+</article>
+<p>Your puzzle answer was <code>2609</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="/2022">return to your Advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="3/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+%22Rucksack+Reorganization%22+%2D+Day+3+%2D+Advent+of+Code+2022&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F3&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Rucksack+Reorganization%22+%2D+Day+3+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F3'}else{return false;}" target="_blank">Mastodon</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('set', 'anonymizeIp', true);
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
\ No newline at end of file