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
acf2328f
authored
Dec 10, 2021
by
Stuart Kurtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Day 10
parent
c3bfe3c7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
2 deletions
data/syntax.txt
src/AOC-10a.hs
src/AOC-10b.hs
test/syntax.txt
data/syntax.txt
0 → 100644
View file @
acf2328f
This diff is collapsed.
Click to expand it.
src/AOC-10a.hs
View file @
acf2328f
module
Main
where
score
::
String
->
Int
score
=
go
[]
where
match
[]
_
=
False
match
(
a
:
_
)
c
=
(
a
,
c
)
`
elem
`
[(
'('
,
')'
),
(
'['
,
']'
),(
'{'
,
'}'
),(
'<'
,
'>'
)]
isOpen
c
=
c
`
elem
`
[
'('
,
'['
,
'{'
,
'<'
]
go
_
[]
=
0
-- out of input
go
as
(
c
:
cs
)
|
isOpen
c
=
go
(
c
:
as
)
cs
|
match
as
c
=
go
(
tail
as
)
cs
|
otherwise
=
charScore
c
charScore
')'
=
3
charScore
']'
=
57
charScore
'}'
=
1197
charScore
'>'
=
25137
charScore
c
=
error
$
"score.charScore -- unexpected character: "
++
[
c
]
main
::
IO
()
main
=
pure
()
main
=
do
input
<-
lines
<$>
readFile
"data/syntax.txt"
print
.
sum
.
map
score
$
input
src/AOC-10b.hs
View file @
acf2328f
module
Main
where
import
Data.List
(
sort
)
import
Data.Maybe
(
mapMaybe
)
score
::
String
->
Maybe
Int
score
=
go
[]
where
match
[]
_
=
False
match
(
a
:
_
)
c
=
(
a
,
c
)
`
elem
`
[(
'('
,
')'
),
(
'['
,
']'
),(
'{'
,
'}'
),(
'<'
,
'>'
)]
isOpen
c
=
c
`
elem
`
[
'('
,
'['
,
'{'
,
'<'
]
go
as
[]
=
Just
$
stackScore
as
go
as
(
c
:
cs
)
|
isOpen
c
=
go
(
c
:
as
)
cs
|
match
as
c
=
go
(
tail
as
)
cs
|
otherwise
=
Nothing
-- bad syntax
stackScore
=
foldl
(
\
s
c
->
charScore
c
+
5
*
s
)
0
charScore
'('
=
1
charScore
'['
=
2
charScore
'{'
=
3
charScore
'<'
=
4
charScore
c
=
error
$
"score.charScore -- unexpected character: "
++
[
c
]
middle
::
[
a
]
->
a
middle
as
=
head
.
drop
(
length
as
`
div
`
2
)
$
as
main
::
IO
()
main
=
pure
()
main
=
do
input
<-
lines
<$>
readFile
"data/syntax.txt"
putStr
.
show
.
middle
.
sort
.
mapMaybe
score
$
input
test/syntax.txt
0 → 100644
View file @
acf2328f
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]
\ No newline at end of file
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