[–] 2 points 8 months ago

Uiua

I'm currently going through the 2025 Quests to learn Rust, committing great sins along the way.
Decided to take a shot at the third one with Uiua because it looked nice and simple, and it was. This may have been the fastest I've ever finished a complete quest :P

Run with example input

Code

I₁   ← "10,5,1,10,3,8,5,2,2"
Iβ‚‚   ← "4,51,13,64,57,51,82,57,16,88,89,48,32,49,49,2,84,65,49,43,9,13,2,3,75,72,63,48,61,14,40,77"
I₃   ← "4,51,13,64,57,51,82,57,16,88,89,48,32,49,49,2,84,65,49,43,9,13,2,3,75,72,63,48,61,14,40,77"
Prep ← βŠβŠΈβ–βŠœβ‹•βŠΈβ‰ @,
P₁   ← /+β—΄ Prep
Pβ‚‚   ← /+↙₋₂₀◴ Prep
P₃   ← +₁/β†₯⧆ Prep
⍚$"Part _: _" 1_2_3 [P₁I₁ Pβ‚‚Iβ‚‚ P₃I₃]
&pf /$$ _
     $$ _

  • source
  • [–] 1 point 11 months ago

    Uiua

    Part 1 only for now, probably not the most optimal solution (calculating all possible rectangles) but at least it's short ^^

    Run with example input

    ::spoiler Code

    $ 7,1
    $ 11,1
    $ 11,7
    $ 9,7
    $ 9,5
    $ 2,5
    $ 2,3
    $ 7,3
    # &fras "input-9.txt" β—Œ
    ⊜(βŠœβ‹•βŠΈβ‰ @,)βŠΈβ‰ @\n
    β§…<2
    ≑(/Γ—+₁-βŠƒβ†§β†₯°⊟)
    /β†₯
    

    :::

  • source
  • [–] 3 points 11 months ago

    Uiua

    Not really proud of this one. Part 1's still ok, just calculated all distances between boxes after realizing it's not that many (499500, a reasonable amount I think, relatively speaking).
    The dumbest thing I did this time was manually implementing the function to take the first n rows of an array by using a loop. Only when I was working on part 2 did I realize that I can just use the "take" function Uiua provides. Additionally, I even had some mistake in my reimplementation of it that only caused issues in part 2 somehow.
    For anyone interested, it's the commented out line in P₁ below.
    Part 2 is just a brute force. For the actual input, I searched manually until I got to the pair number just before the actual solution because I didn't want it to run that long and it takes long enough as is.

    Run with example input

    Code

    $ 162,817,812
    $ 57,618,57
    $ 906,360,560
    $ 592,479,940
    $ 352,342,300
    $ 466,668,158
    $ 542,29,236
    $ 431,825,988
    $ 739,650,466
    $ 52,470,668
    $ 216,146,977
    $ 819,987,18
    $ 117,168,530
    $ 805,96,715
    $ 346,949,466
    $ 970,615,88
    $ 941,993,340
    $ 862,61,35
    $ 984,92,344
    $ 425,690,689
    
    Dist ← ⍜(β‰‘Β°βˆš)/+⌡-°⊟
    Prep ← (
      ⊜(βŠœβ‹•βŠΈβ‰ @,)βŠΈβ‰ @\n
      β§…<2
      βŠββŠΈβ‰‘Dist
    )
    
    Merge ← (
      βœβ™­β‚‚βŠ›
      {}
      β₯(⍣(βŠ™(Β°βŠ‚
            β–‘β₯(
              βŸœβŠΈΛœβ‰‘βŒŸ(>/+βŠƒβ¨‚(Γ—β‚‚β‹…β§»))
              β—΄βŠ‚βŠ™(β™­βˆ©βŒŸβ–½βŸœΒ¬)
            )∞
          )
          βŠ‚
        | ∘)
      )∞
      βŠ™β—Œ
    )
    
    P₁ ← (
      Prep
      # β₯₁₀(βŠ™β€™βŠ‘Β°ΛœβŠ‚)
      ↙₁₀
      Merge
      ⍆≑◇⧻
      /×↙₋₃
    )
    
    Pβ‚‚ ← (
      Prep
      1_0
      ⊸⍒(
        ⍜°˜⊟(
          βŠ™+₁
          β‹…βŸœβ†™
          βŠ™(Merge
            β—‡β§»βŠ’)
        )
      | <20⊣)
      -β‚βŠ’
      ⊑
      Γ—Β°βŠŸβŠ‘β‚€β‰
    )
    
    [βŠƒP₁Pβ‚‚]
    ≑(&p $"Part _: _") 1_2
    

  • source
  • [–] 1 point 11 months ago* (last edited 11 months ago)

    Uiua

    Part 1 was fun, though I had quite some frustration with getting the loop work the way I wanted it to.
    For part 2 I didn't actually need to modify that much, just pass another function to deal with the list of tachyons: part 1, remove duplicates, part 2, don't remove and count at the end. Easy. Or so I thought.
    I realized something was wrong when it just wouldn't stop running and the fan got louder.

    Today I started over from scratch and decided to solve both parts at once since I basically got the counts for each row anyways, so I just had to change the way the splitting was handled.
    There was one occasion where I got an error that the resulting array would be too big (~4GB) but at least I got a warning instead of seeing RAM usage spike suddenly :P

    Run with example input

    Code

    $ .......S.......
    $ ...............
    $ .......^.......
    $ ...............
    $ ......^.^......
    $ ...............
    $ .....^.^.^.....
    $ ...............
    $ ....^.^...^....
    $ ...............
    $ ...^.^...^.^...
    $ ...............
    $ ..^...^.....^..
    $ ...............
    $ .^.^.^.^.^...^.
    $ ...............
    # &fras "input-7.txt" β—Œ
    βŠœβˆ˜βŠΈβ‰ @\n
    βŠƒ(=@SβŠ‘β‚€)(⊏⊚>0βŠΈβ‰‘/+=@^β†˜β‚‚)
    ShootSplit ← (
      ‚(=2+>0)
      ⧻⊸⊚
      βŠ™(βŸœβ‚‚(
          βŸœβŠβŠšβŠ™βŸœ[β§»]
          ⍚(βŠ‚βŠƒ-₁+₁)
          /+β‰‘βŒŸ(⬚0Λœβ†―Γ—β—‡Β°βŠš)
        )
        +⍜⊏(Λœβ†―0β§»)⊚
      )
    )
    
    Solve ← (
      0
      β₯(βŠ™(+|ShootSplit|βŠƒβŠ‘β‚€β†˜β‚))β—‘β‹…β‹…β§»
      βŠŸβŠ™βŠ™β—ŒβŠ™/+
    )
    
    Solve
    ≑(&p $"Part _: _") 1_2
    

    And for completeness sake:

    Previous attemptEdit: Tried to scrape the old code together but seems like it doesn't actually work like this. Probably just some small thing I missed but I don't have the mental energy to take a look at this mess again :P

    Prep ← βŠƒ(⊚=@S)βŠœβˆ˜βŠΈβ‰ @\n
    
    Splits! ← (
      ˙⍀>0β—‘β‹…β§»
      ‚(=β§»β€™Λœβ¨‚)
      βˆ©βŒŸβ–½βŠΈΒ¬
      ⊸⧻
      βŠ™(♭≑[βŠƒ-₁+₁]
        ^βŠ‚)
    )
    
    Shoot! ← (
      0
      ⍒(βŠ™(+
        | ⍣Splits!^βŠΈβ‹…0
        | ⊚=@^Β°βŠ‚
        )
      | >0β‹…β‹…β§»)
    )
    
    PartOne ← (
      &fras "input-7.txt"
      Prep
      βŠ™β‹…β—ŒShoot!β—΄
    )
    
    PartTwo ← (
      &fras "input-7.txt"
      Prep
      β§»β‹…βŠ™β—ŒShoot!∘
    )
    

  • source
  • [–] 4 points 11 months ago

    Uiua

    This was fun :D

    I had a fun experience just throwing the strings with both numbers and spaces at the parse function. In the online pad, everything worked out fine but running the same code on my input locally gave me a "invalid float literal" error.
    I thought I'd missed some edge case in the real input again, like is often the case.
    Turns out that the Uiua version I used locally had a bug that's fixed in the latest build. For once it wasn't directly my fault ^^

    Run with example input

    Code

    $ 123 328  51 64 
    $  45 64  387 23 
    $   6 98  215 314
    $ *   +   *   +  
    
    # &fras "input-6.txt" β—Œ
    
    Calc ← (
      β†˜β‚‚βŠ›βŠ‚"+*"/β—‡βŠ‚
      ≑◇⨬(/+|/Γ—)
      /+
    )
    
    P₁ ← (
      ⊜(βŠœβ–‘βŠΈβ‰ @ )βŠΈβ‰ @\n
      βŠƒβŠ£β†˜β‚‹β‚
      βŠ™(⍉≑₀◇⋕)
      Calc
    )
    
    Pβ‚‚ ← (
      βŠœβˆ˜βŠΈβ‰ @\n
      ⟜⧻
      βŠ“β‰(Λœβ†―@ )
      ⊜(βŠ™(░≑⋕)βœβ‰(βŠƒ(⊒⊣)β†˜β‚‹β‚))Β¬β€šβ‰‘βŒŸβ‰
      Calc
    )
    
    1_2 [βŠƒP₁Pβ‚‚]
    ≑(&p &pf $"Part _: ")
    
    

  • source
  • [–] 2 points 11 months ago

    Uiua

    Quite simple this one. Part 2 still takes a few seconds because I'm essentially checking off each roll individually.

    Run with example input

    Code

    $ ..@@.@@@@.
    $ @@@.@.@.@@
    $ @@@@@.@.@@
    $ @.@@@@..@.
    $ @@.@@@@.@@
    $ .@@@@@@@.@
    $ .@.@.@.@@@
    $ @.@@@.@@@@
    $ .@@@@@@@@.
    $ @.@.@@@.@.
    βŠœβˆ˜βŠΈβ‰ @\n
    =@@
    
    Rolls ← ⍣(β§»βŠšΛ™β€)∞⊸⊑1_1
    Removable ← (
      ⬚0⧈Rolls[3_3 1_1 1_1]
      βŠšβ‰€4
    )
    
    Remove ← ⍜⊑(Λœβ†―0β§»)
    
    PartOne ← β§»Removable
    
    PartTwo ← (
      βŠ™0
      β₯(
        βŠ™(βŠ™+⟜⧻)⟜Removable
        ˜Remove
      )∞
      β—Œ
    )
    &pf "Part One: "
    &p ⊸PartOne
    
    &pf "Part Two: "
    &p PartTwo
    

    Old Part 2Before seeing mykl's solution this was my solution for part 2

    PartTwoOld ← (
      0βŠ™0
      ⍒(βŠ™βŠ™β—Œ
        βŠ™βŠΈRemovable
        +βŠ™βŠΈβ§»
        βŠ™βŠΈRemove
      | Β¬β‰β—Œ)
      βŠ™β‹…β—Œ
    )
    

    It's basically the same, just that I used a while-do-loop, making the check for the ending condition myself (which took me a bit to get right because I still find loops in Uiua a bit confusing).
    Using the repeat-loop as above also gets rid of the dip's (βŠ™). I could've removed them here as well but I was already deep in the trouble of getting the loop to work correctly and I liked the little face at the beginning 0βŠ™0

  • source
  • [–] 2 points 11 months ago* (last edited 11 months ago)

    My original solution for part 1 was just removing the last digit, get the highest number, cut off everything up to and including that first number, get the highest number again.
    Once I did part 2 I realized I can just throw in a loop, cut off parts of the end so there's enough numbers left for the subsequent iterations and keep the rest the same.
    Now it works for any number of batteries and all you'd need to change is the number after Total! :D

    Online pad: AoC-2025-D3

    You can even use your own input by uploading a file (make sure it's using LF line endings only with a trailing one at the end) and replacing the example input with this: &rs inf &fo "input-file.txt"

    Code

    $ 987654321111111
    $ 811111111111119
    $ 234234234234278
    $ 818181911112111
    βŠœβˆ˜βŠΈβ‰ @\n
    
    Max ← βŠ’βŠΈβ–
    
    Jolt! ← (
      Β―^
      ""
      β₯(βŠ™(‚⊑Maxβ—‘β†˜+₁
          βŠ™(βŠ™β†˜β€šβ‹…βˆ˜+₁))
        βŠ‚
      )^
      βŠ™β‹…β—Œ
    )
    
    Total! ← (
      ≑(β‹•Jolt!^)
      /+
    )
    
    PartOne ← Total!2
    PartTwo ← Total!12
    
    ⊸PartOne
    &pf "Part One: "
    &p
    PartTwo
    &pf "Part Two: "
    &p
    

  • source