Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Advent of Code 2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Regler
Advent of Code 2024
Commits
8bd4d683
Commit
8bd4d683
authored
5 months ago
by
Sebastian Banert
Browse files
Options
Downloads
Patches
Plain Diff
Sebastian's day 11.
parent
88021bec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
day 11/day_11_sebastian.hs
+52
-0
52 additions, 0 deletions
day 11/day_11_sebastian.hs
with
52 additions
and
0 deletions
day 11/day_11_sebastian.hs
0 → 100644
+
52
−
0
View file @
8bd4d683
module
Main
where
import
qualified
Data.Map.Strict
as
M
main
::
IO
()
main
=
interact
solve
solve
::
String
->
String
solve
s
=
unlines
[
"Part 1: "
++
part1
s
,
"Part 2: "
++
part2
s
]
part1
::
String
->
String
part1
=
show
.
length
.
rep
25
(
concatMap
blink
)
.
readInput
part2
::
String
->
String
part2
=
show
.
sum
.
rep
75
(
concatMap'
blink
)
.
toMap
.
readInput
concatMap'
::
(
Integer
->
[
Integer
])
->
M
.
Map
Integer
Integer
->
M
.
Map
Integer
Integer
concatMap'
f
=
M
.
foldrWithKey
(
\
k
a
m'
->
foldl
(
flip
(
M
.
alter
(
incrBy
a
)))
m'
(
f
k
))
M
.
empty
readInput
::
String
->
[
Integer
]
readInput
=
map
read
.
words
toMap
::
[
Integer
]
->
M
.
Map
Integer
Integer
toMap
=
foldl
(
flip
(
M
.
alter
incr
))
M
.
empty
incr
::
Maybe
Integer
->
Maybe
Integer
incr
=
incrBy
1
incrBy
::
Integer
->
Maybe
Integer
->
Maybe
Integer
incrBy
k
Nothing
=
Just
k
incrBy
k
(
Just
n
)
=
Just
(
n
+
k
)
blink
::
Integer
->
[
Integer
]
blink
0
=
[
1
]
blink
n
|
even
(
length
ds
)
=
[
undigits
n2
,
undigits
n1
]
|
otherwise
=
[
2024
*
n
]
where
ds
=
digits
n
nds
=
length
(
digits
n
)
(
n1
,
n2
)
=
splitAt
(
nds
`
div
`
2
)
ds
rep
::
Int
->
(
a
->
a
)
->
a
->
a
rep
0
_
x
=
x
rep
n
f
x
=
rep
(
n
-
1
)
f
(
f
x
)
digits
::
Integer
->
[
Integer
]
digits
0
=
[]
digits
n
=
(
n
`
mod
`
10
)
:
digits
(
n
`
div
`
10
)
undigits
::
[
Integer
]
->
Integer
undigits
[]
=
0
undigits
(
d
:
r
)
=
d
+
10
*
undigits
r
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment