Skip to content

Instantly share code, notes, and snippets.

@lokedhs
Last active December 8, 2021 16:53
Show Gist options
  • Save lokedhs/a97e1a0210f62f06eadc62183b0561be to your computer and use it in GitHub Desktop.
Save lokedhs/a97e1a0210f62f06eadc62183b0561be to your computer and use it in GitHub Desktop.
∇ solvePart1 {
content ← ⊃ {⍎¨ ↓ "^([0-9]+),([0-9]+) -> ([0-9]+),([0-9]+)$" regexp:finderror ⍵}¨ io:read "part05.txt"
⍝ Compute size of array
width ← 1+⌈/,content[;0 2]
height ← 1+⌈/,content[;1 3]
xcoords ← ((⍋⊇⊢)⍤1) content[;0 2]
ycoords ← ((⍋⊇⊢)⍤1) content[;1 3]
checkCoords ⇐ {
(x1 x2 y1 y2) ← ⍺
((x1=x2) ∨ y1=y2) × ∧/ (y1 x1 ≤ ⍵) ∧ y2 x2 ≥ ⍵
}
+/, 1 < +⌿ ({(⊂⍵) checkCoords¨parallel ⍳ height width}⍤1) xcoords,ycoords
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment