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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Regler
Advent of Code 2024
Commits
88021bec
Commit
88021bec
authored
6 months ago
by
Sebastian Banert
Browse files
Options
Downloads
Patches
Plain Diff
Sebastian's day 10.
parent
0a670a43
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 10/day_10_sebastian.hs
+45
-0
45 additions, 0 deletions
day 10/day_10_sebastian.hs
with
45 additions
and
0 deletions
day 10/day_10_sebastian.hs
0 → 100644
+
45
−
0
View file @
88021bec
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module
Main
where
import
Data.List
(
transpose
)
import
Data.Array
import
qualified
Data.Set
as
S
import
qualified
Data.Map
as
M
neighbours
::
(
Int
,
Int
)
->
[(
Int
,
Int
)]
neighbours
(
i
,
j
)
=
[(
i
+
1
,
j
),
(
i
-
1
,
j
),
(
i
,
j
+
1
),
(
i
,
j
-
1
)]
main
::
IO
()
main
=
interact
solve
solve
::
String
->
String
solve
s
=
unlines
[
"Part 1: "
++
part1
s
,
"Part 2: "
++
part2
s
]
part1
::
String
->
String
part1
s
=
show
$
sum
$
M
.
map
S
.
size
zeroes
where
m
=
readInput
s
(
lv9
:
lvls
)
=
getLevels
m
nines
=
M
.
fromSet
S
.
singleton
lv9
zeroes
=
foldl
descend
nines
lvls
descend
::
M
.
Map
(
Int
,
Int
)
(
S
.
Set
(
Int
,
Int
))
->
S
.
Set
(
Int
,
Int
)
->
M
.
Map
(
Int
,
Int
)
(
S
.
Set
(
Int
,
Int
))
descend
upper
=
M
.
fromSet
(
S
.
unions
.
map
(
flip
(
M
.
findWithDefault
S
.
empty
)
upper
)
.
neighbours
)
part2
::
String
->
String
part2
s
=
show
(
sum
zeroes
)
where
m
=
readInput
s
(
lv9
:
lvls
)
=
getLevels
m
nines
=
M
.
fromSet
(
const
(
1
::
Int
))
lv9
zeroes
=
foldl
descend'
nines
lvls
descend'
::
M
.
Map
(
Int
,
Int
)
Int
->
S
.
Set
(
Int
,
Int
)
->
M
.
Map
(
Int
,
Int
)
Int
descend'
upper
=
M
.
fromSet
(
sum
.
map
(
flip
(
M
.
findWithDefault
0
)
upper
)
.
neighbours
)
readInput
::
String
->
Array
(
Int
,
Int
)
Char
readInput
s
=
listArray
((
0
,
0
),
(
w
-
1
,
h
-
1
))
(
concat
ls
)
where
ls
=
transpose
(
lines
s
)
w
=
length
(
head
ls
)
h
=
length
ls
getLevels
::
Array
(
Int
,
Int
)
Char
->
[
S
.
Set
(
Int
,
Int
)]
getLevels
m
=
map
(
\
c
->
S
.
filter
(
\
i
->
m
!
i
==
c
)
(
S
.
fromList
(
indices
m
)))
(
reverse
[
'0'
..
'9'
])
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