Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Created August 11, 2012 13:35
Show Gist options
  • Save mike-neck/3324473 to your computer and use it in GitHub Desktop.
Save mike-neck/3324473 to your computer and use it in GitHub Desktop.
素数の時にEnrico Pucciと出力するプログラム。
var jojo;
(function () {
jojo = jojo || {};
jojo.bizarre = jojo.bizarre || {};
jojo.bizarre.pucci = function (number, element, maxNumber) {
var base = element || 2,
mod = number % base,
max = maxNumber || (number - mod) / base + 1;
if (base >= max) return true;
if (mod === 0) return false;
return jojo.bizarre.pucci(number, base + 1, max);
};
jojo.bizarre.Stand = function (from, to) {
var condition = from < to,
min = condition ? from : to,
max = condition ? to : from,
item = from,
limit = function (number) {return condition ? number <= to : number >= to;},
increment = condition ? 1 : -1,
size = max - min + 1,
index = 0,
array = new Array (size);
for (; limit(item); item += increment, index++) {
array[index] = item;
}
return array;
};
}) ();
var enricoPucci = function () {
var Range = jojo.bizarre.Stand,
isPrime = jojo.bizarre.pucci;
Range(1,100).forEach(function (e){
console.log(isPrime(e) ? "Enrico Pucci" : e);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment