July 23, 2019, 04:48:27 pm

## News:

The account sign-up bug has been fixed.

Alternatively, join us on Discord.

## Golfed code snippets

Started by Juju, December 06, 2018, 01:23:24 am

0 Members and 1 Guest are viewing this topic.

#### Juju

##### December 06, 2018, 01:23:24 am
Code (node.js, 346 chars) Select
`[..." sos"].map(c=>{p="  etianmsurwdkgohvfüläpjbxcyzqö 54\x063é  2&è+  à 16=/ ç\2( 7  ñ8 90     \4      ?_    \"  .    @   '  -        ;! )     ,    :".search(c)for(s="00";p>1;p=p/2|0)s=(p%2?"1110":"10")+sm+=p>0?s:s+s},m=i="");(w=new(require('wemo-client'))()).discover((e,d)=>{setInterval(_=>w.client(d).setBinaryState(+m[i++%m.length]),500)})`

Probably the weirdest constant to ever appear in a program, guess what it does.

the answer: Show

Get one of these things, plug a lamp in and it does morse code with the correct timing.
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

#### _iPhoenix_

##### December 08, 2018, 04:28:09 am #1
As far as weird/cool constants in golfed code goes, this is my absolute favorite.

From the Quake III Arena source code, a routine to calculate an inverse square root
`float Q_rsqrt( float number ){   long i;   float x2, y;   const float threehalfs = 1.5F;   x2 = number * 0.5F;   y  = number;   i  = * ( long * ) &y;                       // evil floating point bit level hacking   i  = 0x5f3759df - ( i >> 1 );               // what the f***?    y  = * ( float * ) &i;   y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration//   y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed   return y;}`

From wikipedia
Please spam here: https://legend-of-iphoenix.github.io/spam/

"walruses are better than tuxedo chickens, all hail the great " ~ me
Evolution of my avatar:

#### Juju

##### December 08, 2018, 06:18:41 am #2
Ah yeah, back when golfing your code was actually useful, I love little tricks like this.

C allows for a lot of neat stuff like doing stuff on a float as if it was an int.
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

#### rowan_futurerave

##### December 12, 2018, 11:45:27 am #3
Quote from: Juju on December 06, 2018, 01:23:24 am
Code (node.js, 346 chars) Select
`[..." sos"].map(c=>{p="  etianmsurwdkgohvfüläpjbxcyzqö 54\x063é  2&è+  à 16=/ ç\2( 7  ñ8 90     \4      ?_    \"  .    @   '  -        ;! )     ,    :".search(c)for(s="00";p>1;p=p/2|0)s=(p%2?"1110":"10")+sm+=p>0?s:s+s},m=i="");(w=new(require('wemo-client'))()).discover((e,d)=>{setInterval(_=>w.client(d).setBinaryState(+m[i++%m.length]),500)})`

Probably the weirdest constant to ever appear in a program, guess what it does.

the answer: Show

Get one of these things, plug a lamp in and it does morse code with the correct timing.

What a hideous bastard of a piece of code. I would definitely sack the person who wrote it.

Powered by EzPortal