[-] Quant@programming.dev 2 points 1 week ago

That's also possible, though I've had cases where putting a ? before a function changed the output to what I expected instead of doing something else.
This only happened in the online pad and seems to have been fixed by reloading the tab but I've taken to call any such behavior a bug now :D
Especially in this case because β‹•"1019" should at least not throw a "invalid float literal" error.

Though if you ever find another explanation I'd be happy to read it ^^

(I'm going to 'investigate' some more because I had this error a few times but I don't remember the circumstances and solution anymore)

[-] Quant@programming.dev 3 points 1 week ago

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

[-] Quant@programming.dev 3 points 1 week ago

You can actually use (singular) emojis as variable names. According to the documentation, they won't be be used as glyphs so you don't even have to worry about breaking changes of that kind :D

[-] Quant@programming.dev 2 points 1 week ago

Hell yeah!

┻━┻︡ (Β°β–‘Β°)/ οΈ΅ ┻━┻

[-] Quant@programming.dev 2 points 1 week ago

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

[-] Quant@programming.dev 1 points 1 week ago

Uiua

Part one was simple enough. Part two nearly made me give up.
Part two has the most ugly and least performant code I've made in uiua so far but it gets the job done and that's all I care about for now.

Run with example input here

RotateClock ← (
  βŠ™βŠ™(β‰β‡Œ)
  βŠ™(β‡Œβœ(⊑0)(-βŠ™(⧻⊑0.)+1))
  ↻¯1
)

RotateCounter ← (
  βŠ™βŠ™(β‡Œβ‰)
  βŠ™(⍜(⊑0)(-βŠ™(⧻.)+1)β‡Œ)
  ↻1
)

NewPos ← (
  βŠ™βœ(βŠ™βŠ‘:)(-1+βŠ™(βŠ—@#)βŸœβ†˜βŠ™.)⟜°⊟
  ⍜(⊑1)β‹…
)

MarkPath ← (
  RotateClock
  ⍒( # replace characters up til next '#'
    βŠ™(βŠ™βœ(β†˜βŠ™βŠ‘:)(⍜(↙)(β–½:@^⧻)βŠ—@#.)⟜°⊟
      NewPos
    )
    RotateCounter
  | β‹…(β‰ 0⊑0))
  β—Œβ—Œ
)

PartOne ← (
  &rs ∞ &fo "input-6.txt"
  βŠœβˆ˜β‰ @\n.
  # maybe make compatible with
  # non-up facing inputs
  β™­βŠš=@^.
  [0 1 2 3]
  MarkPath
  &fwa "test.txt" json.
  /+/+=@^
)

PartTwo ← (
  &rs ∞ &fo "input-6.txt"
  βŠœβˆ˜β‰ @\n.
  # maybe make compatible with
  # non-up facing inputs
  β™­βŠš=@^.
  [0 1 2 3]
  β—‘MarkPath
  βŠ™::
  # rotate the field to match the intital state
  βŠ™βŠ™(
    βŠ™(⊚=@#)
    ⍒(β‡Œβ‰|Β¬β‰βŠš=@#)
    βŠ™β—Œ
  )
  βŠ™βŠ™(⊚=@^.)
  βŠ™βŠ™βŠ™Β€βˆ©Β€
  ⊞(βŠ™βŠ™(βœβŠ‘β‹…@#)
    RotateClock
    βŠ™NewPos
    €¯1_¯1_¯1
    ⍒(βŠ™β—‘(βŠ‚βŠ’)
      βŠ‚
      βŠ™(RotateCounter
        βŠ™NewPos
      )
    | =1+βŠ™(βˆˆβ†˜1β‡Œ)β—‘β‹…(β‰ 129⊑2)βŠ™(βŠ‚βŠ’))
    # 129 = length of input array. Hardcoded because
    # the condition block doesn't seem to get the
    # input array passed to it so the length can't
    # be read dynamically
    βŠ™(βŠ‚βŠ’)
    ∈
    βŠ™β—Œ
  )
  /+β™­
)

&p "Day 6:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
[-] Quant@programming.dev 1 points 1 week ago

Uiua

This is the first one that caused me some headache because I didn't read the instructions carefully enough.
I kept trying to create a sorted list for when all available pages were used, which got me stuck in an endless loop.

Another fun part was figuring out to use memberof (∈) instead of find (βŒ•) in the last line of FindNext. So much time spent on debugging other areas of the code

Run with example input here

FindNext ← βŠ™(
  ⊑1⍉,
  βŠƒβ–½(β–½Β¬)⊸∈
  βŠ™βŠ™(⊑0⍉.)
  :βŠ™(⟜(β–½Β¬βˆˆ))
)

# find the order of pages for a given set of rules
FindOrder ← (
  β—΄β™­.
  []
  ⍒(βŠ‚FindNext|β‹…(>1⧻))
  βŠ™β—ŒβŠ‚
)

PartOne ← (
  &rs ∞ &fo "input-5.txt"
  βˆ©Β°β–‘Β°βŠŸβŠœβ–‘Β¬βŒ•"\n\n".
  βŠ™(⊜(β–‘βŠœβ‹•β‰ @,.)β‰ @\n.β†˜1)
  ⊜(βŠœβ‹•β‰ @|.)β‰ @\n.

  βŠ™.
  Β€
  ⊞(β—‘(Β°β–‘:)
    ⟜:βŠ™(Β°βŠŸβ‰)
    =2+∩∈
    β–½
    FindOrder
    βŠΈβ‰Β°β–‘:
    βŠ™β—Œ
  )
  ≑◇(⊑⌊÷2⧻.)β–½β™­
  /+
)

PartTwo ← (
  &rs ∞ &fo "input-5.txt"
  βˆ©Β°β–‘Β°βŠŸβŠœβ–‘Β¬βŒ•"\n\n".
  βŠ™(⊜(β–‘βŠœβ‹•β‰ @,.)β‰ @\n.β†˜1)
  ⊜(βŠœβ‹•β‰ @|.)β‰ @\n.
  βŠ™.
  ⍜€⊞(
    β—‘(Β°β–‘:)
    ⟜:βŠ™(Β°βŠŸβ‰)
    =2+∩∈
    β–½
    FindOrder
    βŠΈβ‰Β°β–‘:
    βŠŸβˆ©β–‘
  )
  βŠ™β—Œ
  βŠƒ(⊑0)(⊑1)⍉
  ≑◇(⊑⌊÷2⧻.)▽¬≑°░
  /+
)

&p "Day 5:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
[-] Quant@programming.dev 2 points 1 week ago

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
[-] Quant@programming.dev 1 points 1 week ago

Uiua

Regex my beloved <3

Run with example input here

FindMul ← regex "mul\\((\\d+),(\\d+)\\)"

PartOne ← (
  &rs ∞ &fo "input-3.txt"
  FindMul
  /+≑(Γ—Β°βŠŸβ‹•βŠ1_2)
)

IdDont ← βŠ—β–‘"don't()"β™­

PartTwo ← (
  &rs ∞ &fo "input-3.txt"
  regex "mul\\(\\d+,\\d+\\)|do\\(\\)|don't\\(\\)"
  ⍒(IdDont.
    β†˜1βŠƒβ†˜β†™
    βŠ—β–‘"do()"β™­.
    βŠ‚β†˜1β†˜
  | IdDont.
    ≠⧻,
  )
  β–½β™­=0βŒ•β–‘"do()".
  ≑(Γ—Β°βŠŸβ‹•βŠ1_2β™­FindMul)β™­
  /+
)

&p "Day 3:"
&pf "Part 1: "
&p PartOne
&pf "Part 2: "
&p PartTwo
[-] Quant@programming.dev 1 points 1 week 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
[-] Quant@programming.dev 1 points 1 week ago* (last edited 1 week 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 β€Ί

Quant

joined 1 week ago