about summary refs log tree commit diff
path: root/day04.ijs
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-05 17:44:23 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-05 17:44:23 +0100
commita2037e84ec9dd2ee9ad1528d94a5e4451a0fd41a (patch)
tree2d420888ff5b9aa35092007e0792df6549dc2df4 /day04.ijs
parentd20125b66e35d3380e4e39c4a75fbb6604b6cc00 (diff)
downloadadventofcode2020-a2037e84ec9dd2ee9ad1528d94a5e4451a0fd41a.tar.gz
adventofcode2020-a2037e84ec9dd2ee9ad1528d94a5e4451a0fd41a.tar.xz
adventofcode2020-a2037e84ec9dd2ee9ad1528d94a5e4451a0fd41a.zip
day04
Diffstat (limited to 'day04.ijs')
-rw-r--r--day04.ijs27
1 files changed, 27 insertions, 0 deletions
diff --git a/day04.ijs b/day04.ijs
new file mode 100644
index 0000000..83e779a
--- /dev/null
+++ b/day04.ijs
@@ -0,0 +1,27 @@
+d =: ':' splitstring&> '\w+:\S+'&rxall&> cutpara 1!:1 <'day04'
+
+look =: 4 : 0
+{. > }. (y,('';'0')) {~ ({."1 y) i. < x
+)
+
+inr =: 4 : '(-: /:~) ({. x), y, (}. x)'
+
+ks =: 0 = [: # (<;._1 ' byr iyr eyr hgt hcl ecl pid')&-.
+
+hv =: 3 : 0
+(>(('cm';'in') i. <_2 {. y) { 150 193;59 76; 1 0) inr ". _2 }. y
+)
+
+rv =: 3 : 0
+l =. ks {."1 y
+l =. l *. 1920 2002 inr ". 'byr' look y
+l =. l *. 2010 2020 inr ". 'iyr' look y
+l =. l *. 2020 2030 inr ". 'eyr' look y
+l =. l *. '#[0-9a-f]{6}' rxeq 'hcl' look y
+l =. l *. 'amb|blu|brn|gry|grn|hzl|oth' rxeq 'ecl' look y
+l =. l *. '[0-9]{9}' rxeq 'pid' look y
+     l *. hv 'hgt' look y
+)
+
++/ks"1 {."1 d   NB. 228
++/rv"2 d        NB. 175