mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-14 05:49:52 +01:00
Move 2015 to haskellAoC & change Days listing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
*input*
|
|
||||||
1
haskellAoC/.gitignore
vendored
1
haskellAoC/.gitignore
vendored
@@ -1,4 +1,3 @@
|
|||||||
.stack-work/
|
.stack-work/
|
||||||
*~
|
*~
|
||||||
inputs/
|
|
||||||
*.cabal
|
*.cabal
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ dependencies:
|
|||||||
- sort
|
- sort
|
||||||
- split
|
- split
|
||||||
- directory
|
- directory
|
||||||
|
- pureMD5
|
||||||
|
- utf8-string
|
||||||
|
|
||||||
library:
|
library:
|
||||||
source-dirs: src
|
source-dirs: src
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module Lib (pickYear) where
|
module Lib (pickYear) where
|
||||||
|
|
||||||
|
import Y2015.Days
|
||||||
import Y2019.Days
|
import Y2019.Days
|
||||||
import Y2020.Days
|
import Y2020.Days
|
||||||
|
|
||||||
@@ -11,22 +12,9 @@ import System.Environment
|
|||||||
type DayFun = [String] -> (String, String)
|
type DayFun = [String] -> (String, String)
|
||||||
|
|
||||||
getDayFun :: String -> String -> DayFun
|
getDayFun :: String -> String -> DayFun
|
||||||
getDayFun "2019" "01" = y19day01
|
getDayFun "2015" = year2015
|
||||||
getDayFun "2019" "02" = y19day02
|
getDayFun "2019" = year2019
|
||||||
getDayFun "2019" "03" = y19day03
|
getDayFun "2020" = year2020
|
||||||
getDayFun "2019" "04" = y19day04
|
|
||||||
getDayFun "2019" "05" = y19day05
|
|
||||||
getDayFun "2019" "06" = y19day06
|
|
||||||
getDayFun "2019" "07" = y19day07
|
|
||||||
getDayFun "2019" "08" = y19day08
|
|
||||||
getDayFun "2019" "09" = y19day09
|
|
||||||
getDayFun "2019" "10" = y19day10
|
|
||||||
getDayFun "2019" "11" = y19day11
|
|
||||||
getDayFun "2019" "12" = y19day12
|
|
||||||
getDayFun "2019" "13" = y19day13
|
|
||||||
getDayFun "2020" "01" = y20day01
|
|
||||||
getDayFun "2020" "02" = y20day02
|
|
||||||
getDayFun "2020" "03" = y20day03
|
|
||||||
|
|
||||||
callDailyFun :: String -> DayFun -> String -> IO ()
|
callDailyFun :: String -> DayFun -> String -> IO ()
|
||||||
callDailyFun year fn name = do
|
callDailyFun year fn name = do
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
module Y2015.Day01 (y15day01) where
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
day1steps :: [Char] -> [Int]
|
day1steps :: [Char] -> [Int]
|
||||||
@@ -10,3 +12,8 @@ day1p2 :: [Char] -> Maybe Int
|
|||||||
day1p2 xs = findIndex (== entrance) steps
|
day1p2 xs = findIndex (== entrance) steps
|
||||||
where steps = scanl (\acc x -> acc + x) 0 (day1steps xs)
|
where steps = scanl (\acc x -> acc + x) 0 (day1steps xs)
|
||||||
entrance = -1
|
entrance = -1
|
||||||
|
|
||||||
|
y15day01 :: [String] -> (String, String)
|
||||||
|
y15day01 (input:_) = (part1, part2)
|
||||||
|
where part1 = show $ day1p1 input
|
||||||
|
part2 = show $ day1p2 input
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
module Y2015.Day02 (y15day02) where
|
||||||
|
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
|
|
||||||
computeSides :: [Int] -> [Int]
|
computeSides :: [Int] -> [Int]
|
||||||
@@ -30,18 +32,8 @@ part1computation dims = computeWrapping dims + computeSlack dims
|
|||||||
part2computation :: [Int] -> Int
|
part2computation :: [Int] -> Int
|
||||||
part2computation dims = computeRibbonWrap dims + computeRibbonBow dims
|
part2computation dims = computeRibbonWrap dims + computeRibbonBow dims
|
||||||
|
|
||||||
day2 :: ([Int] -> Int) -> String -> Int
|
y15day02 :: [String] -> (String, String)
|
||||||
day2 fn input = sum paper
|
y15day02 input = (part1, part2)
|
||||||
where entries = lines input
|
where part1 = show $ compute part1computation
|
||||||
dims = map parseDims entries
|
part2 = show $ compute part2computation
|
||||||
paper = map fn dims
|
compute fn = sum $ map fn $ map parseDims input
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
input <- getContents
|
|
||||||
putStr "Part1: "
|
|
||||||
print (day2 part1computation input)
|
|
||||||
putStrLn ""
|
|
||||||
putStr "Part2: "
|
|
||||||
print (day2 part2computation input)
|
|
||||||
putStrLn ""
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
module Y2015.Day03 (y15day03) where
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
move :: [(Int, Int)] -> Char -> [(Int, Int)]
|
move :: [(Int, Int)] -> Char -> [(Int, Int)]
|
||||||
@@ -26,3 +28,8 @@ day3part1 input = length (uniqueHouses (houses input))
|
|||||||
|
|
||||||
day3part2 :: [Char] -> Int
|
day3part2 :: [Char] -> Int
|
||||||
day3part2 input = length (uniqueHouses (housesWithBot input))
|
day3part2 input = length (uniqueHouses (housesWithBot input))
|
||||||
|
|
||||||
|
y15day03 :: [String] -> (String, String)
|
||||||
|
y15day03 (input:_) = (part1, part2)
|
||||||
|
where part1 = show $ day3part1 input
|
||||||
|
part2 = show $ day3part2 input
|
||||||
17
haskellAoC/src/Y2015/Day04.hs
Normal file
17
haskellAoC/src/Y2015/Day04.hs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
module Y2015.Day04 (y15day04) where
|
||||||
|
|
||||||
|
import Data.ByteString.Lazy.UTF8 (fromString)
|
||||||
|
import Data.Digest.Pure.MD5
|
||||||
|
|
||||||
|
getLeadingZeroes :: String -> Int -> Int
|
||||||
|
getLeadingZeroes base nb = nbZeroes
|
||||||
|
where pass = base ++ (show nb)
|
||||||
|
md5hash = show $ md5 $ fromString pass
|
||||||
|
nbZeroes = length $ takeWhile (== '0') md5hash
|
||||||
|
|
||||||
|
-- Crappy bruteforce solution...
|
||||||
|
y15day04 :: [String] -> (String, String)
|
||||||
|
y15day04 (input:_) = (part1, part2)
|
||||||
|
where part1 = show $ firstWithNzeroes 5
|
||||||
|
part2 = show $ firstWithNzeroes 6
|
||||||
|
firstWithNzeroes n = head $ take 1 $ dropWhile (\h -> getLeadingZeroes input h /= n) $ iterate (+1) 0
|
||||||
13
haskellAoC/src/Y2015/Days.hs
Normal file
13
haskellAoC/src/Y2015/Days.hs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module Y2015.Days (year2015) where
|
||||||
|
|
||||||
|
import Y2015.Day01
|
||||||
|
import Y2015.Day02
|
||||||
|
import Y2015.Day03
|
||||||
|
import Y2015.Day04
|
||||||
|
|
||||||
|
|
||||||
|
year2015 :: String -> [String] -> (String, String)
|
||||||
|
year2015 "01" = y15day01
|
||||||
|
year2015 "02" = y15day02
|
||||||
|
year2015 "03" = y15day03
|
||||||
|
year2015 "04" = y15day04
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
module Y2019.Days (y19day01, y19day02, y19day03, y19day04, y19day05, y19day06,
|
module Y2019.Days (year2019) where
|
||||||
y19day07, y19day08, y19day09, y19day10, y19day11, y19day12,
|
|
||||||
y19day13
|
|
||||||
) where
|
|
||||||
|
|
||||||
import Y2019.Day01
|
import Y2019.Day01
|
||||||
import Y2019.Day02
|
import Y2019.Day02
|
||||||
@@ -17,16 +14,17 @@ import Y2019.Day11
|
|||||||
import Y2019.Day12
|
import Y2019.Day12
|
||||||
import Y2019.Day13
|
import Y2019.Day13
|
||||||
|
|
||||||
y19day01 = day1
|
year2019 :: String -> [String] -> (String, String)
|
||||||
y19day02 = day2
|
year2019 "01" = day1
|
||||||
y19day03 = day3
|
year2019 "02" = day2
|
||||||
y19day04 = day4
|
year2019 "03" = day3
|
||||||
y19day05 = day5
|
year2019 "04" = day4
|
||||||
y19day06 = day6
|
year2019 "05" = day5
|
||||||
y19day07 = day7
|
year2019 "06" = day6
|
||||||
y19day08 = day8
|
year2019 "07" = day7
|
||||||
y19day09 = day9
|
year2019 "08" = day8
|
||||||
y19day10 = day10
|
year2019 "09" = day9
|
||||||
y19day11 = day11
|
year2019 "10" = day10
|
||||||
y19day12 = day12
|
year2019 "11" = day11
|
||||||
y19day13 = day13
|
year2019 "12" = day12
|
||||||
|
year2019 "13" = day13
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
module Y2020.Days (y20day01, y20day02, y20day03) where
|
module Y2020.Days (year2020) where
|
||||||
|
|
||||||
import Y2020.Day01
|
import Y2020.Day01
|
||||||
import Y2020.Day02
|
import Y2020.Day02
|
||||||
import Y2020.Day03
|
import Y2020.Day03
|
||||||
|
|
||||||
|
|
||||||
|
year2020 :: String -> [String] -> (String, String)
|
||||||
|
year2020 "01" = y20day01
|
||||||
|
year2020 "02" = y20day02
|
||||||
|
year2020 "03" = y20day03
|
||||||
|
|||||||
Reference in New Issue
Block a user