Skip to content

Commit

Permalink
Day_10
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheinxy committed Dec 10, 2022
1 parent d9d306a commit 01657af
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Day_10/day_10.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Main where

parseInput :: String -> [Int]
parseInput = concatMap (\l -> 0 : if l == "noop" then [] else [read . last . words $ l]) . lines

chunk :: Int -> [a] -> [[a]]
chunk n = takeWhile (not . null) . map (take n) . iterate (drop n)

drawLine :: [Int] -> IO()
drawLine = putStrLn . map getChar . zip [0 .. ]
where getChar (c, x) = if abs (c - x) <= 1 then '#' else '.'

main = do
input <- parseInput <$> readFile "input"
let cycles = init . scanl (+) 1 $ input
print $ sum [cycles !! (i - 1) * i | i <- [20, 60 .. 220]]
mapM drawLine . chunk 40 $ cycles
140 changes: 140 additions & 0 deletions Day_10/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
addx 2
addx 15
addx -11
addx 6
noop
noop
noop
addx -1
addx 5
addx -1
addx 5
noop
noop
noop
noop
noop
addx 7
addx -1
addx 3
addx 1
addx 5
addx 1
noop
addx -38
noop
addx 1
addx 6
addx 3
noop
addx -8
noop
addx 13
addx 2
addx 3
addx -2
addx 2
noop
addx 3
addx 9
addx -2
addx 2
addx -10
addx 11
addx 2
addx -14
addx -21
addx 2
noop
addx 5
addx 29
addx -2
noop
addx -19
noop
addx 2
addx 11
addx -10
addx 2
addx 5
addx -9
noop
addx 14
addx 2
addx 3
addx -2
addx 3
addx 1
noop
addx -37
noop
addx 13
addx -8
noop
noop
noop
noop
addx 13
addx -5
addx 3
addx 3
addx 3
noop
noop
noop
noop
noop
noop
noop
addx 6
addx 3
addx 1
addx 5
addx -15
addx 5
addx -27
addx 30
addx -23
addx 33
addx -32
addx 2
addx 5
addx 2
addx -16
addx 17
addx 2
addx -10
addx 17
addx 10
addx -9
addx 2
addx 2
addx 5
addx -29
addx -8
noop
noop
noop
addx 19
addx -11
addx -1
addx 6
noop
noop
addx -1
addx 3
noop
addx 3
addx 2
addx -3
addx 11
addx -1
addx 5
addx -2
addx 5
addx 2
noop
noop
addx 1
noop
noop
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Watch me code in Haskell for 25 days straight

| Day | Part 1 | Part 2 | Day | Part 1 | Part 2 | Day | Part 1 | Part 2 |
|----- |-------- |-------- |----- |-------- |-------- |----- |-------- |-------- |
| [Day 01](./Day_01) ||| [Day 10](./Day_10) | | | [Day 19](./Day_19) | | |
| [Day 01](./Day_01) ||| [Day 10](./Day_10) | | | [Day 19](./Day_19) | | |
| [Day 02](./Day_02) ||| [Day 11](./Day_11) | | | [Day 20](./Day_20) | | |
| [Day 03](./Day_03) ||| [Day 12](./Day_12) | | | [Day 21](./Day_21) | | |
| [Day 04](./Day_04) ||| [Day 13](./Day_13) | | | [Day 22](./Day_22) | | |
Expand Down Expand Up @@ -53,3 +53,7 @@ Well, it didn't go so bad, I definitely feel like I'm getting better at this eve
### [Day 09](./Day_09):
I spent so much time on this simply because I didn't understand properly how
moving works

### [Day 10](./Day_10):
Definitely one of the easiest ones so far (not as easy as Day 6, but still really easy)!
I'm pretty sure that, had I woken up before 6AM today, I could actually have been in the leaderboard 🙀

0 comments on commit 01657af

Please sign in to comment.