Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Stuart A Kurtz
/
advent-of-code-2021
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
423aa87b
authored
Dec 21, 2021
by
Stuart Kurtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Day 21, with major part a cleanups and improved comments.
parent
3a60a6d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
src/AOC-21b.hs
src/AOC-21b.hs
View file @
423aa87b
...
...
@@ -14,24 +14,24 @@ splits = M.assocs $ roll 3 (M.singleton 0 1) where
roll
0
m
=
m
roll
n
m
=
roll
(
n
-
1
)
.
M
.
unionsWith
(
+
)
.
map
((`
M
.
mapKeys
`
m
)
.
(
+
))
$
[
1
,
2
,
3
]
-- universes ! (x
Score,xPos,yScore
,yPos) = (losers,winners)
-- universes ! (x
Count,xPos,yCount
,yPos) = (losers,winners)
-- where player X will make the next move.
universes
::
Array
(
Int
,
Int
,
Int
,
Int
)
(
Integer
,
Integer
)
universes
=
array
bds
[(
p
,
score
p
)
|
p
<-
range
bds
]
where
universes
=
array
bds
[(
p
,
counts
p
)
|
p
<-
range
bds
]
where
bds
=
((
0
,
1
,
0
,
1
),(
20
,
10
,
20
,
10
))
score
(
xScore
,
xPos
,
yScore
,
yPos
)
=
counts
(
xCount
,
xPos
,
yCount
,
yPos
)
=
sumPairs
[
(
c
*
losers
,
c
*
winners
)
|
(
r
,
c
)
<-
splits
,
let
nPos
=
((
xPos
+
r
-
1
)
`
mod
`
10
)
+
1
nScore
=
x
Score
+
nPos
(
winners
,
losers
)
=
univ
y
Score
yPos
nScore
nPos
nScore
=
x
Count
+
nPos
(
winners
,
losers
)
=
univ
y
Count
yPos
nScore
nPos
]
sumPairs
=
foldr1
(
\
(
a
,
b
)
(
c
,
d
)
->
(
a
+
c
,
b
+
d
))
univ
x
Score
xPos
yScore
yPos
|
y
Score
>=
21
=
(
1
,
0
)
|
otherwise
=
universes
!
(
x
Score
,
xPos
,
yScore
,
yPos
)
univ
x
Count
xPos
yCount
yPos
|
y
Count
>=
21
=
(
1
,
0
)
|
otherwise
=
universes
!
(
x
Count
,
xPos
,
yCount
,
yPos
)
diracGame
::
Int
->
Int
->
(
Integer
,
Integer
)
diracGame
p1
p2
=
universes
!
(
0
,
p1
,
0
,
p2
)
...
...
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