-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday25.jq
More file actions
executable file
·35 lines (33 loc) · 982 Bytes
/
Copy pathday25.jq
File metadata and controls
executable file
·35 lines (33 loc) · 982 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
31
32
33
34
35
#!/usr/bin/env -S jq -Rs -f
def parse:
# return [is_key: bool, heights]
split("\n") | map(select(length > 0) | split(""))
| . as $split
| if $split[0][0] == "#" then
# have lock
[false, (transpose | map(index(".") - 1))]
else
# have key
[true, (transpose | map(length - index("#") - 1))]
end;
split("\n\n") | (.[0] | split("\n") | length - 1) as $height | map(parse)
| . as $objects
# [index, locks, keys]
| [0, [], []] | until($objects[.[0]] | not;
.[0] as $i
| $objects[$i] as $obj
| if $obj[0] then
.[1] as $locks
| .[2] | . + [$obj[1]]
| [$i + 1, $locks, .]
else
.[2] as $keys
| .[1] | . + [$obj[1]]
| [$i + 1, ., $keys]
end
) | .[1:] | . as [$locks, $keys]
| reduce (range($locks | length) as $l | range($keys | length) | [$l, .]) as [$lock, $key] (0;
if all([$locks[$lock], $keys[$key]] | transpose[]; add < $height) then
. + 1
end
)