Skip to content

Instantly share code, notes, and snippets.

@livingston
Created April 24, 2010 20:58
Show Gist options
  • Save livingston/377936 to your computer and use it in GitHub Desktop.
Save livingston/377936 to your computer and use it in GitHub Desktop.
SPOJ 1. Life, the Universe, and Everything
/* 1. Life, the Universe, and Everything
Problem code: TEST
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything.
More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42.
All numbers at input are integers of one or two digits.
Example:
Input: 1 2 88 42 99
Output: 1 2 88
*/
var SPOJ_01 = function () {
var result = '', len = arguments.length, args = [].reverse.call(arguments), value;
while(len--) {
value = args[len];
if(value !== 42) {
result += value + ' ';
}
}
return result;
};
@BartekKwapisz
Copy link

BartekKwapisz commented Mar 12, 2017

For SPOJ you'll need to use readline() for Input and print() for Output.
(read more at MDN JS shell intro)
The shortest solution I found is:
while((num = readline()) != 42) {
print(num);
}

PS: It breaks if you skip num and just type:
while(readline() != 42) { print( readline() ); }

@yashydv243
Copy link

With Ada.Text_IO; Use Ada.Text_IO;
With Ada.Integer_Text_IO; Use Ada.Integer_Text_IO;

-- your code goes here
var SPOJ-01 = function () {
var result = '', len = arguments.length, args = Array.prototype.reverse.call(arguments), value;
while(len--) {
value = args[len];
if(value !== 42) {
result += value + ' ';
}
}

return result;

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment