day02
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
cabal-version: 1.12
|
||||
|
||||
-- This file has been generated from package.yaml by hpack version 0.34.2.
|
||||
-- This file has been generated from package.yaml by hpack version 0.35.0.
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
|
||||
@@ -28,6 +28,7 @@ executable AOC22-exe
|
||||
other-modules:
|
||||
AOCUtil
|
||||
Days.Day01
|
||||
Days.Day02
|
||||
Paths_AOC22
|
||||
hs-source-dirs:
|
||||
src
|
||||
|
||||
0
CHANGELOG.md
Normal file
0
CHANGELOG.md
Normal file
2500
data/day02.txt
Normal file
2500
data/day02.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -12,4 +12,4 @@ solve :: [String]-> Int
|
||||
solve = maximum . map (sum . (map read)) . splitOn ""
|
||||
|
||||
solveB :: [String] -> Int
|
||||
solveB = sum . take 3 .reverse. sort . map (sum . (map read)) . splitOn ""
|
||||
solveB = sum. take 3 .reverse. sort . map (sum . (map read)) . splitOn ""
|
||||
|
||||
57
src/Days/Day02.hs
Normal file
57
src/Days/Day02.hs
Normal file
@@ -0,0 +1,57 @@
|
||||
module Days.Day02 where
|
||||
|
||||
import AOCUtil
|
||||
import Data.List
|
||||
|
||||
runA :: IO ()
|
||||
runA = interactF "data/day02.txt" (show . solve . lines)
|
||||
|
||||
runB :: IO ()
|
||||
runB = interactF "data/day02.txt" (show . sum . map (scoreB . words) . lines)
|
||||
|
||||
solve :: [String] -> Int
|
||||
solve = sum . map (score . words)
|
||||
|
||||
score :: [String] -> Int
|
||||
score [a, b] = myScore b + winScore a b
|
||||
score _ = undefined
|
||||
|
||||
-- data Symbol = Rock | Paper | Scissor
|
||||
|
||||
-- readSymbol :: String -> Symbol
|
||||
-- readSymbol "A" = Rock
|
||||
-- readSymbol "X" = Rock
|
||||
-- readSymbol "B" = Paper
|
||||
-- readSymbol "Y" = Paper
|
||||
-- readSymbol "C" = Scissor
|
||||
-- readSymbol "Z" = Scissor
|
||||
-- readSymbol _ = undefined
|
||||
|
||||
scoreB :: [String] -> Int
|
||||
scoreB [a, b] = myScore (choose a b) + winScore a (choose a b)
|
||||
scoreB _ = undefined
|
||||
|
||||
myScore :: String -> Int
|
||||
myScore "X" = 1
|
||||
myScore "Y" = 2
|
||||
myScore "Z" = 3
|
||||
|
||||
winScore :: String -> String -> Int
|
||||
winScore "A" "Y" = 6
|
||||
winScore "B" "Z" = 6
|
||||
winScore "C" "X" = 6
|
||||
winScore "A" "X" = 3
|
||||
winScore "B" "Y" = 3
|
||||
winScore "C" "Z" = 3
|
||||
winScore _ _ = 0
|
||||
|
||||
choose :: String -> String -> String
|
||||
choose "A" "X" = "Z"
|
||||
choose "A" "Y" = "X"
|
||||
choose "A" "Z" = "Y"
|
||||
choose "B" "X" = "X"
|
||||
choose "B" "Y" = "Y"
|
||||
choose "B" "Z" = "Z"
|
||||
choose "C" "X" = "Y"
|
||||
choose "C" "Y" = "Z"
|
||||
choose "C" "Z" = "X"
|
||||
@@ -17,7 +17,8 @@
|
||||
#
|
||||
# resolver: ./custom-snapshot.yaml
|
||||
# resolver: https://example.com/snapshots/2018-01-01.yaml
|
||||
resolver: lts-20.2
|
||||
resolver:
|
||||
compiler: ghc-9.2.4
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
|
||||
@@ -4,9 +4,4 @@
|
||||
# https://docs.haskellstack.org/en/stable/lock_files
|
||||
|
||||
packages: []
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 648432
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/2.yaml
|
||||
sha256: fc39d8afc97531d53d87b10abdef593bce503c0c1e46c2e9a84ebcbc78bf8470
|
||||
original: lts-20.2
|
||||
snapshots: []
|
||||
|
||||
Reference in New Issue
Block a user