Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Neil Smith
advent-of-code-20
Commits
e76710c7
Commit
e76710c7
authored
Jan 05, 2021
by
Neil Smith
Browse files
Tweaking
parent
facb3213
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
7 deletions
+6
-7
advent22/src/advent22.hs
advent22/src/advent22.hs
+6
-7
No files found.
advent22/src/advent22.hs
View file @
e76710c7
...
...
@@ -35,8 +35,8 @@ main =
print
$
part1
decks
print
$
part2
decks
part1
decks
=
score
$
winningDeck
$
play
decks
part2
decks
=
score
$
snd
$
playRecursive
decks
M
.
empty
part1
game
=
score
$
winningDeck
$
play
game
part2
game
=
score
$
snd
$
playRecursive
game
M
.
empty
play
=
until
finished
playRound
...
...
@@ -50,13 +50,12 @@ playRound ((x :<| xs), (y :<| ys))
|
x
<
y
=
(
xs
,
ys
|>
y
|>
x
)
|
otherwise
=
(
xs
|>
x
|>
y
,
ys
)
winningDeck
::
Game
->
Deck
winningDeck
(
Empty
,
ys
)
=
ys
winningDeck
(
xs
,
_
)
=
xs
score
::
Deck
->
Int
score
=
Q
.
foldrWithIndex
(
\
i
c
s
->
s
+
(
i
+
1
)
*
c
)
0
.
Q
.
reverse
score
=
sum
.
zipWith
(
*
)
[
1
..
]
.
toList
.
Q
.
reverse
playRecursive
::
Game
->
Cache
->
(
Player
,
Deck
)
playRecursive
(
Empty
,
ys
)
_
=
(
P2
,
ys
)
...
...
@@ -68,8 +67,8 @@ playRecursive g@(x :<| xs, y :<| ys) seen
where
seen'
=
enCache
g
seen
(
subWinner
,
_
)
=
playRecursive
(
Q
.
take
x
xs
,
Q
.
take
y
ys
)
seen'
subG
=
updateDecks
subWinner
g
compare
Winner
=
if
x
<
y
then
P2
else
P1
compareG
=
updateDecks
compare
Winner
g
compare
Tops
=
if
x
<
y
then
P2
else
P1
compareG
=
updateDecks
compare
Tops
g
updateDecks
P1
(
x
:<|
xs
,
y
:<|
ys
)
=
(
xs
|>
x
|>
y
,
ys
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment