Skip Navigation

Posts
15
Comments
200
Joined
3 yr. ago

  • Uiua

    Suspiciously easy. I even included a free animation generator for your entertainment.

     
        
    "..@@.@@@@.\n@@@.@.@.@@\n@@@@@.@.@@\n@.@@@@..@.\n@@.@@@@.@@\n.@@@@@@@.@\n.@.@.@.@@@\n@.@@@.@@@@\n.@@@@@@@@.\n@.@.@@@.@."
    # You can run against your own input by dragging your file
    # onto this pane and uncommenting the line below.
    # &fras"day4.txt" # edit to match the filename.
    ⊜(=@@)⊸≠@\n
    N₈ ← ⊂A₂C₂
    R  ← ×<4⊸(/+⬚0↻)N₈
    P₁ ← /+♭R
    P₂ ← /+♭-⊸⍥(-⊸R)∞
    P₃ ← ⍥(▽₃10)<1e6/×⊸△⍥⊸(-⊸R)∞
    ⊃(P₁|P₂|P₃)
    
    
      

  • Thanks, although it only really became clear after I'd written it. I am thinking about doing a more detailed explainer post based on one day's answer to help people get a feel for it.

  • Uiua

    You can run this in Uiua Pad

     
        
    "987654321111111\n811111111111119\n234234234234278\n818181911112111"
    ⊜∘⊸≠@\n
    Jolt ← ⍥(⊙⊃⋅∘∘+1⟜(⊃(˜⊡|˜↘⊙+₁)⍜↘⟜(˜⨂⊸/↥)))⟜(+1¯)
    ∩/+⊃≡(⋕Jolt2)≡(⋕Jolt12)
    
      

    ::: spoiler Explanation You're always looking for the highest digit far enough from the end of the string that there's space to pick the remaining number of digits. So the algorithm is very straightforward: just temporarily exclude the last n-1 characters off the end of the string and look for the first instance of the largest digit in that substring, store that char and behead the string at that point. Repeat n times.

  • Uiua

    Considerably easier than Day 1 for me. Uiua does have regex support, but no back references, so this is my poor man's version.

     
        
    "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124"
    ⊜(⊜⋕⊸≠@-)⊸≠@,
    R    ← +⊙⇡⟜-⊙+₁°⊟
    Dup  ← ¬˜∊0⦷⊸↙⌈÷2⊸⧻°⋕
    Dup₂ ← ⨬(/↥≡⌟(¬˜∊0⦷⊸↙)↘1⇡+1⌈÷2⊸⧻|0)<2÷∩⧻⊸⊸◴°⋕
    ⊃≡(/+▽⊸≡Dup R)≡(/+▽⊸≡Dup₂ R)
    ∩/+
    
    
      

    You can run the code on Uiua Pad, btw.

  • Just had a look at the Uiua Discord, and Part 2 can be simplified a little...

     
        
    "L68 L30 R48 L5 R60 L55 L1 L99 R14 L82"
    ⊜⋕⊸≠@\s∧⍜⊡⋅@¯⊚⊸⌕"L"∧⍜⊡⋅@+⊚⊸⌕"R"
    P₁ ← ⧻⊚=0\(◿100+)⊂50
    P₂ ← /+=0◿100\+▽⌵⟜±⊂50
    ⊃P₁ P₂
    
      

    Sometimes I could just cry.

  • Uiua

    Today's lesson: Never think that scanning the first 100 lines of input will give you a good understanding of it.

    Part 2 is really messy and could probably be much simpler, but I couldn't get the logic straight in my head otherwise.

     
        
    "L68 L30 R48 L5 R60 L55 L1 L99 R14 L82"
    ⊜⋕⊸≠@\s∧⍜⊡⋅@¯⊚⊸⌕"L"∧⍜⊡⋅@+⊚⊸⌕"R"
    P₁ ← ⧻⊚=0\(◿100+)⊂50
    P ← (
      ⊃(-×100×|/+)⌊÷100⌵⟜(⊸±) # Count and remove all over-rotations
      ⍉⊟↘¯1⊸(\(◿100+)⊂50)     # Take all positions and next moves.
      ▽⊸≡(≠0⊢)                # Ignore any starting from zero
      +/+↥⊃(<0|>100)≡/+       # Sum the pairs, check for passing zero.
    )
    P₂ ← +⊃P P₁
    ⊃(P₁|P₂)
    
      
  • Uiua

    Just a dirty great hack and a few minutes of toasty CPU for part3 with live data.

     uiua
        
    "1,5,2,6,8,4,1,7,3"
    ⊜⋕⊸≠@,
    &p /+=⊃(⧈₂(⌵/-)|÷2/↥) # Part1 --> 4
    
    "1,5,2,6,8,4,1,7,3,5,7,8,2"
    ⊜⋕⊸≠@,
    Knot  ← (⊃(=¯|=)∩⌞(±-)⊙°⊟)
    Knots ← /↧/↥↯∞_2[∩⌟Knot]°⊟
    ⧈₂⍆
    &p /+≡(/+≡Knots¤°⊂↙¯)⊙¤+1↘2⇡⊸⧻ # Part 2 --> 21
    
    "1,5,2,6,8,4,1,7,3,6"
    ⊜⋕⊸≠@,
    ⊃(⧅<2+1⇡⧻◴|⧈₂⍆)            # Possible cuts, existing strings.
    /↥+⊃(≡˜∊⊙¤|≡(/+≡Knots¤)⊙¤) # Part3 --> 7
    
      
  • Uiua

    There's probably a good solution hiding in here, but this ain't it. I originally went for the combinatoric approach for part 3, but it was giving me an answer that turned out to be out by 8, so brute force came to the rescue.

     uiua
        
    Prep ← (
      ⊜□⊸≠@\n
      Pairs ← ≡⊂⊓(¤|⊜∘⊸≠@,)∩°□°⊟
      ⊃(≡(□Pairs⊜□⊸(¬⦷" > ")°□)↘1|⊜□⊸≠@,°□⊢)
      ↘¯1∧(⊂°□) ⊙["  "]
    )
    "Oronris,Urakris,Oroneth,Uraketh\nr > a,i,o\ni > p,w\nn > e,r\no > n,m\nk > f,r\na > k\nU > r\ne > t\nO > r\nt > h\n"
    °□⊢▽⊸≡(/↧∊⊙(⧈₂∘°□))¤Prep # Part1 --> "Oroneth"
    "Xanverax,Khargyth,Nexzeth,Helther,Braerex,Tirgryph,Kharverax\nr > v,e,a,g,y\na > e,v,x,r\ne > r,x,v,t\nh > a,e,v\ng > r,y\ny > p,t\ni > v,r\nK > h\nv > e\nB > r\nt > h\nN > e\np > h\nH > e\nl > t\nz > e\nX > a\nn > v\nx > z\nT > i\n"
    /++1⊚≡(/↧∊⊙(⧈₂∘°□))¤Prep # Part2 --> 23
    P ← Prep"Khara,Xaryt,Noxer,Kharax\nr > v,e,a,g,y\na > e,v,x,r,g\ne > r,x,v,t\nh > a,e,v\ng > r,y\ny > p,t\ni > v,r\nK > h\nv > e\nB > r\nt > h\nN > e\np > h\nH > e\nl > t\nz > e\nX > a\nn > v\nx > z\nT > i\n"
    Keys  ← ⊙◌P
    Names ← ◌ P
    GoodNames ← (
      ˜▽Names≡(/↧∊⊙(⧈₂∘°□))¤P                 # Remove names that fail part2
      ▽⊸(¬≡(/+≡(⨬(0|≍∩⌞↙↧◡∩⧻∩°□)>◡∩(⧻°□))))⊸¤ # Exclude all names that are prefixes of others.
    )
    # Build up all names and count them. Yuk, slower, but righter.
    ⊙0GoodNames
    ≡◇([∘]
       ⍢(
        /◇⊂≡◇(□≡˜⊂⊙¤≡⊣▽⤚(=≡⊢)Keys⊸⊣) # Add next chars, collect.
        ⨬(∘|⊙+⟜⧻)⊸(≥7⧻⊢)             # Add to counts if long enough.
      | <11⊣△)
       ◌ # We don't need the data, just the counts.
    )
    /+
    
    
      
  • Uiua

    Straightforward until part3. I left the naive approach running while I put together the version below, but of course the better algorithm got there first.

     uiua
        
    Prep ← (
      ⍉˜⊟°⊏≡□                # store char with index
      ⊕(⊟⊃(⊢⊢|□≡(°□⊣)))⊛⊸≡◇⊢ # group them
      ⍉↯∞_6⊏⍏⊸≡(°□⊢⊢)        # re-arrange
      ▽=1◿2°⊏                # drop labels, as we never used them...
    )
    /+/+⊞>∩°□°⊟⊢Prep "ABabACacBCbca"     # Part1
    /+≡(/+/+⊞>∩°□°⊟)Prep "ABabACacBCbca" # Part2
    
    # Note that the pattern repeats, so the only distinct values
    # are in the first run and last run. Everything in between
    # will be identical. Only works when distance < string length...
    ⟜Prep "AABCBABCABCabcabcABCCBAACBCa"
    Rep   ← 2
    Split ← [1 -2Rep 1] # multipliers for the three results for each profession.
    Dist  ← 10
    ≡(≡(⊟∩□)⊃(≡+⊙(¤°□⊢)|¤♭≡+⊙(¤°□⊣)))¤×⇡3⧻ # Create the start, middle, end set for each.
    /+≡(/+×Split≡(/+/+⊞(≤Dist⌵-)∩°□°⊟))
    
      
  • Uiua

    [Works on test data, but fails on Part 3 live data: my checksum is "Correct length and correct first character". Posting for the record while I think about it more.] Turned out to be trailing zeros.

     uiua
        
    F ← (
      ↘1⊙[0_0_0] # Create empty row
      ∧(
        ◡≡([⊃(↧⊃(=0⊢◌|>⊙⊡₁)|=0⊡₁◌|↧⊃(=0⊣◌|<⊙⊡₁))]) # Will it fit in each row?
        ⊟⊙(⊢⊚)⟜⊡⊢⊚⊸≡/↥                             # Find first non-zero row and col.
        (⍜⊡⋅∘)⊙⊃⋅∘∘                                # insert
        ⍥(˜⊂0_0_0)¬≍0_0_0⊸⊣                        # Add padding row back
      )
      ↘¯1
    )
    S     ← ⋕/$"__"⊡1⍉
    Part₁ ← S F
    Part₂ ← -⊃/↧/↥≡(S F)
    
    Part₃ ← (
      ⬚0⊸≡(⊂⊃(S|≡(°⊥₁₀▽⊸>₀⇌))F) # All sword stats
      ≡⊂⊙(⊢⍉)             # Append sword IDs
      ⊏⊸⍖                 # Sort
      /+×+1°⊏≡⊣           # Checksum
    )
    
    Part₁ [58 5 3 7 8 9 10 4 5 7 8 8]
    Part₂ [[2 7 9 9 3 8 3 8 8 6 8] [5 2 9 3 8 3 9 5 2 1 4]]
    Part₃ [[1 7 1 9 1 6 9 8 3 7 2]
           [2 7 1 9 1 6 9 8 3 7 2]]
    
      
  • Uiua

    Fortunately the ratios for the common gears all proved to be rational in part 3.

     uiua
        
    ⌊×2025/÷⊏¯1_0[128 64 32 16 8]              # ->32400
    ⌈×⊙÷°⊟⊏¯1_0⊙10000000000000[128 64 32 16 8] # -> 625000000000
    ⊜□⊸≠@\s "5 5|10 10|20 5"
    ⌊×100×⊃(÷∩⋕⊃⊣⊢|/×≡◇(/÷⊜⋕⊸≠@|)↘1↘¯1) # -> 400
    
      
  • Very simple task for Uiua.

     uiua
        
    [10 5 1 10 3 8 5 2 2]
    /+◴
    [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]
    /+↙20⍆⊸◴
    /↥⊜⧻⊸∘⍆
    
    
      

    -> 29, 781, 3

  • Sadly Uiua doesn't handle the large numbers here well, so here's a Dart solution instead.

     dart
        
    import 'dart:math';
    import 'package:more/more.dart';
    
    typedef P = Point;
    void main(List<String> args) {
      P add(P a, P b) => P(a.x + b.x, a.y + b.y);
      P mul(P a, P b) => P(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
      P div(P a, P b) => P(a.x ~/ b.x, a.y ~/ b.y);
      P part1(P a) {
        P r = P(0, 0);
        for (var _ in 0.to(3)) {
          r = add(div(mul(r, r), P(10, 10)), a);
        }
        return r;
      }
    
      bool test2(P a) {
        P r = P(0, 0);
        for (var _ in 0.to(100)) {
          r = add(div(mul(r, r), P(100000, 100000)), a);
          if (r.x.abs() > 1000000 || r.y.abs() > 1000000) return false;
        }
        return true;
      }
    
      part2(P a, {step = 1}) => [
            for (var x in 0.to(1001, step: step))
              for (var y in 0.to(1001, step: step)) test2(P(a.x + x, a.y + y))
          ].count((e) => e);
    
      print(part1(P(25, 9)));
      print(part2(P(35300, -64910), step: 10));
      print(part2(P(35300, -64910)));
    }
    
      
  • :-(

    ^ not valid Uiua code

  • Short and simple Uiua solution :-)

     uiua
        
    Data ← {"Vyrdax,Drakzyph,Fyrryn,Elarzris"
            "R3,L2,R3,L1"}
    Prep    ← ⊜□⊸≠@,°□⊣⟜(+1/+˜=@,°□⊢)
    Present ← °□˜⊡⊜□⊸≠@,°□⊢Data⊙◌
    Part₁   ← ∧(↧⊙(⊸-₁)↥0+⍥¯=@L⊙⋕°⊂°□)⊙0
    Part₂   ← ∧(˜◿⊙⟜∘+⍥¯=@L⊙⋕°⊂°□)⊙0
    Present Part₁ Prep Data
    Present Part₂ Prep Data
    Data ← {"Vyrdax,Drakzyph,Fyrryn,Elarzris"
            "R3,L2,R3,L3"}
    ∩(⊜□⊸≠@,)∩°□°⊟⇌Data
    °□⊢∧(⍜⊏⇌⊂0◿(⧻⊃⋅∘⊙∘)⍥¯=@L⊙⋕°⊂°□)
    
    
    
      

    -> "Fyrryn", "Elarzris", "Drakzyph"

  • A messy drawer? There should be at least two: one for the kitchen and one for general.

  • I’m reading some of these replies thinking I’m getting gaslighted by railway operator employees. Unless they actually sell “absolutely no sitting” tickets and the conductors fine abusers, this ticket makes no sense.

  • Tell everyone that I’ve just watched a Jordan Peterson video and I’m going down the rabbit hole and ask them if they know where I can get my hands on some ketamine. My irrational behaviour and urgent need for fast access to my funds would then seem pretty par for the course.