Skip to content

Instantly share code, notes, and snippets.

@lokedhs
Last active December 7, 2021 16:28
Show Gist options
  • Save lokedhs/875467cebc8b6bca55bad27ab4e2bb21 to your computer and use it in GitHub Desktop.
Save lokedhs/875467cebc8b6bca55bad27ab4e2bb21 to your computer and use it in GitHub Desktop.
∇ solvePart1 {
stringToNumbers ⇐ {⍎¨ ⍵ ⊂⍨ ⍺≠⍵}
filecontent ← io:read "part04.txt"
num ← @, stringToNumbers ↑filecontent
b ← ⊃ {⊃ (↑" ") stringToNumbers¨ ⍵}¨ v ⊂⍨ (⊂⍬) ≢¨ v←2↓filecontent
⍝ Compute the time at which each cell is picked, 0 means that the cell was not picked
indexed ← (1+⍳≢num) ×⌺ (⍴b)⍴1
res ← +⌿ indexed × num=⌺b
highest ← ⌊/ (⌊/⌈/[2] res) ,[0.5] ⌊/⌈/[1] res
winning ← b[indexHigh←↑⍋highest;;]
numbersPicked ← highest[indexHigh]
unmarkedValues ← winning × ~winning ∊ num[⍳numbersPicked]
num[numbersPicked-1] × +/,unmarkedValues
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment