Last active
August 29, 2015 14:06
-
-
Save ridhoq/3dd4775de22f2e08161c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
function BK() { | |
var self = this; | |
this.bkList = []; | |
this.seenConditionBefore = function(n) { | |
if (self.bkList[self.calculateConditionIndex(n)]) | |
return true; | |
else | |
return false; | |
}; | |
this.calculateConditionIndex = function(n) { | |
var setCondition = 0; | |
if (self.divisibleByFive(n)) | |
setCondition = setCondition | 1; | |
if (self.divisibleBySeven(n)) | |
setCondition = setCondition | 2; | |
if (self.containsFive(n)) | |
setCondition = setCondition | 4; | |
if (self.containsSeven(n)) | |
setCondition = setCondition | 8; | |
console.log(setCondition); | |
return setCondition; | |
}; | |
this.divisibleByFive = function(n) { | |
if (n % 5 == 0) | |
return true; | |
else | |
return false; | |
}; | |
this.divisibleBySeven = function(n) { | |
if (n % 7 == 0) | |
return true; | |
else | |
return false; | |
}; | |
this.containsFive = function(n) { | |
var s = n.toString(); | |
if (s.indexOf(5) != -1) | |
return true; | |
else | |
return false; | |
}; | |
this.containsSeven = function(n) { | |
var s = n.toString(); | |
if (s.indexOf(7) != -1) | |
return true; | |
else | |
return false; | |
}; | |
}; | |
var game = new BK(); | |
//counter | |
var i = 1; | |
//# of combinations of all conditions | |
var conditions = 16; | |
while(conditions > 0) { | |
if (!game.seenConditionBefore(i)) { | |
var conditionIndex = game.calculateConditionIndex(i); | |
game.bkList[conditionIndex] = i; | |
conditions--; | |
} | |
i++; | |
} | |
console.log(game.bkList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment