#day 1 +/INPUT {1↑{((⍵⍳⍵)≠⍳⍴⍵)/⍵}+⍀0,1000000⍴⍵}INPUT #day 2 ⍝ part 1 dyalog ×/¨+/{0<+/⍉{{{(2=⍵),(3=⍵)}2⊃⍵}⍺,≢⍵}⌸⍵}¨ ⍝ part 2 ⍝ boolean if two vecs are one item off 'abc' {(¯1+⍴⍵)=+/⍺=⍵} 'abz' ⍝ need to select only matching letters here 'abc' {(1+(¯1+⍴⍵)=+/⍺=⍵)⌷0 (⍺=⍵)} 'abz' ⍝ Remove characters!!! {(~⍵∊' ')/⍵}'1 2' ⍝ Our dydactic solution fn 'abc' {(1+(¯1+⍴⍵)=+/⍺=⍵)⌷0 ⍵[{(~⍵∊0)/⍵}(⍺=⍵)×⍳⍴⍵]} 'abz' ONEOFF←{(1+(¯1+⍴⍵)=+/⍺=⍵)⌷0 ⍵[{(~⍵∊0)/⍵}(⍺=⍵)×⍳⍴⍵]} ⍝ now run permutations on each string ⊃1↑{(~⍵∊0)/⍵},{⍵ ∘.{(1+(¯1+⍴⍵)=+/⍺=⍵)⌷0 ⍵[{(~⍵∊0)/⍵}(⍺=⍵)×⍳⍴⍵]} ⍵} INPUT ]BOXING ¯29 ⍝ load a file INPUT←⎕FIO[49]'data/2018.3.txt' # DAY 3 ⍝ part 1 DIMS←{⊃1↓⍎¨⍵}¨{(1≠⍵∊' #@,:x') ⊂ ⍵}¨INPUT GRID←1000 1000⍴0 ⍝ matrix of indicies into the grid {((2↓⍵)⍴⊂(2↑⍵))+⍳⍴(2↓⍵)⍴0} 3 4 5 2 ⍝ inc a coord {GRID[1⌷⍵;2⌷⍵]←1+GRID[1⌷⍵;2⌷⍵]}3 4 ⍝ tally {+/+/⍵>1}GRID ⍝ one liner {+/+/⍵>1}GRID⋄{{GRID[1⌷⍵;2⌷⍵]←1+GRID[1⌷⍵;2⌷⍵]}¨{((2↓⍵)⍴⊂(2↑⍵))+⍳⍴(2↓⍵)⍴0}⊃⍵}¨DIMS⋄GRID←1000 1000⍴0 ⍝ part 2 DIMS←{⊃⍎¨⍵}¨{(1≠⍵∊' #@,:x') ⊂ ⍵}¨INPUT ⍝ initialize SET←0⍴0 GRID←1000 1000⍴0 ⍝ set functions HAS←{+/⍺∊⍵} DSTNCT←{((⍵⍳⍵)=⍳⍴⍵)/⍵} CONJ←{SET←(SET,⍵)} ⍝ IMPL INDGRID←{((2↓⍵)⍴⊂(2↑⍵))+⍳⍴(2↓⍵)⍴0} ⍝ given an id and coords, if coord allready has id, add both to SET ⍝ then write new id to coords WRITE←{GRID[2⌷⍵;3⌷⍵]←1⌷⍵} ⍝8 4 4 ⍝ if loc != 0 CONJ loc value and new value SCORD←{CONJ ⊃(((1⌷⍵) GRID[2⌷⍵;3⌷⍵]) 0)[((0=GRID[2⌷⍵;3⌷⍵])+1)]} ⍝6 4 3 DIMS←10↑DIMS ⍝ create the coord rect matrix, then record and check ⍴{{WRITE ⍵,SCORD ⍵}¨(1⌷⍵),¨INDGRID 1↓⍵}¨DIMS ⍝ 55 3 4 5 2 ⍝ make an actual set SET←DSTNCT SET ⍝ find id not in SET +/{⍵×0=SET HAS ⍵}¨1↑¨DIMS