Day 22: Monkey Market

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

  • mykl@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    10 hours ago

    Uiua

    It’s been a while since I posted one of these, but I thought this would be straightforward in Uiua. Turns out that bitwise operations are a bit (haha) of a pain, so the Rng operation is very slow at 4sec for live data.

    I took this as an opportunity to play with the ⧈(stencil) operator which probably slowed things down too.

    # Data ← 1_10_100_2024
    Data ← 1_2_3_2024
    Xor  ← °⋯◿2⬚0+∩⋯ # Bitwise xor of two numbers.
    Rng  ← ⊙◌◿,Xor×2048.◿,Xor⌊÷32.◿,Xor×64.⊙16777216
    Runs ← ⍉(⇌[⍥(Rng.)])2000 Data # Should be constant.
    First ← (
      ⊟⊂0⧈₂/-.◿10 ↘¯1                 # Build run, gen pair diffs
      ⍣⊢0▽⊸>0⊢⧈(⨬⋅0⊣≍¯2_1_¯1_3°⊟) 2_4 # Take first value for matching diffs.
    )
    &p /+≡⊣.Runs
    &p /+≡First