-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathday_4.lua
More file actions
30 lines (23 loc) · 789 Bytes
/
Copy pathday_4.lua
File metadata and controls
30 lines (23 loc) · 789 Bytes
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
local eio = require "libs.eio"
local profile = require "libs.profile"
local input = eio.lines()
local printf = eio.printf
local match = string.match
profile.start()
local function isOneRangeSubsetOfOther (a, b, c, d)
return (a <= c and d <= b) or (c <= a and b <= d)
end
local function areOverlapping (a, b, c, d)
return not (b < c or d < a)
end
local count1 = 0
local count2 = 0
for i = 1, #input do
local a, b, c, d = match(input[i], "(%d+)-(%d+),(%d+)-(%d+)")
a, b, c, d = tonumber(a), tonumber(b), tonumber(c), tonumber(d)
count1 = count1 + (isOneRangeSubsetOfOther(a, b, c, d) and 1 or 0)
count2 = count2 + (areOverlapping(a, b, c, d) and 1 or 0)
end
printf("Part 1: %i\n", count1)
printf("Part 2: %i\n", count2)
return count1, count2, profile.finish()