-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04.q
More file actions
21 lines (18 loc) · 723 Bytes
/
04.q
File metadata and controls
21 lines (18 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//--- Day 4: Passport Processing ---
p:{(0,where 0=count each x) _ x} read0 `:input/04.txt
t:raze {[x;y] update id:y from (flip `f`v!"S*"$flip ":"vs'" "vs" "sv x where 0<count each x) }'[;til count p] p
/ mandatory columns
m:`byr`iyr`eyr`hgt`hcl`ecl`pid
/ filter on mandatory columns
count exec distinct id from select from t where f in m, 7 = (count;i) fby id
/ 230
/ pivot
pv:exec m#(f!v) by id:id from t
/ cast columns
pv:update "J"$byr, "J"$iyr, "J"$eyr, `$ecl from pv
/ select
count select from pv
where byr within 1920 2002, iyr within 2010 2020, eyr within 2020 2030,
{ within["J"$-2_x;] $["cm"~-2#x;150 198;59 76] } each hgt,
"#"~'first each hcl, ecl in `amb`blu`brn`gry`grn`hzl`oth, 9=count each pid
/156