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
Hell yeah!
β»ββ»οΈ΅ (Β°β‘Β°)/ οΈ΅ β»ββ»
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
Glad to hear that my attempts at de-spaghettifying worked to some degree at least :D
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
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
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
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
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
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
A solution in malbolge would be amazing and also kinda terrifying