Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Neil Smith
advent-of-code-20
Commits
d86a8647
Commit
d86a8647
authored
Dec 22, 2020
by
Neil Smith
Browse files
Tidying
parent
7f33f392
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
18 deletions
+20
-18
advent12/src/advent12.hs
advent12/src/advent12.hs
+18
-16
advent13/src/advent13.hs
advent13/src/advent13.hs
+2
-2
No files found.
advent12/src/advent12.hs
View file @
d86a8647
...
...
@@ -17,12 +17,13 @@ type Position = (Int, Int) -- (x, y)
data
Action
a
=
N
a
|
S
a
|
E
a
|
W
a
|
L
a
|
R
a
|
F
a
deriving
(
Show
,
Eq
,
Ord
)
data
Ship
=
Ship
{
direction
::
Direction
,
position
::
Position
}
deriving
(
Show
,
Eq
,
Ord
)
--
data Ship = Ship { direction :: Direction, position :: Position }
--
deriving (Show, Eq, Ord)
data
ShipW
=
ShipW
{
positionW
::
Position
,
waypoint
::
Position
}
data
Ship
=
Ship
{
position
::
Position
,
direction
::
Direction
,
waypoint
::
Position
}
deriving
(
Show
,
Eq
,
Ord
)
...
...
@@ -38,12 +39,12 @@ main =
part1
actions
=
manhattan
(
position
ship1
)
start
where
start
=
(
0
,
0
)
ship0
=
Ship
{
position
=
start
,
direction
=
East
}
ship0
=
Ship
{
position
=
start
,
direction
=
East
,
waypoint
=
(
10
,
1
)
}
ship1
=
foldl
act
ship0
actions
part2
actions
=
manhattan
(
position
W
ship1
)
start
part2
actions
=
manhattan
(
position
ship1
)
start
where
start
=
(
0
,
0
)
ship0
=
Ship
W
{
position
W
=
start
,
waypoint
=
(
10
,
1
)}
ship0
=
Ship
{
position
=
start
,
direction
=
East
,
waypoint
=
(
10
,
1
)}
ship1
=
foldl
actW
ship0
actions
-- apAc actions = ship1
...
...
@@ -56,6 +57,7 @@ part2 actions = manhattan (positionW ship1) start
-- ship0 = ShipW {positionW = start, waypoint = (10, 1) }
-- ship1 = foldl actW ship0 actions
act
::
Ship
->
Action
Int
->
Ship
act
Ship
{
..
}
(
N
d
)
=
Ship
{
position
=
dDelta
d
North
position
,
..
}
act
Ship
{
..
}
(
S
d
)
=
Ship
{
position
=
dDelta
d
South
position
,
..
}
act
Ship
{
..
}
(
W
d
)
=
Ship
{
position
=
dDelta
d
West
position
,
..
}
...
...
@@ -65,14 +67,14 @@ act Ship{..} (R a) = Ship { direction = d, ..} where d = (iterate succW directio
act
Ship
{
..
}
(
F
d
)
=
Ship
{
position
=
dDelta
d
direction
position
,
..
}
actW
Ship
W
{
..
}
(
N
d
)
=
Ship
W
{
waypoint
=
dDelta
d
North
waypoint
,
..
}
actW
Ship
W
{
..
}
(
S
d
)
=
Ship
W
{
waypoint
=
dDelta
d
South
waypoint
,
..
}
actW
Ship
W
{
..
}
(
W
d
)
=
Ship
W
{
waypoint
=
dDelta
d
West
waypoint
,
..
}
actW
Ship
W
{
..
}
(
E
d
)
=
Ship
W
{
waypoint
=
dDelta
d
East
waypoint
,
..
}
actW
Ship
W
{
..
}
(
L
a
)
=
Ship
W
{
waypoint
=
d
,
..
}
where
d
=
(
iterate
rotL
waypoint
)
!!
(
a
`
div
`
90
)
actW
Ship
W
{
..
}
(
R
a
)
=
Ship
W
{
waypoint
=
d
,
..
}
where
d
=
(
iterate
rotR
waypoint
)
!!
(
a
`
div
`
90
)
actW
Ship
W
{
..
}
(
F
d
)
=
Ship
W
{
position
W
=
p'
,
..
}
where
(
x
,
y
)
=
position
W
actW
Ship
{
..
}
(
N
d
)
=
Ship
{
waypoint
=
dDelta
d
North
waypoint
,
..
}
actW
Ship
{
..
}
(
S
d
)
=
Ship
{
waypoint
=
dDelta
d
South
waypoint
,
..
}
actW
Ship
{
..
}
(
W
d
)
=
Ship
{
waypoint
=
dDelta
d
West
waypoint
,
..
}
actW
Ship
{
..
}
(
E
d
)
=
Ship
{
waypoint
=
dDelta
d
East
waypoint
,
..
}
actW
Ship
{
..
}
(
L
a
)
=
Ship
{
waypoint
=
d
,
..
}
where
d
=
(
iterate
rotL
waypoint
)
!!
(
a
`
div
`
90
)
actW
Ship
{
..
}
(
R
a
)
=
Ship
{
waypoint
=
d
,
..
}
where
d
=
(
iterate
rotR
waypoint
)
!!
(
a
`
div
`
90
)
actW
Ship
{
..
}
(
F
d
)
=
Ship
{
position
=
p'
,
..
}
where
(
x
,
y
)
=
position
(
dx
,
dy
)
=
waypoint
p'
=
(
x
+
(
d
*
dx
),
y
+
(
d
*
dy
))
...
...
advent13/src/advent13.hs
View file @
d86a8647
...
...
@@ -17,8 +17,8 @@ main :: IO ()
main
=
do
text
<-
TIO
.
readFile
"data/advent13.txt"
let
(
timestamp
,
busses
)
=
successfulParse
text
print
timestamp
print
busses
--
print timestamp
--
print busses
print
$
part1
timestamp
busses
print
$
part2
busses
...
...
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