Quant
Uiua
Adapting the part one solution for part two took me longer than part one did today, but I didn’t want to change much anymore.
I even got scolded by the interpreter to split the evaluating line onto multiple ones because it got too long.
Can’t say it’s pretty but it does it’s job ^^’
Run with example input here
PartOne ← (
&rs ∞ &fo "input-8.txt"
⟜(▽¬∈".\n".◴)
⊜∘≠@\n.
:¤⟜(:¤-1△)
≡(□⊚⌕)
◴/◇⊂⍚(≡(-:⟜-°⊟)⧅≠2)
⧻▽¬:⊙(/+⍉+)⟜⊓><,0
)
PartTwo ← (
&rs ∞ &fo "input-8.txt"
⟜(▽¬∈".\n".◴⟜¤
▽:⟜≡(>1⧻⊚⌕)
)
⊜∘≠@\n.
:¤⟜(:¤-1△)
≡(□⊚⌕)
⊸⍚(
⧅≠2⊙¤
≡(:¤⟜-°⊟
⍢(⊙⊂⟜-⊙⊸⊢
| ⋅(=0/++⊓><,0⊢))
□⊙◌◌
)
)
◴/◇⊂/◇⊂
⧻▽¬:⊙(/+⍉+)⟜⊓><,0
)
&p "Day 8:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
Uiua
Credits to @mykl@lemmy.world for the approach of using reduce
and also how to split the input by multiple characters.
I can happily say that I learned quite a bit today, even though the first part made me frustrated enough that I went searching for other approaches ^^
Part two just needed a simple modification. Changing how the input is parsed and passed to the adapted function took longer than changing the function itself actually.
Run with example input here
PartOne ← (
&rs ∞ &fo "input-7.txt"
⊜□≠@\n.
≡◇(⊜□≠@:.)
≡⍜⊡⋕0
≡⍜(°□⊡1)(⊜⋕≠@ .)
⟜(⊡0⍉)
# own attempt, produces a too low number
# ≡(:∩°□°⊟
# ⍣(⍤.◡⍣(1⍤.(≤/×)⍤.(≥/+),,)0
# ⊙¤⋯⇡ⁿ:2-1⊸⧻
# ⊞(⍥(⟜⍜(⊙(↙2))(⨬+×⊙°⊟⊡0)
# ↘1
# )⧻.
# ⍤.=0⧻.
# )
# ∈♭◌
# )0)
# reduce approach found on the programming.dev AoC community by mykl@lemmy.world
≡(◇(∈/(◴♭[⊃(+|×)]))⊡0:°⊂)
°□/+▽
)
PartTwo ← (
&rs ∞ &fo "input-7.txt"
⊜(□⊜⋕¬∈": ".)≠@\n.
⟜≡◇⊢
≡◇(∈/(◴♭[≡⊃⊃(+|×|⋕$"__")]):°⊂)
°□/+▽
)
&p "Day 7:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
Great explanation :D
I understand what I called black magic before now. I did wonder what something other than a concatenation would do in that place but didn’t consider that it might be just that because it looked so complicated.
I wasn’t able to get it running with ⋕$"__"
either, though I’d assume it’s a bug caused by how the numbers get passed around or something. The day uiua has a stable release will be glorious
Thanks to your solution I learned more about how to use reduce
:D
My solution did work for the example input but not for the actual one. When I went here and saw this tiny code block and you saying
This turned out to be reasonably easy
I was quite taken aback. And it’s so much better performance-wise too :D (well, until part 2 comes along in my case. Whatever this black magic is you used there is too high for my fried brain atm)
Uiua
This one was nice. The second part seemed quite daunting at first but wasn’t actually that hard in the end.
Run with example input here
Row ← ⌕ "XMAS"
RevRow ← ⌕"SAMX"
Sum ← /+/+
Count ← +∩Sum⊃Row RevRow
PartOne ← (
&rs ∞ &fo "input-4.txt"
⊜∘≠@\n.
⊙+⟜∩Count⟜⍉ # horizontal and vertical search
⟜(/+⧈(Count⍉≡⬚@ ↻⇡⧻.)4)
/+⧈(Count⍉≡⬚@ ↻¯⇡⧻.)4
++
)
Mask ← °⊚×2⇡5
# Create variations of X-MAS
Vars ← (
["M S"
" A "
"M S"]
≡♭[∩⟜⍉]≡⇌.
Mask
⊏0⊞▽¤
)
PartTwo ← (
&rs ∞ &fo "input-4.txt"
⊜∘≠@\n.
⧈(/+♭⊞≍⊙¤Vars▽Mask♭)3_3
Sum
)
&p "Day 4:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
No worries, it does seem a lot less difficult in hindsight now, my mind just blanked at what I expected to be a lot more code :))
That performance improvement is amazing, I’ll definitely take a look at how that works in detail later. Just gotta recover from the mental stretch gymnastics trying to remember the state of the stack at different code positions