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 β Β°β―βΏ2β¬0+β©β― # 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.