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
79c9326d
authored
Dec 06, 2021
by
Stuart Kurtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Day 6, minor cleanups
parent
735cbe2f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
12 deletions
src/AOC-06a.hs
src/AOC-06b.hs
src/AOC-06a.hs
View file @
79c9326d
{-# LANGUAGE TypeApplications #-}
module
Main
where
import
Data.Array
import
Data.Array
(
Array
,
array
,
(
!
),
accumArray
)
type
Population
=
Array
Int
Int
...
...
@@ -13,9 +11,9 @@ step a = array (0,8) [(x,f x) | x <- [0..8]] where
f
n
=
a
!
(
n
+
1
)
makeFish
::
[
Int
]
->
Array
Int
Int
makeFish
=
accumArray
(
+
)
0
(
0
,
8
)
.
map
(
\
x
->
(
x
,
1
))
makeFish
=
accumArray
(
+
)
0
(
0
,
8
)
.
map
(
flip
(,)
1
)
main
::
IO
()
main
=
do
phases
<-
makeFish
.
read
@
[
Int
]
.
(
"["
++
)
.
(
++
"]"
)
<$>
readFile
"data/lantern-fish.txt"
phases
<-
makeFish
.
read
.
(
"["
++
)
.
(
++
"]"
)
<$>
readFile
"data/lantern-fish.txt"
print
.
sum
$
iterate
step
phases
!!
80
src/AOC-06b.hs
View file @
79c9326d
{-# LANGUAGE TypeApplications #-}
module
Main
where
import
Data.Array
import
Data.Array
(
Array
,
array
,
(
!
),
accumArray
)
type
Population
=
Array
Int
Int
...
...
@@ -13,9 +11,9 @@ step a = array (0,8) [(x,f x) | x <- [0..8]] where
f
n
=
a
!
(
n
+
1
)
makeFish
::
[
Int
]
->
Array
Int
Int
makeFish
=
accumArray
(
+
)
0
(
0
,
8
)
.
map
(
\
x
->
(
x
,
1
))
makeFish
=
accumArray
(
+
)
0
(
0
,
8
)
.
map
(
flip
(,)
1
)
main
::
IO
()
main
=
do
phases
<-
makeFish
.
read
@
[
Int
]
.
(
"["
++
)
.
(
++
"]"
)
<$>
readFile
"data/lantern-fish.txt"
phases
<-
makeFish
.
read
.
(
"["
++
)
.
(
++
"]"
)
<$>
readFile
"data/lantern-fish.txt"
print
.
sum
$
iterate
step
phases
!!
256
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