Simple console number-guessing game.
-
-
Save tkissing/1360238 to your computer and use it in GitHub Desktop.
MiniGame in 140byt.es
This file contains 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
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; | |
} | |
} |
This file contains 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
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 |
This file contains 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
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}} |
This file contains 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
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. |
This file contains 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
{ | |
"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