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
    5
    ·
    edit-2
    5 days 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_2_3_2024
    Xor  ← °⋯◿20+∩⋯ # Bitwise xor of two numbers.
    Rng  ← ⊙◌◿,Xor×2048.◿,Xor⌊÷32.◿,Xor×64.⊙16777216
    Runs ← ⍉(⇌[⍥(Rng.)])2000 Data # Should be constant?
    Firsts ← (
      ⊟⊂0⧈₂/-.◿10 ↘¯1         # Build run, gen pair diffs
      ⊢⧈(⊟⊙⊣/(+×40+20)°⊟) 2_4 # Convert 4-diff into key, collect.
      ⊕⊢⊛⊙⍉⊙◌°⊟.⍉             # Only keep first of each key. # ⍜(map°⊟⍉⇌|∘) failed. 
    )
    &p /+≡⊣.Runs
    &p /↥⊕(/+)+1⊛°⊟⍉/◇⊂wait≡spawn(□Firsts) # Group by key, sum prices, return highest.