Compare commits
No commits in common. "175760995026cc04c5b41e199bc32f445de37aac" and "2e6907c6041c0bb7206281268ac227c204b5f163" have entirely different histories.
1757609950
...
2e6907c604
3 changed files with 0 additions and 44 deletions
|
@ -8,4 +8,3 @@ https://adventofcode.com/2020/
|
||||||
|---|--------|---------|------|
|
|---|--------|---------|------|
|
||||||
| 1 | `**` | `**` | |
|
| 1 | `**` | `**` | |
|
||||||
| 2 | `**` | | `**` |
|
| 2 | `**` | | `**` |
|
||||||
| 3 | `**` | | |
|
|
||||||
|
|
23
day3/day3.hs
23
day3/day3.hs
|
@ -1,23 +0,0 @@
|
||||||
import Control.Applicative (empty)
|
|
||||||
import Control.Monad.Zip (mzip)
|
|
||||||
import Data.List (intercalate)
|
|
||||||
import Data.Maybe (catMaybes)
|
|
||||||
|
|
||||||
compose2 :: (a' -> b' -> c) -> (a -> a') -> (b -> b') -> a -> b -> c
|
|
||||||
compose2 f g h x y = f (g x) (h y)
|
|
||||||
|
|
||||||
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
|
|
||||||
f .: g = (f .) . g
|
|
||||||
infixl 8 .:
|
|
||||||
|
|
||||||
countHits :: (Int, Int) -> [[Bool]] -> Int
|
|
||||||
countHits = length . filter id . map (uncurry $ flip (!!)) . catMaybes .: compose2 (zipWith mzip) (uncurry . flip $ compose2 intercalate (flip replicate empty . pred) (fmap pure . map pure . enumFromThen 0)) (map pure)
|
|
||||||
|
|
||||||
treeCharToBool :: Char -> Bool
|
|
||||||
treeCharToBool = (== '#')
|
|
||||||
|
|
||||||
main = do
|
|
||||||
charLines <- lines <$> readFile "input.txt"
|
|
||||||
let boolLines = cycle <$> map treeCharToBool <$> charLines
|
|
||||||
print $ countHits (3, 1) boolLines
|
|
||||||
print $ product $ flip countHits boolLines <$> [(1,1), (3,1), (5,1), (7,1), (1,2)]
|
|
20
day3/day3.py
20
day3/day3.py
|
@ -1,20 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
def count_trees(right, down, lines):
|
|
||||||
n = 0
|
|
||||||
for i, line in enumerate(lines[::down]):
|
|
||||||
c = line[(i*right) % len(line)]
|
|
||||||
if c == '#':
|
|
||||||
n += 1
|
|
||||||
return n
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
with open('input.txt', 'r') as f:
|
|
||||||
lines = [line.strip() for line in f.readlines()]
|
|
||||||
|
|
||||||
print(count_trees(3, 1, lines))
|
|
||||||
|
|
||||||
hits_multiplied = 1
|
|
||||||
for slope in ((1,1), (3,1), (5,1), (7,1), (1,2)):
|
|
||||||
hits_multiplied *= count_trees(*slope, lines)
|
|
||||||
print(hits_multiplied)
|
|
Loading…
Reference in a new issue