Quant

joined 2 weeks ago
[–] [email protected] 1 points 2 weeks ago

Uiua

Took me a bit longer to get this one but still quite simple overall.
Spent quite some time on getting to know the try and assert operators better.

Run with example input here

# Get the indices matching the ascending/
# descending criteria
CheckAsc ← β‰‘Β°β–‘βš(⍣(⊸⍀.≍⍆.)⍣(⊸⍀.β‰β‡Œβ†.)0)
# Get the indices matching the distance criteria
CheckDist ← β‰‘Β°β–‘βš(⍣(⊸⍀.β‰ 1∈:0)0Γ—βŠ“β‰₯≀1,3⌡⧈-)
Split     ← βŠ™(β–½β‰ 1)β–½,,

PartOne ← (
  &rs ∞ &fo "input-2.txt"
  ⊜(β–‘βŠœβ‹•β‰ @ .)β‰ @\n.
  CheckAsc.
  β–½
  CheckDist
  ⧻⊚
)

PartTwo ← (
  &rs ∞ &fo "input-2.txt"
  ⊜(β–‘βŠœβ‹•β‰ @ .)β‰ @\n.
  CheckAsc.
  Split
  CheckDist.
  Split
  βŠ™(βŠ‚)
  ⧻
  :
  ⍚(≑(β–½:°⊟)⍜€⊞⊟:β‰ 1⊞=.⇑⧻.)
  ≑(⧻⊚CheckDistβ–½CheckAsc.Β°β–‘)
  +β§»β—΄βŠš
)

&p "Day 2:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
[–] [email protected] 1 points 2 weeks ago* (last edited 2 weeks ago)

Uiua

Decided to try and use Uiua for each day this year. At least I'm not the only one to get this idea ^^

Run with example input here

PartOne ← (
  &rs ∞ &fo "input-1.txt"
  ⊜(βŠœβ‹•β‰ @ .)β‰ @\n.
  ≑⍆⍉
  ⌡/-
  /+
)

PartTwo ← (
  &rs ∞ &fo "input-1.txt"
  ⊜(βŠœβ‹•β‰ @ .)β‰ @\n.
  βŠ’βŸœβŠ£β‰
  0
  ⍒(+βŠ™(:βŠ™(Γ—β§»βŠšβ—‘βŒ•)β†˜1⟜⊒)|β‹…(β‰ 0⧻))
  βŠ™(β—Œβ—Œ) # just cleaning up the stack
)

&p "Day 1:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo

view more: β€Ή prev next β€Ί