-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.nim
79 lines (69 loc) · 1.41 KB
/
template.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
let doc = """
Advent of code {}, day {}
Usage:
do [options] [<input>]
Options:
-h --help Show this help message.
-v --verbose Show extra information.
-t --test Use test points
--part2 Process for part 2
"""
import re
import docopt
import terminal
import streams
import strutils
import sequtils
import algorithm
import tables
import sets
import lists
import typetraits
import strformat
var
filename = ""
let args = docopt(doc, version = "0.1.0")
if args["--test"]:
filename = "test.txt"
else:
filename = "input.txt"
if args["<input>"]:
filename = $args["<input>"]
type
ClayType = enum
Vertical,
Horizontal
Clay = object
kind: ClayType
x, x2, y, y2: int
var
file = newFileStream(filename, fmRead)
line = ""
inputData = newSeq[Clay]()
# x=495, y=2..7
# y=7, x=495..501
if not isNil(file):
while file.readLine(line):
var matches: array[3, string]
if match(line, re"^y=(\d+), x=(\d+)..(\d+)$", matches, 0):
var
e: Clay
i = matches.map(parseInt)
e.kind = Horizontal
e.y = i[0]
e.x = i[1]
e.x2 = i[2]
inputData.add(e)
if match(line, re"^x=(\d+), y=(\d+)..(\d+)$", matches, 0):
var
e: Clay
i = matches.map(parseInt)
e.kind = Vertical
e.x = i[0]
e.y = i[1]
e.y2 = i[2]
inputData.add(e)
file.close()
if args["--verbose"]:
for e in inputData:
echo $e