@@ 12,6 12,7 @@ Languages used
--------------
- [C11](https://en.wikipedia.org/wiki/C11)
+- [Kuroko](https://kuroko-lang.github.io) (version 1.3.0)
- [Lua](https://www.lua.org/) (version 5.4)
- [Python](https://python.org) (version 3.10, most programs probably work all
the way down to version 3.6)
@@ 2,14 2,22 @@
from fileio import stdin
-let count = 0
+def parse_line(line):
+ let l, r = line.strip().split(",")
+ let ll, lr = map(int, l.split("-"))
+ let rl, rr = map(int, r.split("-"))
+ return set(range(ll, lr + 1)), set(range(rl, rr + 1))
+
+let count1, count2 = 0, 0
for line in stdin.readlines():
- let a, b = line.strip().split(",")
- let al, ar = map(int, a.split("-"))
- let bl, br = map(int, b.split("-"))
+ let l, r = parse_line(line)
+ let c = l & r
- if (al <= bl and br <= ar) or (bl <= al and ar <= br):
- count += 1
+ if c == l or c == r:
+ count1 += 1
+ if len(c) > 0:
+ count2 += 1
-print(count)
+print("Part 1:", count1)
+print("Part 2:", count2)