Follow

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 

Not supper happy with how verbose this turned out to be – it's only day 2, and I already had to strip out the error handling code to fit in a toot.

Maybe I'll be able to be a bit more concise tomorrow…

Show thread

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!

Show thread

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

Show thread

AoC day 2 solution 

@codesections Your mom was shouting into the phone while you uploaded that on your 300 bps modem?

AoC day 2 solution 

@codesections oh wow, that... looks so alien! seems that some of those characters don't even render correctly though xD

@Matter

> oh wow, that... looks so alien!

Yeah, is fun like that :D

> seems that some of those characters don't even render correctly though xD

How many? The code contains two quads, ⎕ (unicode-table.com/en/2395/) and four squish quads, ⌷ (unicode-table.com/en/2337/), both of which look a lot like the characters that are sometimes displayed when a font is missing a glyph, so it might just be those you're seeing.

@codesections Oh OK then it does render correctly. Been conditioned to think boxes mean I don't have the right font I guess 🤷

re: AoC day 2 revised/shorter solution 

@codesections ...what the fuck is this?

re: AoC day 2 revised/shorter solution 

@brandon

> ...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

Sign in to participate in the conversation
Fosstodon

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