Skip to content

Instantly share code, notes, and snippets.

@tkissing
Forked from 140bytes/LICENSE.txt
Created November 12, 2011 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkissing/1360238 to your computer and use it in GitHub Desktop.
Save tkissing/1360238 to your computer and use it in GitHub Desktop.
MiniGame in 140byt.es

Simple console number-guessing game.

function(a, b, c) {
c = [];
// fill an array with 5 random numbers between 1 and the upper bound provided by a
for (b = 5; b--; c[b] = 1 | a * Math.random());
// return a "game instance"
return function(d) { // d needs to be an array/object with numbers at index 0..5
b = [];
// compare the 5 random numbers with those provided by the player
for (a = 5; a--; b[a] = d[a] == c[a] || c[a] % d[a]);
// if all 5 numbers match, the string representations of the arrays are equal - return true
// otherwise return the array with the matches and modulo values
return d + '' == c || b;
}
}
game = function(a,b,c){c=[];for(b=5;b--;c[b]=1|a*Math.random());return function(d){b=[];for(a=5;a--;b[a]=d[a]==c[a]||c[a]%d[a]);return d+''==c||b}};
// >>> function()
g = g || game(6);
// >>> function()
g([3,2,3,3,5]);
// >>> [2, 1, true, 2, 1]
g([1,1,3,1,4]);
// >>> [0, true, true, 0, 1]
g([5,1,3,5,1]);
// >>> true
function(a,b,c){c=[];for(b=5;b--;c[b]=1|a*Math.random());return function(d){b=[];for(a=5;a--;b[a]=d[a]==c[a]||c[a]%d[a]);return d+''==c||b}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "yetAnother140bytesEntry",
"description": "This should be a short description of your entry, but it isn't yet.",
"keywords": [
"140bytes",
"game"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment