46 lines
739 B
Nim
46 lines
739 B
Nim
|
import lib/loader
|
||
|
|
||
|
|
||
|
type
|
||
|
Map = object
|
||
|
rows: seq[string]
|
||
|
|
||
|
|
||
|
proc `[]`(m: Map, x, y: int): bool =
|
||
|
let row = m.rows[y]
|
||
|
let colNum = x mod row.len
|
||
|
result = (row[colNum] == '#')
|
||
|
|
||
|
|
||
|
let data = Map(rows: loadStrings(3))
|
||
|
|
||
|
|
||
|
proc partOne(dX, dY: int): int =
|
||
|
var count, x, y = 0
|
||
|
while y < data.rows.len:
|
||
|
if data[x, y]:
|
||
|
count += 1
|
||
|
x += dX
|
||
|
y += dY
|
||
|
result = count
|
||
|
|
||
|
|
||
|
proc partTwo(): int =
|
||
|
let slopes = @[
|
||
|
(1, 1),
|
||
|
(3, 1),
|
||
|
(5, 1),
|
||
|
(7, 1),
|
||
|
(1, 2),
|
||
|
]
|
||
|
|
||
|
var total = 1
|
||
|
for slope in slopes:
|
||
|
total *= partOne(slope[0], slope[1])
|
||
|
result = total
|
||
|
|
||
|
|
||
|
when isMainModule:
|
||
|
echo "One: ", partOne(3, 1)
|
||
|
echo "Two: ", partTwo()
|