skissue

joined 2 weeks ago
[–] skissue@programming.dev 2 points 2 weeks ago

Uiua

My silly part one solution, because I have no idea how to do part two (this is usually the difficulty at which I bow out, but I want to try actually expanding my knowledge this year!).

Parse         ← ⊜(⊜⋕⊸≠@,)⊸≠@\n
CornerClosest ← ⊏⊢⍏⊸≡⌞(/+ⁿ2-)
Big           ← 9999999
RectSize      ← /×+1⌵-
Part₁ ← (
  ∩⌟∩⌟CornerClosest 0_0 1000000_1000000 Big_0 0_Big
  ↥∩RectSize
)

$ 7,1
$ 11,1
$ 11,7
$ 9,7
$ 9,5
$ 2,5
$ 2,3
$ 7,3

&fras "9.txt"
Part₁ Parse
[–] skissue@programming.dev 3 points 2 weeks ago

Uiua

Heavily ~~copied~~ ahem, inspired by @mykl@lemmy.world's solution :)

Parse     ← °⊂ ▽⊸≡/↥≠@.⊜∘⊸≠@\n
Flow      ← +⊃(/+≡↻1_¯1¤×|×⊙¬)
Propagate ← ˜∧(⊸˜Flow)
Part₁     ← /+♭↧ ⊸Propagate
Part₂     ← /+⊣Propagate ⊙(˜⊂0)

$ .......S.......
$ ...............
$ .......^.......
$ ...............
$ ......^.^......
$ ...............
$ .....^.^.^.....
$ ...............
$ ....^.^...^....
$ ...............
$ ...^.^...^.^...
$ ...............
$ ..^...^.....^..
$ ...............
$ .^.^.^.^.^...^.
$ ...............
&fras "7.txt"

⊃(Part₁|Part₂) Parse
[–] skissue@programming.dev 3 points 2 weeks ago (1 children)

Man, your solution is so much cleaner than the hell I was trying (and failing) to coerce into doing what I wanted. Curse my inability to think bottom-up and array-oriented at the same time!

[–] skissue@programming.dev 6 points 2 weeks ago (4 children)

Uiua

I'm new to Uiua, so probably not the best way to express the solution!

ParseRows ← (
  ⊜∘⊸≠@\n
  ⍜⇌°⊂ # Get the row of operations.
)
ParseOperations ← ⊜⊢⊸≠@\s
SumCalculations ← (
  ≡(
    ⍣(◇/×°@*
    | ◇/+°@+
    )
  )
  /+
)

Part₁ ← (
  ParseRows
  ⊓(ParseOperations
  | ⍉ ≡(⊜⋕⊸≠@\s) # Parse columns.
  )
  SumCalculations
)

Part₂ ← (
  ParseRows
  ⊓(ParseOperations
  | ⊜(□≡(⋕▽⊸≠@\s)) ≡/↥⊸≠@\s⍉ # Parse numbers.
  )
  SumCalculations
)

&fras "6.txt"
⊃Part₁ Part₂