Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2016 18:35
Show Gist options
  • Save anonymous/1b58ccd58e5cd8543b9efe6c6f1c238e to your computer and use it in GitHub Desktop.
Save anonymous/1b58ccd58e5cd8543b9efe6c6f1c238e to your computer and use it in GitHub Desktop.
https://repl.it/CPrZ/53 created by sethopia
//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());
Native Browser JavaScript
>>> Hello World
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment