-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathday19.nim
More file actions
32 lines (24 loc) · 673 Bytes
/
day19.nim
File metadata and controls
32 lines (24 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import strutils, complex
const
instructions = readFile("./inputs/19.txt").splitLines
leftTurn = complex(0.0, -1.0)
rightTurn = complex(0.0, 1.0)
var
pos = complex(instructions[0].find('|').toFloat, 0.0)
direction = complex(0.0, 1.0)
letters = ""
steps = 0
func getChar(pos: Complex): char =
instructions[int(pos.im)][int(pos.re)]
proc change(direction: var Complex) =
if getChar(pos + leftTurn * direction) != ' ': direction *= leftTurn
else: direction *= rightTurn
var c = pos.getChar
while c != ' ':
inc steps
if c.isAlphaAscii: letters.add(c)
elif c == '+': change direction
pos += direction
c = pos.getChar
echo letters
echo steps