Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with:

Code Golf: 2014 In ColdFusion

By Ben Nadel on
Tags: ColdFusion

Over the weekend, I happened upon this Stack Exchange entry asking people to try and output the value "2014" without actually using any numbers. Apparently there is this thing called "Code Golf" in which developers try to do carry-out some task with the smallest amount of code possible. This is new to me, but it sounds exciting. I figured I'd give it a try. Well, not the "least amount of characters" aspect - just the trying to output 2014 without numbers.

All of the following output 2014:

  • <cfscript>
  •  
  • // Inspired by this entry on Stack Exchange (via Hacker News):
  • // http://codegolf.stackexchange.com/questions/17005/produce-the-number-2014-without-any-numbers-in-your-source-code
  • // --
  • // So, now that it's 2014, it's time for a code question involving
  • // the number 2014. Your task is to make a program that prints the
  • // number 2014 without using any of the characters 0123456789 in
  • // your code. The shortest code (counting in bytes) to do so in any
  • // language in which numbers are valid tokens wins.
  •  
  •  
  • // Simply logs all of the arguments to output.
  • // --
  • // NOTE: This funciton uses a "1", however, since its just a
  • // utility function for writeOutput(), I'm not going ot count it.
  • function print( arg1, arg2, arg3, arg4 ) {
  •  
  • for ( var i = 1 ; i <= arrayLen( arguments ) ; i++ ) {
  •  
  • writeOutput( arguments[ i ] );
  •  
  • }
  •  
  • writeOutput( "<br />" );
  •  
  • }
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // Outputting the current year is definitely the most low-hanging
  • // fruit approach to the problem.
  • print( year( now() ) );
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // While we can't use numbers, we certainly can generate numbers
  • // based on other values.
  • print(
  • len( "xx" ),
  • len( "" ),
  • len( "x" ),
  • len( "xxxx" )
  • );
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // If we know what the Base64-encoded version of 2014 is, we
  • // can reverse engineer the value.
  • print( toString( toBinary( "MjAxNA==" ) ) );
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // Similarly, if we know the encrypted value, we can just decrypt
  • // it, assuming the encrypted value contains no numbers!
  • print( decrypt( "$##RL.+P", "you sexy beast" ) );
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // Each character can be represented by a decimal value. As such,
  • // we can use the "char" versions of said numbers to produce
  • // the numerical equivalents for some math.
  • print(
  • ( asc( "<" ) - asc( "(" ) ),
  • ( asc( "." ) - asc( " " ) )
  • );
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // Another way to generate numbers is to find the location of
  • // substrings within larger strings.
  • print(
  • find( "sexy", "How you doing, you sexy lady?!" ),
  • find( "troll", "Ewwwwww, you troll! Get away from me!" )
  • );
  •  
  •  
  • // ------------------------------------------------------ //
  • // ------------------------------------------------------ //
  •  
  •  
  • // By using mathematical operations, we can force ColdFusion to
  • // cast boolean values into ones and zeros.
  • print(
  • ( true + true ),
  • ( true * false ),
  • ( false + true ),
  • ( true + true + true + true )
  • );
  •  
  • </cfscript>

I thought maybe there would be some interesting bit-shifting I could do. But 1) I'm not that good at bits and, 2) all of the bit-shift functions in ColdFusion require actual numbers as part of their arguments.

Tweet This Provocative thoughts by @BenNadel - Code Golf: 2014 In ColdFusion Thanks my man — you rock the party that rocks the body!


Reader Comments

Here's another one:
<cfset Code = "Golf" />
<cfoutput>
#Find('o', Code)##Find('x', Code)##Find('G', Code)##Find('f', Code)#
</cfoutput>

Reply to this Comment

Hey Ben, it's been a while.
<cfscript>
i = val('a');
writeOutput((++i + i++ & --i - i-- & ++i & ++i + i++ ));
</cfscript>

Reply to this Comment

Nice job, @Ben! I don't think that's the smallest amount of code with all of your comments, though. ;) Just kidding. I've always liked all your comments. I can't come up with anything better or shorter.

Reply to this Comment

Post A Comment

?
You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.