• 1 Post
  • 12 Comments
Joined 1 year ago
cake
Cake day: December 6th, 2024

help-circle


  • 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
    

  • 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 attempt

    Edit: 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!∘
    )
    



  • 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 _: ")
    
    


  • 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 2

    Before 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


  • 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