-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday04_1.nim
53 lines (43 loc) · 1.27 KB
/
day04_1.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 os
if paramCount() != 1:
echo "Usage: ./dayXX <input file>"
quit(1)
let filename = paramStr(1)
if not fileExists(filename):
echo "File not found: ", filename
quit(1)
## RUN: TEST
# RUN: FULL
import std/strutils
proc biject_string*(s: string, d: char): tuple =
let split = s.split(d);
assert split.len == 2
result = (split[0], split[1])
# Have a look at https://stackoverflow.com/a/63802982/2531987 too ???
var data: seq[((int, int), (int, int))] = @[]
for line in lines(filename):
let
split_line = biject_string(line, ',')
elf1 = biject_string(split_line[0], '-')
elf2 = biject_string(split_line[1], '-')
parsed = (
(elf1[0].parseInt, elf1[1].parseInt),
(elf2[0].parseInt, elf2[1].parseInt)
)
data.add(parsed)
var count: int = 0
for (elf1, elf2) in data:
if elf1[0] <= elf2[0] and elf1[1] >= elf2[1]:
count += 1
elif elf2[0] <= elf1[0] and elf2[1] >= elf1[1]:
count += 1
echo count
# var a: array[3, char] = ['a', 'b', 'c'];
# # var a: set[char] = {'a', 'b', 'c'};
# echo a;
# var ep = cast[ByteAddress](addr(a));
# for j in 0..len(a)-1:
# # echo a[j];
# # echo ord(a[j]);
# let b: uint8 = cast[ptr uint8](ep + j)[];
# echo b, " ", char(b)