adventofcode

https://adventofcode.com/
Log | Files | Refs

puzzle_2.apl (304B)


      1 #! /usr/bin/apl --script
      2 
      3 input← ⎕FIO[49] 'files/2.txt'
      4 
      5 x← { ⍵ { 1 ⍴ (⍺ = ⍵) × ⍎⍵[≢ ⍵] } ¨ input } ¨ 'fdu'
      6 
      7 y[1] × y[2] - (y← +/¨ x)[3] ⍝ part 1
      8 
      9 f← { 0 0 ⍺ ↓⍤3⍵ }
     10 +/z × +/(+⊢/1 f -1 f y) × z← ⊢/2 f⌽ y← ⊃ (⊂ ⍤1)⍉ ⊃ ⊃ x ⍝ part 2
     11 
     12 )OFF