by codereflection · 8y ago · 0 comments
let tokens = [];
tokens.push("Fizz", "Buzz", "Fizzbuzz");
for (let i = 0; i <= 100; i++) { tokens.push(i); }
function generateFizzBuzz(n) {
if (n > 100) { return [[]]; }
let result = [];
for (let token of tokens) {
for (let tail of generateFizzBuzz(n+1)) {
tail.splice(0, 0, token);
result.push(tail);
}
}
return result;
}
let candidates = generateFizzBuzz(1);
while (candidates.length > 1) {
let candidateIndex = Math.floor(Math.random() * candidates.length);
let candidate = candidates[candidateIndex];
let checkIndex = Math.floor(Math.random() * 100);
let expected = checkIndex % 3 == 0
? (checkIndex % 5 == 0 ? "Fizzbuzz" : "Fizz")
: (checkIndex % 5 == 0 ? "Buzz" : checkIndex);
if (candidate[checkIndex] !== expected) {
candidates.splice(candidateIndex, 1);
}
}
return candidates[0];Based on a true story, sadly:
#! /usr/bin/tail -n+2
1
2
Fizz
4
Buzz
[...]
98
Fizz
Buzz
On the other hand, there's also ones like: let{a="ssfsbfssfbsfssX"++a;x 's'=show;x 'f'=const"Fizz";x 'b'=const"Buzz";x 'X'=const"FizzBuzz"}in putStrLn$concat$map(\(i,f)->x f i++"\n")(zip[1..100]a)
(because who needs divisibility tests, right?) a=[1:100];
b=strcat({'','fizz'}([1+!mod(a,3)]),{'','buzz'}([1+!mod(a,5)]));
a=num2cell(int16(cellfun(@isempty,b)).*a);
b(cellfun(@isempty,b))=0;
strcat(b,a)