Skip to content

Instantly share code, notes, and snippets.

@xpqz
Last active December 4, 2020 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpqz/d40cf54cb517b2360c5fabba18391051 to your computer and use it in GitHub Desktop.
Save xpqz/d40cf54cb517b2360c5fabba18391051 to your computer and use it in GitHub Desktop.
AoC 2020 Day04 Dyalog APL
'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
@jayfoad
Copy link

jayfoad commented Dec 4, 2020

Simpler: part2←{∧/{(⍎⍺)⍵}/(2÷⍨≢⍵)2⍴⍵}¨part1/pp

@xpqz
Copy link
Author

xpqz commented Dec 4, 2020

Thanks, @jayfoad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment