-
-
Save sethschori/fef944fc24f9c8ac9487751cfa9fc23e to your computer and use it in GitHub Desktop.
https://repl.it/CPrZ/53 created by sethopia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Log 'Hello World' to the console in as convoluted and zany a way as possible! | |
//See some heroic examples in various languages here: http://codegolf.stackexchange.com/questions/4838/most-complex-hello-world-program-you-can-justify | |
//Define the function here | |
var helloWorld = function() { | |
var abc = 'abcdefghijklmnopqrstuvwxyz'; | |
// declare the add function which will be used in decoderRing operations | |
function add(startingValue, argumentValue) { | |
return startingValue + argumentValue; | |
} | |
// declare the subtract function which will be used in decoderRing operations | |
function subtract(startingValue, argumentValue) { | |
return startingValue - argumentValue; | |
} | |
// declare the decoderRing which tells us how to determine each letter of our message | |
var decoderRing = [ | |
[add, 33], | |
[subtract, 29], | |
[add, 7], | |
[add, 0], | |
[add, 3], | |
[add, 38], | |
[subtract, 4], | |
[subtract, 34], | |
[add, 3], | |
[subtract, 6], | |
[subtract, 8] | |
]; | |
// var order = [33,4,11,11,14,52,48,14,17,11,3]; | |
function constructMessage() { | |
// initialize destinationArr for message output | |
var messageArr = []; | |
// make the full alphabet to work with | |
var alphabetArr = makeAlphabet(abc); | |
// set the initial value that will be fed into the decoderRing | |
var currentDecoderValue = 0; | |
// loop through the decoderRing and pass each decoded letter into destinationArr for message output | |
var nextLetter = ""; | |
for (var i = 0; i < decoderRing.length; i++) { | |
nextLetterPosition = readDecoderRing(currentDecoderValue, i); | |
messageArr.push(alphabetArr[nextLetterPosition]); | |
currentDecoderValue = nextLetterPosition; | |
} | |
return messageArr; | |
} | |
function makeAlphabet() { | |
return abc.split('').concat(abc.toUpperCase().split('').concat(' ')); | |
} | |
function readDecoderRing(currentDecoderValue, decoderRingPosition) { | |
// get the function and argument to perform from the next position on the decoderRing | |
var nextFunction = decoderRing[decoderRingPosition][0]; | |
var nextArgument = decoderRing[decoderRingPosition][1]; | |
// perform the operation using the argument | |
var returnValue = nextFunction(currentDecoderValue, nextArgument); | |
// return the newly decoded decoderRing value | |
return returnValue; | |
} | |
// return the message | |
return constructMessage().join(''); | |
} | |
//Invoke it here | |
console.log(helloWorld()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native Browser JavaScript | |
>>> Hello World |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment