projects
/
advent-of-code-22.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c4a6729
)
Using bounded
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Sat, 3 Dec 2022 08:29:04 +0000
(08:29 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Sat, 3 Dec 2022 08:29:04 +0000
(08:29 +0000)
advent02/Main.hs
patch
|
blob
|
history
diff --git
a/advent02/Main.hs
b/advent02/Main.hs
index 9cb89cc02be4dc4faa67d1ec62aedc12ede4ec05..44a236173b398a9e5005ebb10c2be8f952f61eb0 100644
(file)
--- a/
advent02/Main.hs
+++ b/
advent02/Main.hs
@@
-6,7
+6,7
@@
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
import Control.Applicative
import Data.Attoparsec.Text hiding (Result)
import Control.Applicative
-data Shape = Rock | Paper | Scissors deriving (Show, Eq, Ord, Enum)
+data Shape = Rock | Paper | Scissors deriving (Show, Eq, Ord, Enum
, Bounded
)
data Result = Loss | Draw | Win deriving (Show, Eq, Ord, Enum)
data Round = Round Shape Shape deriving (Eq, Show)
data ShapeResult = ShapeResult Shape Result deriving (Eq, Show)
data Result = Loss | Draw | Win deriving (Show, Eq, Ord, Enum)
data Round = Round Shape Shape deriving (Eq, Show)
data ShapeResult = ShapeResult Shape Result deriving (Eq, Show)
@@
-55,7
+55,8
@@
scoreResult r = 3 * fromEnum r
roundFromResult :: ShapeResult -> Round
roundFromResult (ShapeResult shape result) = Round shape p2s
where p2s = head [ p2Shape
roundFromResult :: ShapeResult -> Round
roundFromResult (ShapeResult shape result) = Round shape p2s
where p2s = head [ p2Shape
- | p2Shape <- [Rock .. Scissors]
+ -- | p2Shape <- [Rock .. Scissors]
+ | p2Shape <- [minBound .. maxBound]
, player2Result (Round shape p2Shape) == result
]
, player2Result (Round shape p2Shape) == result
]