Pied Piper’s Compression Code From HBO’s Silicon Valley, Compiled

Pied Piper’s Compression Code From HBO’s Silicon Valley, Compiled

The third season of HBO’s Silicon Valley is now under way and if you caught the first episode, you would have noticed a snippet of Pied Piper’s valuable compression code towards the end of the show. Turns out this code actually compiles, though the output isn’t what you might expect.

Or perhaps it is.

Obviously, Mike Judge doesn’t hold the key to a compression algorithm that tosses the laws of information entropy out the window. So, what’s the next best thing? Well, that would be a joke.

You can see the code snippet from the show, in written form, over on Wikicoding. For those with sore clicking fingers, here it is replicated:


typedef unsigned long u64;

/* Start here */
typedef void enc_cfg_t;
typedef int enc_cfg2_t;
typedef __int128_t dcf_t;

enc_cfg_t _ctx_iface(dcf_t s, enc_cfg2_t i){
	int c = (((s & ((dcf_t)0x1FULL > i * 5) + 65);
	printf("%c", c); }
	enc_cfg2_t main() {
	for (int i=0; i0; c >>= 1)
		d += c & 1;
	// O(m) lol no thanks

	//1000 wrap into loop
	c = c - ((c >> 1) & ~0UL/3);
	c = (c & ~0UL/5) + ((c >> 2) & ~0UL/5);
	c = (c & 0UL/0x21) + ((c >> 4) & 0UL/0x11);
	c = (c & ~0UL/0x101) + ((c >> 8) & ~0UL/0x101);
	c = (c & ~0UL/0x10001)+((c>>16)&~0UL/0x10001);
	c = (c & ~0UL/0x100000001)+((c>>32)&~0UL/0x100000001);

	//TODO throw away intermediates... but could be useful later (see seander)
	return c;

//TODO transform + multiply spectra + transform back. faster? lossy?

u64 * ConvolutedMagic(u64 *x, u64 y, u64 *z, u64 n, u64 n_y) {
	//z is array of offsets in BITS
	//y is left-aligned of length n_y
	//TODO function is ridic fragile. e.g. if len z > len x/y...

	u64 * a = malloc(sizeof(u64)*n);
	u64 b,o_64,o_bit;

	for (int i=0; i> 6;
		o_bit= z[i] - ((z[i]>>6)  0) {
			b += x[o_64+1] >> (64-o_bit);
		b = (b >> (64-n_y))> (64-n_y))

What language is that? It's good old C and if you reckon it should compile, well, it does. Does it produce the mystical and highly vaunted middle-out compression from the show? No.

For those without a C compiler at the ready, you can do it online. As for the output, it's a simple one-liner:


Dream on indeed.

[Wikicoding, via Reddit]