3829a68a601b192d17d3112813ad0cde0afea130
[advent-of-code-19.git] / advent21 / src / advent21.hs
1 import Debug.Trace
2
3 import Intcode
4
5 import qualified Data.Text.IO as TIO
6
7 import Data.List
8 import Data.Char
9
10
11 main :: IO ()
12 main = do
13 text <- TIO.readFile "data/advent21.txt"
14 let mem = parseMachineMemory text
15 let machine = makeMachine mem
16 putStrLn $ part1 machine
17 putStrLn $ part2 machine
18
19 part1Code :: [Integer]
20 part1Code = map (fromIntegral . ord) $ concatMap (++ "\n")
21 [ "OR A T"
22 , "AND B T"
23 , "AND C T"
24 , "NOT T J"
25 , "AND D J"
26 , "WALK"
27 ]
28
29 part2Code :: [Integer]
30 part2Code = map (fromIntegral . ord) $ concatMap (++ "\n")
31 [ "OR A T"
32 , "AND B T"
33 , "AND C T"
34 , "NOT T J"
35 -- e OR H -> T
36 , "OR E T"
37 , "OR H T"
38 , "AND T J"
39 , "AND D J"
40 , "RUN"
41 ]
42
43
44 part1 machine = drawOutput output
45 where (_, _, output) = runMachine part1Code machine
46
47 part2 machine = drawOutput output
48 where (_, _, output) = runMachine part2Code machine
49
50 drawOutput cs = t ++ n
51 where t = map (chr . fromIntegral) $ filter (<= 128) cs
52 n = show (filter ( > 128) cs)
53