-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution1.nim
53 lines (46 loc) · 990 Bytes
/
solution1.nim
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import std/[
algorithm,
bitops,
deques,
json,
math,
re,
sequtils,
sets,
strformat,
strutils,
tables,
sugar,
]
proc part1(input: string): int =
let lines = input.split("\n")
var a = lines[0].split(" ")[1].parseInt
var b = lines[1].split(" ")[1].parseInt
var d = lines[2].split(" ")[1].parseInt
for _ in 0 ..< d:
let c = a
a += b
b = c
var c = lines[16].split(" ")[1].parseInt
d = lines[17].split(" ")[1].parseInt
a += c * d
a
proc part2(input: string): int =
let lines = input.split("\n")
var a = lines[0].split(" ")[1].parseInt
var b = lines[1].split(" ")[1].parseInt
var d = lines[2].split(" ")[1].parseInt
var c = lines[5].split(" ")[1].parseInt
d += 7
for _ in 0 ..< d:
c = a
a += b
b = c
c = lines[16].split(" ")[1].parseInt
d = lines[17].split(" ")[1].parseInt
a += c * d
a
when isMainModule and not defined(test):
let input = readAll(stdin).strip
echo part1(input)
echo part2(input)