[Code Golf Challenge] Can Bitshift Variations in C Minor be compressed down to less than 185 characters? (Ṁ666 subsidy!)
12
701
996
resolved Jun 5
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).

My previous market was a challenge about decoding this music piece out of an 8x8 png image: /MayMeta/challenge-will-someone-decode-this, and this market is about the source code itself.

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

Will someone be able to shrink it down below 185 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 Ṁ200 play money

🏅 Top traders

#NameTotal profit
1Ṁ703
2Ṁ124
3Ṁ62
4Ṁ37
5Ṁ28
Sort by:
sold Ṁ15 of NO

The community has spoken! 6 votes against 5, it was judged that "Changing gcc to cc should totally count". I congratulate @brubsby on a sneaky solution, and I hope they'll continue to try compressing it even further 🙂

Bitshift Variations in C Minor has been compressed down to 184 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

But can we do even better? /MayMeta/code-golf-challenge2-can-bitshift-v

bought Ṁ95 of YES

Since you specified bash and C, not bash and GCC, I would say you should resolve this to yes. The problem was solved with bash knowledge rather than C knowledge, but as both are at play, the slightly disappointing answer is nonetheless correct. I would also encourage you to open a second market, either comparing against the provided 184 character solution, or specifying the surrounding GCC and |aplay lines, challenging for a smaller C script to be written.

predicted YES

this one's a bit trivial, but:

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

is 184 characters :^)
as cc is an alias for gcc on the average linux machine

predicted NO

@brubsby I'm leaning towards not counting that, but I'll research that first 🙂

bought Ṁ100 of YES

@MayMeta I do want to see it go lower than 184, but on the other hand it seems to meet all the criteria. This market resolving to yes also doesn't preclude the existence of another copy of this market with the title changed to 184 though :p

predicted NO

@brubsby On the one hand, I agree, this was clever and sneaky, and that does meet all of the criteria as they were written in the description, so I see your point.

But on the other, this doesn't truly feel like progress was made in compressing the source code itself. I'm guilty of overlooking this potential outcome, and not specifying that aplay AND gcc must be used, or that the C part of the program written should be optimized, and not the bash part.

Additionally, my research showed that cc can indeed be an alias of gcc on some linux distros, but it can also point to clang, or sometimes be its own binary, or be absent altogether. I'm not sure, perhaps if I've written "most of the linux machines" instead of "average linux machine" then this discussion would've been prevented.

I'm still leaning towards disqualifying this change as per the "against the spirit of code golf" clause. I don't want to make this call on my own thought, so I'll hold a 24 hour poll to see what the community thinks about this.

predicted NO

Yes changing gcc to cc should totally count 👍

predicted NO

No changing gcc to cc should be disqualified 👎

@MayMeta if we're depending on the environment, theoretically there could be a symlink called 'c'...

bought Ṁ0 of YES

@Mira that'd be a user defined symlink vs what is likely to be a system alias on the average linux machine though, and seems to fall under the spirit of "Reading from pre-written files"

@MayMeta Since people are buying in, you could also consider duplicate + NA instead of just disqualifying it. That way nobody loses money.

And in the next iteration, say something like "Environment is a container with exactly gcc, bash, aplay, etc. installed".

predicted YES

@Mira I think resolving to N/A rather than following the procedure outlined in the market description would uniquely detriment my position unfairly, even moreso than disqualifying my answer and slightly changing the rules.

@MayMeta I'm surprised so many people think this shouldn't count. One of the examples of shaving goes from using "echo" to "<<<", clearly bash-level codegolfing is part of the challenge. I would be very surprised to find any way of installing gcc through a package manager that would not also install a "cc" symlink unless one already existed for clang

bought Ṁ100 of YES

feels like i'm so close... 185 chars definitely hasn't hit the kolmogorov complexity yet, as there's "simple" syntax changes to c that could be done to remove some redundancy.

bought Ṁ30 of NO

@firstuserhere thx for the Ṁ466 subsidy! ❤