We're on Discord! Please join our server now if you don't want to miss anything! (More info) | Join the UCC4 contest! (More info)

* WalrusIRC & Discord main room

If you have a forum account, have more than 4 posts and are not part of a restricted usergroup, then you can chat in our main Discord server room directly from here and continue using the forums at the same time. Or you can join our server directly and access many more discussion rooms!

Author Topic: Golfed code snippets  (Read 138 times)

0 Members and 1 Guest are viewing this topic.

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3280
  • Post Rating Ratio: +39/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Golfed code snippets
« 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")+s
m+=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.

(click to show/hide)


  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

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

Offline _iPhoenix_

  • Custom title
  • Super User
  • Join Date: Mar 2017
  • Location: Location
  • Posts: 673
  • Post Rating Ratio: +16/-1
  • ███████ ▼ ♪ Best music ♫
    • @dj_iPhoenix
    • @UCytgMNPxAMDsxjimvxHf01w
    • Legend-of-iPhoenix
    • @the-legend-of-iphoenix
    • My website.
  • Gender: Male
Re: Golfed code snippets
« Reply #1 on: December 08, 2018, 04:28:09 am »
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
Code: [Select]
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
  • Calculators owned: Two TI-84+ CE's
Please spam here: https://legend-of-iphoenix.github.io/spam/

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

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3280
  • Post Rating Ratio: +39/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Golfed code snippets
« Reply #2 on: December 08, 2018, 06:18:41 am »
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.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

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

Offline rowan_futurerave

  • Full User
  • Disabled shoutbox mode
  • Restricted (shoutbox)
  • Join Date: Aug 2018
  • Location:
  • Posts: 39
  • Post Rating Ratio: +0/-0
    • rowanmedhurst
    • Futurerave
  • Gender: Male
Re: Golfed code snippets
« Reply #3 on: December 12, 2018, 11:45:27 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")+s
m+=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.

(click to show/hide)

What a hideous bastard of a piece of code. I would definitely sack the person who wrote it.
  • Calculators owned: TI-84 Plus CE-T, CASIO fx-CG50

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games