Author Topic: Share your bestest code  (Read 5962 times)

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Share your bestest code
« on: September 17, 2012, 06:10:27 AM »
It's been a couple of stressful weeks. We've all been working our socks off trying to do our bit, and in so doing, we might have neglected ourselves. From time to time, it's a good idea to remind ourselves how awesome we are. By we, I mean elite programmers.

My goals in awesome coding are 1) to produce feline-legible code 2) that produces results within the 12 hours or so of the day when we're napping and 3) is capable of making an educated guess if not. Two out of three is good enough to qualify as awesome.

Some examples coming up.

This one is a LoremIpsum generator in Java. It is guaranteed to be bug-free:

https://gist.github.com/3136492

Next up, inverse square root approximation in LOLCODE:
Code: [Select]
HAI
CAN HAZ STDIO?
OBTW
    inverse_sqrt implementation
TLDR

HOW DUZ I INVSQRT YR NUM IT R A FLOAT
    I HAZ A ITEMARATIONTIMEZ IT R 1 SRSLY    BTW increase iteration times for accuracy

    I HAZ A NUMHALF IT R NUM TIEMZ 0.5 IT R A FLOAT
    I HAZ A OUTPUT IT R NUM
    I HAZ A BITVAL IT R OWAIT TEH OUTPUT DEN MAEK DAT A LONG LAZERPOINTR DEN TEH DAT MKAY
    SHIFZORZ BITVAL!!1
    BITVAL R HAX5f3759df NERF BITVAL
    OUTPUT R OWAIT TEH BITVAL DEN MAEK DAT A FLOAT LAZERPOINTR DEN TEH DAT MKAY

    I HAZ A VAR IT R 0
    IM IN YR LOOP UPPIN YR VAR!!1 TIL BOTH SAEM VAR AN ITEMARATIONTIMEZ
        OUTPUT R OWAIT NUMHALF TIMEZ OUTPUT TIEMZ OUTPUT DEN 1.5 NERF DAT DEN OUTPUT TIEMZ DAT MKAY
    IM OUTTA YR LOOP

    FOUND YR OUTPUT
IF U SAY SO
KTHXBAI
« Last Edit: September 18, 2012, 04:57:13 AM by ROBOKiTTY »
Have you played with a KiTTY today?

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #1 on: September 18, 2012, 02:39:35 AM »
Some selected stuffs from my LOLMAFF library.

Code: [Select]
HAI
CAN HAZ STDIO?

HOW DUZ I IZ_BOOMZ!!2 YR NUM IT R A INT
    I HAZ A ANSWER IT R A INT
    ANSWER R NUM PWNZ!!! AN OWAIT NUM ANDBITTEH OWAIT NUM NERF!!1 MKAY MKAY
    FOUND YR BOTH SAEM ANSWER AN 0
IF U SAY SO

HOW DUZ I BUFF_BOOMZ!!2 YR NUM IT R A INT
    BOTH SAEM NUM AN IZ_BOOMZ!!2 NUM
    ORLY
        YARLY
            FOUND YR NUM
        NOWAI
        IZ NUM LIEK PWND!!2 OR BOTH SAEM NUM AN 2
        ORLY
            YARLY
                FOUND YR 2
        KTHX
    KTHX
    NERFZ X!!1
    ORBITTEHZ X!!X SHIFZOR!!1
    ORBITTEHZ X!!X SHIFZOR!!2
    ORBITTEHZ X!!X SHIFZOR!!4
    ORBITTEHZ X!!X SHIFZOR!!8
    ORBITTEHZ X!!X SHIFZOR!!16
    FOUND YR X
IF U SAY SO

HOW DUZ I NERF_BOOMZ!!2 YR NUM IT R A INT
    BOTH SAEM NUM AN IZ_BOOMZ!!2 NUM
    ORLY
        YARLY
            FOUND YR NUM
        NOWAI
            PWND!! NUM BY 2 OR BOTH SAEM NUM AN 2
            ORLY
                YARLY
                    FOUND YR 2
            KTHX
    KTHX
    I HAZ A ANSWER IT R 1
    I HAZ A LASTBOOM IT R 0
    IM IN YR LOOP TIL LOLNO PWND!! ANSWER BY NUM
        LASTBOOM R ANSWER
        SHIFLOLZ ANSWER!!1
    IM OUTTA YR LOOP
    FOUND YR ANSWER
IF U SAY SO

HOW DUZ I ABS YR NUM
    PWND!! NUM BY 0
    ORLY
        YARLY
            FOUND YR NERF 0!!NUM
        NOWAI
            FOUND YR NUM
    KTHX
IF U SAY SO

HOW DUZ I MOD INLINE YR NUM IT R A FLOAT AN YR PERIOD IT R A FLOAT
    NUM R LEFTOVARZ NUM!!PERIOD
    NUM BIGRLIEK 0
    ORLY
        YARLY
            FOUND YR NUM
        NOWAI
            FOUND YR NUM BUFF!!PERIOD
    KTHX
IF U SAY SO

HOW DUZ I CYCLIC_DIFF YR HI IT R A FLOAT
                                        AN LO IT R A FLOAT
                                        AN PERIOD IT R A FLOAT
                                        AN WRAP IT R A TROOF
    WRAP R WIN
    ORLY
        YARLY
            HI R MOD HI!!PERIOD
            LO R MOD LO!!PERIOD
    KTHX
    HI BIGRLIEK LO
    ORLY
        YARLY
            FOUND YR NERF HI!!LO
        NOWAI
            FOUND YR NERF BUFF HI!!PERIOD!!LO
    KTHX
IF U SAY SO
KTHXBAI
« Last Edit: September 18, 2012, 05:10:20 AM by ROBOKiTTY »
Have you played with a KiTTY today?

WanderingAries

  • Elite Boss
  • *****
  • Posts: 321
  • @WanderingAries /\ Mostly on Torch
Re: Share your bestest code
« Reply #2 on: September 18, 2012, 04:00:34 AM »
I guess you can count me out...I tend to skip Meudo code and dive right in. ;-)
Find me on Homecoming:
https://www.homecomingservers.com

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #3 on: September 18, 2012, 04:56:09 AM »
I guess you can count me out...I tend to skip Meudo code and dive right in. ;-)

Hey, it's real code. Compiles smoothly with -w.

Also, awesome code is language-agnostic. ;D
Have you played with a KiTTY today?

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #4 on: September 18, 2012, 06:05:28 AM »
Anonymized production code:

Code: [Select]
#include <cstdlib>
#include <cstdio>
#include "includethis.h"

using namespace std;

typedef int unused;

class FacingDirection : public Direction, public ISCDef
{
public:
inline FacingDirection operator++(unused)
{
if (mIsFacingNorth)
{
setIsFacingEast();
}
else if (mIsFacingEast)
{
setIsFacingSouth();
}
else if (mIsFacingSouth)
{
setIsFacingWest();
}
else if (mIsFacingWest)
{
setIsFacingNorth();
}

return *this;
}

FacingDirection operator++()
{
cerr << "Operation not supported.";
exit(1);
}

FacingDirection operator--(unused)
{
delete[] dirs;
dirs = NULL;
return *this;
}

FacingDirection operator--()
{
cerr << "Operation not supported.";
exit(1);
}

void setIsFacingNorth()
{
mIsFacingNorth = true;
mIsFacingEast = false;
mIsFacingSouth = false;
mIsFacingWest = false;
}

void setIsFacingEast()
{
mIsFacingNorth = false;
mIsFacingEast = true;
mIsFacingSouth = false;
mIsFacingWest = false;
}

void setIsFacingSouth()
{
mIsFacingNorth = false;
mIsFacingEast = false;
mIsFacingSouth = true;
mIsFacingWest = false;
}

void setIsFacingWest()
{
mIsFacingNorth = false;
mIsFacingEast = false;
mIsFacingSouth = false;
mIsFacingWest = true;
}
}
Have you played with a KiTTY today?

Kadmon

  • Boss
  • ****
  • Posts: 155
  • Avatar of Mu - @Kadmon
Re: Share your bestest code
« Reply #5 on: September 18, 2012, 11:20:52 AM »
Won't lie, the most coding I've done was "Intro to Basic" back in high school. In said class, one of the activities was "Write a program for making a peanut butter and jelly sandwich", which I played masterfully. I wrote an intentional endless loop which ended up using the entire bag of bread and half a container of peanut butter before the teacher figured out I'd done it on purpose :D

I was probably the best programmer in the bunch. Admittedly, not because I was any good at it, but because everyone else in there was kinda dumb (but they were my friends, so I helped them out anyway :p)
We're heroes. When something threatens our fair city, we fight it tooth and nail, and by God, we make it pay for every bloody inch!

WanderingAries

  • Elite Boss
  • *****
  • Posts: 321
  • @WanderingAries /\ Mostly on Torch
Re: Share your bestest code
« Reply #6 on: September 18, 2012, 06:24:27 PM »
Anonymized production code:

I followed...most of that. :-p
Find me on Homecoming:
https://www.homecomingservers.com

Michiyo

  • Titan Staff
  • Lieutenant
  • ****
  • Posts: 54
    • SGSpaces
Re: Share your bestest code
« Reply #7 on: September 18, 2012, 07:11:11 PM »
Code: [Select]
function icanhazcheezburger($array) {
echo "I want a Cheeseburger with: ";
foreach ($array as $arr) {
echo "$arr[1] $arr[0], ";
}
}
echo icanhazcheezburger(array(array('Double Meat', ''), array('Tommato', 'No'), array('Ketchup', 'No'), array('Mustard', 'No'), array('Lettuce', 'Add'), array('Bacon', 'Add')));

I want a Cheeseburger with: Double Meat, No Tommato, No Ketchup, No Mustard, Add Lettuce, Add Bacon

This came about because I listed on my FB profile I could speak PHP, someone asked me to order a Cheeseburger, so I did.

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #8 on: September 18, 2012, 10:55:22 PM »
This one is expressive, but seems to be missing that certain je ne sais quoi...

Code: [Select]
dtCurrentDate.mDateConvertFunc = function out(d) {
return (function (stD)  {
if (!!~d)
{
return fn2(function (d) { return in(d) (fn3); } );
}
return fn3(function (d) { if (!!~d) throw d.getString("lc") + " is malformed or corrupted."; } );
});
};

Have you played with a KiTTY today?

Mandrake

  • Boss
  • ****
  • Posts: 100
Re: Share your bestest code
« Reply #9 on: September 19, 2012, 04:23:26 AM »
I remember my BASIC days...

Code: [Select]
10 PRINT "NCSoft sucks..."
20 GOTO 10
30 PRINT "No wait... NCSoft rules!"
40 REM I'll remove 20 when they come to their senses.
   

Reiraku

  • Boss
  • ****
  • Posts: 134
Re: Share your bestest code
« Reply #10 on: September 19, 2012, 11:07:53 AM »
↑ ↑ ↓ ↓ ← → ← → B A Select Start

Or the lesser known:

↑ ↓ ↑ ↓  ← → ← → ↑ → ↓ ← ↑ B

Thirty-Seven

  • Elite Boss
  • *****
  • Posts: 623
  • Keeper of the Sacred Number
Re: Share your bestest code
« Reply #11 on: September 19, 2012, 02:05:15 PM »
In the vein of the above, I present: IDDQD!  Best code ever.

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #12 on: September 20, 2012, 09:46:04 PM »
Because of a bug in my LOLCODE maintenance script, my cygwin was broken:



Now writing a new LOLCODE script to repair the problem.
Have you played with a KiTTY today?

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #13 on: September 22, 2012, 05:00:50 AM »
It's not uncommon that I need to manually unroll loops when tuning for performance. However, this can get tedious, especially when loops iterate more than a dozen times. The obvious solution is to expedite the process with a script.

I present you this BF routine. Supply a code snippet, and it will be automagically duplicated about 999 times. No moar manual code duplication.

Code: [Select]
+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+[->,----------]<[<]<<[>[>>[++++
+++++++.----------->]++++++++++++++++++++++++++++++++.--------------------------------<[<]<-]<->+++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++<]
« Last Edit: September 22, 2012, 05:12:17 AM by ROBOKiTTY »
Have you played with a KiTTY today?

ROBOKiTTY

  • Boss
  • ****
  • Posts: 183
  • KiTTYRiffic
    • KiTTYLand
Re: Share your bestest code
« Reply #14 on: September 22, 2012, 09:30:00 PM »
Have you played with a KiTTY today?