9 "{-# LANGUAGE NegativeLiterals #-}\n",
10 "{-# LANGUAGE FlexibleContexts #-}"
19 "import Data.List.Split (splitOn)"
28 "hexStep :: (Int, Int) -> String -> (Int, Int)\n",
29 "hexStep (n, ne) s = case s of \n",
30 " \"n\" -> (n + 1, ne)\n",
31 " \"ne\" -> (n, ne + 1)\n",
32 " \"nw\" -> (n + 1, ne - 1)\n",
33 " \"s\" -> (n - 1, ne)\n",
34 " \"se\" -> (n - 1, ne + 1)\n",
35 " \"sw\" -> (n, ne - 1)"
44 "hexPath = foldl hexStep (0, 0)"
55 "<style>/* Styles used for the Hoogle display in the pager */\n",
58 "padding-bottom: 1.3em;\n",
59 "padding-left: 0.4em;\n",
63 "font-family: monospace;\n",
64 "white-space: pre;\n",
71 "font-weight: bold;\n",
74 "font-weight: bold;\n",
78 "margin-left: 0.4em;\n",
80 ".hoogle-package {\n",
81 "font-weight: bold;\n",
82 "font-style: italic;\n",
85 "font-weight: bold;\n",
88 "font-weight: bold;\n",
92 "font-weight: bold;\n",
93 "font-family: monospace;\n",
95 "white-space: pre-wrap;\n",
99 "font-weight: bold;\n",
100 "font-family: monospace;\n",
101 "margin-left: 1em;\n",
104 "font-family: monospace;\n",
109 "font-style: italic;\n",
110 "font-family: monospace;\n",
111 "white-space: pre;\n",
116 "font-weight: bold;\n",
118 ".err-msg.in.collapse {\n",
119 "padding-top: 0.7em;\n",
121 ".highlight-code {\n",
122 "white-space: pre;\n",
123 "font-family: monospace;\n",
125 ".suggestion-warning { \n",
126 "font-weight: bold;\n",
127 "color: rgb(200, 130, 0);\n",
129 ".suggestion-error { \n",
130 "font-weight: bold;\n",
133 ".suggestion-name {\n",
134 "font-weight: bold;\n",
136 "</style><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(abs n) + (abs ne)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">abs n + (abs ne)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(abs n) + (abs ne)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">(abs n) + abs ne</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(abs n) - smallest</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">abs n - smallest</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(abs ne) - smallest</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">abs ne - smallest</div></div>"
139 "Line 2: Redundant bracket\n",
141 "(abs n) + (abs ne)\n",
143 "abs n + (abs ne)Line 2: Redundant bracket\n",
145 "(abs n) + (abs ne)\n",
147 "(abs n) + abs neLine 5: Redundant bracket\n",
149 "(abs n) - smallest\n",
151 "abs n - smallestLine 5: Redundant bracket\n",
153 "(abs ne) - smallest\n",
159 "output_type": "display_data"
163 "distance (n, ne) = if n * ne > 0 \n",
164 " then (abs n) + (abs ne)\n",
165 " else smallest + remainder\n",
166 " where smallest = min (abs n) (abs ne)\n",
167 " remainder = max ((abs n) - smallest) ((abs ne) - smallest)"
172 "execution_count": 6,
182 "output_type": "display_data"
186 "distance $ hexPath $ splitOn \",\" \"ne,ne,ne\""
191 "execution_count": 7,
201 "output_type": "display_data"
205 "distance $ hexPath $ splitOn \",\" \"ne,ne,sw,sw\""
210 "execution_count": 8,
220 "output_type": "display_data"
224 "distance $ hexPath $ splitOn \",\" \"ne,ne,s,s\""
229 "execution_count": 9,
239 "output_type": "display_data"
243 "distance $ hexPath $ splitOn \",\" \"se,sw,se,sw,sw\""
248 "execution_count": 10,
252 "part1 = distance . hexPath . splitOn \",\""
257 "execution_count": 11,
263 " text <- readFile \"../../data/advent11.txt\"\n",
264 "-- let instrs = map read $ splitOn \",\" text\n",
265 " print $ part1 text\n",
266 "-- print $ part2 text"
271 "execution_count": 12,
281 "output_type": "display_data"
290 "execution_count": 13,
294 "hexPathB = scanl hexStep (0, 0)"
299 "execution_count": 14,
309 "output_type": "display_data"
313 "maximum $ map distance $ hexPathB $ splitOn \",\" \"ne,ne,ne\""
318 "execution_count": 15,
324 "[(0,0),(0,1),(0,2),(0,3)]"
328 "output_type": "display_data"
332 "hexPathB $ splitOn \",\" \"ne,ne,ne\""
337 "execution_count": 16,
347 "output_type": "display_data"
351 "map distance $ hexPathB $ splitOn \",\" \"ne,ne,ne\""
356 "execution_count": 17,
362 "([(0,0),(0,1),(0,2),(0,3)],[0,1,2,3],3)"
366 "output_type": "display_data"
370 "pth = splitOn \",\" \"ne,ne,ne\"\n",
371 "(hexPathB pth, map distance $ hexPathB pth, maximum $ map distance $ hexPathB pth)"
376 "execution_count": 18,
382 "([(0,0),(0,1),(0,2),(0,1),(0,0)],[0,1,2,1,0],2)"
386 "output_type": "display_data"
390 "pth = splitOn \",\" \"ne,ne,sw,sw\"\n",
391 "(hexPathB pth, map distance $ hexPathB pth, maximum $ map distance $ hexPathB pth)"
396 "execution_count": 19,
402 "([(0,0),(0,1),(0,2),(-1,2),(-2,2)],[0,1,2,2,2],2)"
406 "output_type": "display_data"
410 "pth = splitOn \",\" \"ne,ne,s,s\"\n",
411 "(hexPathB pth, map distance $ hexPathB pth, maximum $ map distance $ hexPathB pth)"
416 "execution_count": 20,
422 "([(0,0),(-1,1),(-1,0),(-2,1),(-2,0),(-2,-1)],[0,1,1,2,2,3],3)"
426 "output_type": "display_data"
430 "pth = splitOn \",\" \"se,sw,se,sw,sw\"\n",
431 "(hexPathB pth, map distance $ hexPathB pth, maximum $ map distance $ hexPathB pth)"
436 "execution_count": 21,
440 "part2 = maximum . map distance . hexPathB . splitOn \",\""
445 "execution_count": 22,
451 " text <- readFile \"../../data/advent11.txt\"\n",
452 "-- let instrs = map read $ splitOn \",\" text\n",
453 " print $ part1 text\n",
454 " print $ part2 text"
459 "execution_count": 23,
470 "output_type": "display_data"
479 "execution_count": null,
487 "display_name": "Haskell",
488 "language": "haskell",
492 "codemirror_mode": "ihaskell",
493 "file_extension": ".hs",