Skip to main content
Ben Nadel at the New York ColdFusion User Group (Feb. 2009) with: Aaron Foss and Clark Valberg
Ben Nadel at the New York ColdFusion User Group (Feb. 2009) with: Aaron Foss Clark Valberg

Code Golf: 2014 In ColdFusion

By
Published in Comments (8)

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.

Want to use code from this post? Check out the license.

Reader Comments

36 Comments

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

383 Comments

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.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel