9 "{-# LANGUAGE NegativeLiterals #-}\n",
10 "{-# LANGUAGE FlexibleContexts #-}"
19 "import Text.Parsec hiding (State)"
24 "execution_count": 19,
28 "instructionLine = many (up <|> down)\n",
30 "up = char '(' *> pure 1\n",
31 "down = char ')' *> pure -1"
36 "execution_count": 20,
40 "parseIline :: String -> Either ParseError [Int]\n",
41 "parseIline input = parse instructionLine \"(unknown)\" input\n",
43 "successfulParse :: Either ParseError [a] -> [a]\n",
44 "successfulParse (Left _) = []\n",
45 "successfulParse (Right a) = a"
50 "execution_count": 21,
54 "part1 :: [Int] -> IO ()\n",
55 "part1 instructions = do\n",
56 " print $ sum instructions"
61 "execution_count": 25,
65 "part2 :: [Int] -> IO ()\n",
66 "part2 instructions = do\n",
67 " print $ length $ takeWhile (>= 0) $ scanl (+) 0 instructions"
72 "execution_count": 23,
78 " text <- readFile \"../../data/advent01.txt\"\n",
79 " let instructions = successfulParse $ parseIline text\n",
80 " part1 instructions\n",
86 "execution_count": 26,
97 "output_type": "display_data"
106 "execution_count": null,
114 "display_name": "Haskell",
115 "language": "haskell",
119 "codemirror_mode": "ihaskell",
120 "file_extension": ".hs",