projects
/
advent-of-code-19.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Done day 21
[advent-of-code-19.git]
/
advent08
/
src
/
advent08.hs
diff --git
a/advent08/src/advent08.hs
b/advent08/src/advent08.hs
index fe00af5cb8e9518498b08d14552de30a5be25f8d..7c02922de66734f83bd0322c0a13b043f010d1f0 100644
(file)
--- a/
advent08/src/advent08.hs
+++ b/
advent08/src/advent08.hs
@@
-2,7
+2,6
@@
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.List.Split
import Data.Char
import Data.Ord
-import Data.Function
main :: IO ()
main = do
main :: IO ()
main = do
@@
-12,7
+11,6
@@
main = do
print $ part1 layers
putStrLn $ part2 layers
print $ part1 layers
putStrLn $ part2 layers
-
imageWidth = 25
imageHeight = 6
imageWidth = 25
imageHeight = 6
@@
-22,28
+20,15
@@
part1 layers = (count 1 target) * (count 2 target)
part2 layers = unlines rows
where pixelLayers = transpose layers
pixels = map firstVisible pixelLayers
part2 layers = unlines rows
where pixelLayers = transpose layers
pixels = map firstVisible pixelLayers
- dPixels = map showPixel pixels
- pixelRows = chunksOf imageWidth dPixels
- rows = map concat pixelRows
-
+ image = concatMap showPixel pixels
+ rows = chunksOf imageWidth image
firstVisible = head . dropWhile (== 2)
showPixel 0 = " "
showPixel 1 = "\x2588"
firstVisible = head . dropWhile (== 2)
showPixel 0 = " "
showPixel 1 = "\x2588"
-
count n = length . filter (== n)
count n = length . filter (== n)
--- Count the number of times a predicate is true
--- (Taken from GHC API utility functions)
-
--- count :: (a -> Bool) -> [a] -> Int
--- count p = go 0
--- where go !n [] = n
--- go !n (x:xs) | p x = go (n+1) xs
--- | otherwise = go n xs
-
-
successfulParse :: String -> [Int]
successfulParse input = map digitToInt input
\ No newline at end of file
successfulParse :: String -> [Int]
successfulParse input = map digitToInt input
\ No newline at end of file