[Code Golf Challenge2] Can Bitshift Variations in C Minor be compressed down to less than 184 characters? (Ṁ300 subsidy)
8
530Ṁ5247
resolved Jun 7
Resolved
YES

Bitshift Variations in C Minor by Robert Miles is a Code Golf music piece wtitten in C (with some additional bash commands). It was originally presented in a 2016 Computerfile video Code Golf & the Bitshift Variations. You can listen to clean renderings of it here (by Lucia Ceionia).

The original 2016 source code presented in the description under the YouTube video was 245 characters long:
echo "g(i,x,t,o){return((3&x&(i*((3&i>>16?\"BY}6YB6%\":\"Qj}6jQ6%\")[t%8]+51)>>o))<<4);};main(i,n,s){for(i=0;;i++)putchar(g(i,1,n=i>>14,12)+g(i,s=i>>17,n^i>>13,10)+g(i,s/3,n+((i>>11)%3),10)+g(i,s/5,8+n-((i>>10)%3),9));}"|gcc -xc -&&./a.out|aplay

A tweet from 2017 (or some other Rob Miles tweet, I'm not sure) stands 216 characters:
gcc -xc -oa -<<<'i;n;g(x,t,o){return(3&x&(i*((3&i>>16?"BY}6YB6%":"Qj}6jQ6%")[t%8]+51)>>o))<<4;}main(s){for(;;)putchar(g(1,n=++i>>14,12)+g(s=i>>17,n^i>>13,10)+g(s/3,n+(i>>11)%3,10)+g(s/5,8+n-(i>>10)%3,9));}';./a|aplay

With a month or two of work, I managed to shrink it down to 185 characters:
gcc -xc -oa -<<<'i;n;g(m,t,o){return("GTj?TG?5"[7&t]+!(n&12|t&2)*9)*i>>o&m&24;}main(s){for(;;)putchar(g(8,n=++i>>14,8)+g(n,n^(s=i>>10)/8,6)+g(n/3,n+s/2%3,6)+g(n/5,n-s%3,5));}';./a|aplay

In my previous market, a 184 characters version was found, by replacing gcc with cc:
cc -xc -oa -<<<'i;n;g(m,t,o){return("GTj?TG?5"[7&t]+!(n&12|t&2)*9)*i>>o&m&24;}main(s){for(;;)putchar(g(8,n=++i>>14,8)+g(n,n^(s=i>>10)/8,6)+g(n/3,n+s/2%3,6)+g(n/5,n-s%3,5));}';./a|aplay

Will someone be able to shrink it down below 184 characters, or the limit has been reached? This market resolves to YES as soon as someone posts a shorter version in bash+C, and I verify that it works. It resolves to NO on Jan 1st 2024 if no such version is found.

Conditions:
- The bash command should compile the source code and run + play it using aplay.
- You ARE allowed to slightly change the played notes, but their relative frequencies should not differ more than 1.4% from the original, and the entire piece should not be shifted more than one semitone (6%) from the original.
- You are allowed to use all sorts of tricks and hack in C language, as long as it compiles and works as intended on an average linux machine.
- Reading from pre-written files or from the internet is not allowed.
- I reserve the right to disqualify methods that I judge to be against the spirit of code golf, but I will hold a discussion about it in the comments section beforehand.

Useful links:
Deep analysis of Bitshift Variations in C Minor code
BitShift-Variations-unrolled
Bitshift Variations Humanized + Rust version

Get
Ṁ1,000
to start trading!

🏅 Top traders

#NameTotal profit
1Ṁ232
2Ṁ110
3Ṁ63
4Ṁ16
5Ṁ0
Sort by:

If this comment gets 6 likes I will create the next market. I wanna know if anybody is as curious as me to see just how far this will go...

Amazing work by @brubsby! I never would've thought to move putchar inside the (;;). Bravo!

@MayMeta and because 182 is not a prime, we get a nice thing to put on a wallpaper as a bonus

predictedYES

@MayMeta beautiful, time to update my desktop wallpaper

predictedYES

@MayMeta I had tried for loop stuffing for a while before finding the gcc->cc bit, but originally didn't realize there was such a good candidate for the body of the loop until later. i wouldn't be surprised if there's one or two more little transformations like this remaining before reaching a local optima. after which I assume expanding it back out and using more arcane approaches would be necessary. perhaps a job for AlphaDev if a successor market's stakes are high enough :) https://www.deepmind.com/blog/alphadev-discovers-faster-sorting-algorithms

predictedYES

@brubsby oh you put it like that, the stakes will be high enough

TIL that Manifold aggressively compresses images above a certain file size. I re-uploaded both in jpg, and now they look much better.

@brubsby Whoa, shit's getting serious...

predictedYES

@MayMeta yeah i realized that for the steganography challenge

predictedYES

@firstuserhere alphadev outputs assembly, which could theoretically be a smaller c program by naively executing a string representing assembly, but i'd posit the question of which representation is smaller is undecideable via rice's theorem

predictedYES

@brubsby oh oh assembly! It's been a while since i did that haha

predictedYES

@firstuserhere the next challenge has to happen, come on people

predictedYES

@brubsby using alphadev assembly to inform a hand crafted c solution to earn monopoly money would certainly be a new frontier in man machine cooperation

@brubsby btw as a side-effect of your solution we got another repeated trigram: ")))", joining the "<<<" that threw people off in the png-decoding market. I'm so happy to see the code getting more and more cursed

predictedYES

@brubsby thanks for linking the article for alphadev, sounds really good. I'll check out their abseil library, cuz a 30% increase in hashing perf has got to be seen

predictedYES
cc -xc -oa -<<<'i;n;g(m,t,o){return("GTj?TG?5"[7&t]+!(n&12|t&2)*9)*i>>o&m&24;}main(s){for(;;putchar(g(8,n=s>>4,8)+g(n,n^s/8,6)+g(n/3,n+s/2%3,6)+g(n/5,n-s%3,5)))s=++i>>10;}';./a|aplay

182 :)

@firstuserhere you really loving these challenges, huh!

predictedYES

@firstuserhere i very much like "please accomplish a fun programming feat" markets :)

predictedNO

@brubsby checking

predictedNO

@brubsby terribly sorry for the delay, resolving

Discussion about gcc vs cc can be found here.

Related questions

© Manifold Markets, Inc.Terms + Mana-only TermsPrivacyRules