AoC day 2 solution

⎕IO←0
find_in←{
⍺←0 0
t←⍺
t[1]+←1
⍺[1]>99:⍺{t[0]+←1 ⋄ t[1]←¯1 ⋄ t find_in ⍵}⍵
in←⍵
in[0;1 2]←t[0 1]
19690720=0⌷intcode in:t
t∇in
}
intcode←{
⍺←0
one←{r←,⍵ ⋄ r[⍵[⍺;3]]←r[⍵[⍺;1]]+r[⍵[⍺;2]] ⋄ (⍺+1)intcode(⍴⍵)⍴r}
two←{r←,⍵ ⋄ r[(⍵[⍺;3])]←r[⍵[⍺;1]]×r[⍵[⍺;2]] ⋄ (⍺+1)intcode(⍴⍵)⍴r}
1=0⌷⍵[⍺;]:⍺ one ⍵
2=0⌷⍵[⍺;]:⍺ two ⍵
99=0⌷⍵[⍺;]:,⍵
}
parse←{{((⌈4÷⍨⍴⍵),4)⍴⍵}⍎¨','(≠⊆⊢)⍵}
in_1←in←parse ⊃⊃⎕nget '02.input' 1
in_1[0;1 2]←12 2
pt1←0⌷intcode in_1
pt2←find_in in

re: AoC day 2 solution (w/ solution from Reddit)

Hmm, yep, as I suspected, my approach was *not* very elegant. Here's a much cleaner version from the solution thread on Reddit:

```
⎕IO←0
s←⍎¨','(≠⊆⊢)⊃⊃⎕NGET'p02.txt' 1
f←{
i←0⊣p[1 2]←⍵⊣p←s
⊃p⊣{i+←4⊣a b c d←p[i+⍳4]
p[d]←(a-1)⌷p[b](+,×)p[c]}⍣{
99=i⌷p
}⊢0
}

⍝ part 1:
f 12 2

⍝ part 2
+/100 1×∊{
0::⍬
19690720=f⍵:⍵

}¨1+,⍳99 99
```

Now to figure out how that works!

re: AoC day 2 revised/shorter solution

⎕IO←0
find←{
⍺←0
in←(⊃⍺⌷,(⍳100)∘.,⍳100) set ⊃0⌷⍵
(⊃1⌷⍵)=0⌷intcode in:in[1 2]
(⍺+1)∇in (⊃1⌷⍵)
}
set←{s←⍵ ⋄ s[1 2]←⍺[0 1] ⋄ s}
intcode←{
⍺←0 ⋄ s←state←⍵
(a b c)←in[⍺+1],in[⍺+2],in[⍺+3]
⍺≥0⌷⍴⍵:'ERR: no HALT opcode'
1=⍺⌷⍵:⍺{s[c]←⍵[a]+⍵[b] ⋄ (⍺+4)intcode s}⍵
2=⍺⌷⍵:⍺{s[c]←⍵[a]×⍵[b] ⋄ (⍺+4)intcode s}⍵
99=⍺⌷⍵:,⍵
'ERR: Unknown opcode'
}
in←⍎¨','(≠⊆⊢) ⊃⊃⎕nget '02.input' 1
pt1←0⌷intcode 12 2 set in
pt2←find in 19690720

re: AoC day 2 revised/shorter solution

@codesections ...what the fuck is this?

re: AoC day 2 revised/shorter solution

> ...what the fuck is this?

:D :D :D

Honestly, half the fun of coding in is getting that reaction.

And probably more than half the fun of tooting about/in APL. (Well, plus, few other languages are concise enough to fit in a toot)

Here's a version of the same code in a gist if you'd like to see it with syntax highlighting:
gist.github.com/codesections/0

re: AoC day 2 revised/shorter solution

@codesections Didn't help at all :P

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.