Last active
December 4, 2020 14:00
-
-
Save xpqz/d40cf54cb517b2360c5fabba18391051 to your computer and use it in GitHub Desktop.
AoC 2020 Day04 Dyalog APL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'segs'⎕CY'dfns' | |
DAY04←↑,/¨{data⊂⍨1,2≠/⍵}0≠≢¨data←' :'∘segs¨⊃⎕NGET'4'1 | |
eyr←(2020∘≤∧≤∘2030)⍎ | |
iyr←(2010∘≤∧≤∘2020)⍎ | |
byr←(1920∘≤∧≤∘2002)⍎ | |
ecl←'amb' 'blu' 'brn' 'gry' 'grn' 'hzl' 'oth'∊⍨⊂ | |
pid←≢'^\d{9}$'⎕S'' | |
hcl←≢'^#[a-f0-9]{6}$'⎕S'' | |
cid←{1} | |
hgt←≢'^(((59|6[0-9]|7[0-6])in)|((1[5-8][0-9]|19[0-3])cm))$'⎕S'' | |
part1←'byr' 'iyr' 'eyr' 'hgt' 'hcl' 'ecl' 'pid'∘(∧/∊)¨pp←(0≠≢¨DAY04)/DAY04 | |
⍝ part2←{∧/⍎¨{⍺,' ','''',⍕⍵,''''}/(2÷⍨≢⍵) 2⍴⍵}¨part1/pp | |
part2←{∧/{(⍎⍺)⍵}/(2÷⍨≢⍵)2⍴⍵}¨part1/pp ⍝ From Jay Foad's suggestion below | |
⊢result←+/¨part1 part2 | |
assert 256 198≡result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simpler:
part2←{∧/{(⍎⍺)⍵}/(2÷⍨≢⍵)2⍴⍵}¨part1/pp