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

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

A solution in malbolge would be amazing and also kinda terrifying

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

Hell yeah!

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

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

Glad to hear that my attempts at de-spaghettifying worked to some degree at least :D

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

Uiua, forgot to put that in the post

47
submitted 1 month ago* (last edited 1 month ago) by Quant@programming.dev to c/advent_of_code@programming.dev

I don't remember exactly what this difference caused but I do remember it being very annoying to debug.

Edit: the language used is Uiua

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

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)

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

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
[-] Quant@programming.dev 2 points 1 month 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
view more: next β€Ί

Quant

joined 1 month ago