• 1 Post
  • 38 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
    

  • QuanttoAdvent Of Code👪 - 2025 DAY 7 SOLUTIONS - 👪
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 month 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 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


  • QuanttoAdvent Of Code💃 - 2025 DAY 3 SOLUTIONS - 💃
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    2 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
    



  • Uiua

    Put this one off for a bit and I’ll put off part two for even longer because I don’t want to deal with any pyramid-shapes of boxes at the moment.
    The code for part one feels too long but it works and runs <2s so I’m happy with it for now ^^

    Run with example input here

    Code

    I decided to split the movement instructions lines further for aesthetic reasons when opening it in the online uiua pad since newlines are thrown out anyways.

    $ ##########
    $ #..O..O.O#
    $ #......O.#
    $ #.OO..O.O#
    $ #[email protected].#
    $ #O#..O...#
    $ #O..O..O.#
    $ #.OO.O.OO#
    $ #....O...#
    $ ##########
    $ 
    $ <vv>^<v^>v>^vv^v>v<>v^v<v<^vv<<<^><
    $ <><>>v<vvv<>^v^>^<<<><<v<<<v^vv^v>^
    $ vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<
    $ >><^^v>^>vv<>v<<<<v<^v>^<^^>>>^<v<v
    $ ><>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v
    $ ^<^^>v^^>v^<^v>v<>>v^v^<v>v^^<^^vv<
    $ <<v<^>>^^^^>>>v^<>vvv^><v<<<>^^^vv^
    $ <vvv>^>v<^^^^v<>^>vvvv><>>v^<<^^^^^
    $ ^><^><>>><>^^<<^^v>>><^<v>^<vv>>v>>
    $ >^v><>^v><<<<v>>v<v<v>vvv>^<><<>^><
    $ ^>><>^v<><^vvv<^^<><v<<<<<><^v<<<><
    $ <<^^<v<^^^><^>>^<v^><<<^>>^v<v^v<v^
    $ >^>>^v>vv>^<<^v<>><<><<v<<v><>v<^vv
    $ <<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^
    $ <><^^>^^^<><vvvvv^v<v<<>^v<v>v<<^><
    $ <><<><<<^^<<<^<<>><<><^^^>^^<>^>v<>
    $ ^^>vv<^v^v<vv>^<><v<^v>^^^>>>^^vvv^
    $ >vvv<>>>^<^>>>>>^<<^v>^vvv<>^<><<v>
    $ v^^>>><<^^<>>^v^<v^vv<>v^<<>^<^v^v>
    $ <^<<<><<^<v><v<>vv>>v><v^<vv<>v^<<^
    
    Pos ← :°⊟♭⊚⊸⌕@@
    Move ← (
      ⊸⊗@.
      ⍣(+₁⍤.◡(≠⊙⧻)
        ⍜↙⍣(⬚@.↻₋₁⍤.=⊃(⧻|⊗@#).)∘
      )⋅∘
    )
    
    PartOne ← (
      # &rs ∞ &fo "input-15.txt"
      ⊜□¬⦷"\n\n".
      ∩°□°⊟
      : ⊙(▽≠@\n.) ⊜∘≠@\n.
      ↘₄⊛⊂"^>v<"
      ⍢(⊃↘₁⊢
        ⊙(⟜(⨬(⍉|∘)◿₂)
          ⟜(⨬(⍜(↘⊙⊡)Move Pos
            | ⍜(⇌↙⊙⊡)Move +₁Pos
            )=₀◿₃)
          ⨬(⍉|∘)◿₂
        )
      | ≠0⧻)
      ◌
      /+≡/+×[100_1]⊚⌕@O
    )
    
    PartTwo ← (
      ""
    )
    
    &p "Day 15:"
    &pf "Part 1: "
    &p PartOne
    &pf "Part 2: "
    &p PartTwo
    


  • QuanttoAdvent Of Code🚽 - 2024 DAY 14 SOLUTIONS - 🚽
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Uiua

    Ok, so part one wasn’t too hard, and since uiua also takes negative values for accessing arrays, I didn’t even have to care about converting my modulus results (though I did later for part two).
    I’m a bit conflicted about the way I detected the quadrants the robots are in, or rather the way the creation of the mask-array happens. I basically made a 11x7 field of 0’s, then picked out each quadrant and added 1-4 respectively. Uiua’s group () function then takes care of putting all the robots in separate arrays for each quadrant. Simple.

    For part two, I didn’t even think long before I came here to see other’s approaches. The idea to look for the first occurrence where no robots’ positions overlapped was my starting point for what follows.

    Example input stuff

    Run with example input here

    $ p=0,4 v=3,-3
    $ p=6,3 v=-1,-3
    $ p=10,3 v=-1,2
    $ p=2,0 v=2,-1
    $ p=0,0 v=1,3
    $ p=3,0 v=-2,-2
    $ p=7,6 v=-1,-3
    $ p=3,0 v=-1,-2
    $ p=9,3 v=2,3
    $ p=7,3 v=-1,2
    $ p=2,4 v=2,-3
    $ p=9,5 v=-3,-3
    .
    PartOne ← (
      # &rs ∞ &fo "input-14.txt"
      ⊜(↯2_2⋕regex"-?\\d+")≠@\n.
      ≡(⍜⌵(◿11_7)+°⊟⍜⊡₁×₁₀₀)
      ↯⟜(▽×°⊟)7_11 0
      ⍜↙₃(⍜≡↙₅+₁⍜≡↘₆+₂)
      ⍜↘₄(⍜≡↙₅+₃⍜≡↘₆+₄)
      /×≡◇⧻⊕□-₁⊸(⊡:)⍉
    )
    
    PartTwo ← (
      # &rs ∞ &fo "input-14.txt"
      ⊜(↯2_2⋕regex"-?\\d+")≠@\n.
      0 # number of seconds to start at
      0_0
      ⍢(◡(≡(⍜⌵(◿11_7)+°⊟⍜⊡₁×):)◌
        ◿[11_7]≡+[11_7]
        ⊙+₁
      | ≠⊙(⧻◴)⧻.)
      ⊙◌◌
      -₁
    )
    
    &p "Day 14:"
    &pf "Part 1: "
    &p PartOne
    &pf "Part 2: "
    &p PartTwo
    

    Now on to the more layered approach of how I got my solution.

    In my case, there’s two occasions of non-overlapping positions before the christmas tree appears.
    I had some fun trying to get those frames and kept messing up with going back and forth between 7x11 vs 103x101 fields, often forgetting to adjust the modulus and other parts, so that was great.

    In the end, I uploaded my input to the online uiua pad to make visualizing possible frames easier since uiua is able to output media if the arrays match a defined format.

    Try it out yourself with your input
    1. Open the uiua pad with code here
    2. Replace the 0 in the first line with your solution for part two
    3. If necessary, change the name of the file containing your input
    4. Drag a file containing your input onto the pad to upload it and run the code
    5. An image should be displayed

    I used this code to find the occurrence of non-overlapping positions (running this locally):

    &rs ∞ &fo "input-14.txt"
    ⊜(↯2_2⋕regex"-?\\d+")≠@\n.
    0 # number of seconds to start at
    0_0
    ⍢(◡(≡(⍜⌵(◿101_103)+°⊟⍜⊡₁×):)◌
      ◿[101_103]≡+[101_103]
      ⊙+₁
    | ≠⊙(⧻◴)⧻.)
    ⊙◌◌
    -₁
    

    Whenever a new case was found, I put the result into the code in the online pad to check the generated image, and finally got this at the third try:


  • QuanttoAdvent Of Code🦀 - 2024 DAY 13 SOLUTIONS -🦀
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Welp, got frustrated again with part one because there kept being something wrong with my totally-not-ugly loop and so came here again. I did have to change IsInt (and thus also Cost to account for different handling) for part two though because I kept getting wrong results for my input.
    I’m guessing it’s because uiua didn’t see the difference between rounded and non-rounded number anymore.

    Here’s the updated, slightly messier version of the two functions that worked out for me in the end :D

    IsInt ← ≍°⊟⍉⍜(⊙(⍉≡↙₂))(/+×)⊙⍉⁅
    Cost  ← /+×3_1×⟜IsInt⊸AB
    

    Could have been done better but I’m lacking the patience for that now



  • QuanttoAdvent Of Code🌻 - 2024 DAY 12 SOLUTIONS -🌻
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Counting the number of corners was a very useful hint for part 2. I had the most trouble with detecting the double corners, i.e. like in the example where the two B fields touch diagonally:

    AAAAAA
    AAABBA
    AAABBA
    ABBAAA
    ABBAAA
    AAAAAA
    

    Still, I would’ve taken a lot longer and probably made really-bad-performance-code without reading this :D


  • I found multidimensional markers for partition to work really well for finding the fields: Areas ← ⊜□:⇡△.+1⍜♭⊛ It just groups the other array’s contents according to adjacent markers, horizontally and vertically. Took me quite a bit to figure out what’s actually happening in the example in the documentation ^^’


  • QuanttoAdvent Of Code🌻 - 2024 DAY 12 SOLUTIONS -🌻
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Uiua

    I spent a while thinking about how to best do a flood fill in Uiua when I saw that (partition) works beautifully with multidimensional markers: “Groups are formed from markers that are adjacent along any axis.”, meaning I just had to convert all letters into numbers and I’d get all indices belonging to a field into an array.
    For part 2, I cheated a bit by coming here and reading that you only need to count the edges. To my surprise, the second part is actually a bit faster than part 1. Takes less than 0.2 seconds each though :D

    Run with example input here

    $ RRRRIICCFF
    $ RRRRIICCCF
    $ VVRRRCCFFF
    $ VVRCCCJFFF
    $ VVVVCJJCFE
    $ VVIVCCJJEE
    $ VVIIICJJEE
    $ MIIIIIJJEE
    $ MIIISIJEEE
    $ MMMISSJEEE
    .
    N     ← +[0_¯1 0_1 ¯1_0 1_0]
    Areas ← ⊜□:⇡△.+1⍜♭⊛
    Peri  ← -/+≡(/+∊N¤)⟜¤⟜(×4⧻)
    Sides ← (
      ⊙(-¤)↯:▽⊙0×°⊟.+2⌵⊸-+1⊃⊣⊢⊸⍜⍉≡⍆
      ⧻⊚⊸∊1_3⧈(/+/+)2_2.⍜⊡=₀+1:
      +⊙(×2/+/+⧈(∊[[1_0 0_1][0_1 1_0]])2_2◌)
    )
    Cost! ← /+≡◇(×^0⟜⧻)
    
    PartOne ← (
      # &rs ∞ &fo "input-12.txt"
      ⊜∘≠@\n.
      Cost!Peri Areas
    )
    
    PartTwo ← (
      # &rs ∞ &fo "input-12.txt"
      ⊜∘≠@\n.
      Cost!Sides Areas
    )
    
    &p "Day 12:"
    &pf "Part 1: "
    &p PartOne
    &pf "Part 2: "
    &p PartTwo