Fifty Fizzbuzzes
vihart.com
vihart.com
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)https://mybinder.org/v2/gh/quasiben/fiftyfizzbuzzes/master?f...
In the meantime, enjoy the ever-classic Fizz Buzz Enterprise Edition:
https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
The point is that there is no "core" logic anymore. It's been broken down and spread out over a dozen files, each of which does "one and only one (tiny) thing" according to the "best practices" of problem decomposition. Then all the pieces are glued together again using design patterns.
This is a common complaint from people I discussed the project with, and the obvious reason for the success of the project in terms of people contributing patches and issues.
https://github.com/jongeorge1/FizzBuzzEnterpriseEdition-CSha...
https://github.com/tonyedgecombe/functionalfizzbuzz/blob/mas...
The code on GitHub is here: https://github.com/vihart/fiftyfizzbuzzes/blob/master/Fifty%...
That explains a LOT. As in most descriptions of it are annoyingly ambiguous.
Whereas if you knew the game, you know it already.
My very first interviewer (intentionally) didn't spec fizzbuzz correctly. The real test was whether the candidate listened to the customer's/lead engineer's spec instead of jumping to conclusions.
Fortunately, I was just entering college and hadn't heard of fizzbuzz before. I passed the "test" but for the wrong reason.
Array.from(new Array(100)).forEach((_, i)=>++i&&console.log(((i%3?"":"Fizz")+(i%5?"":"Buzz"))||i))
https://twitter.com/tracker1/status/1045475226128007169https://github.com/skx/gobasic/blob/master/examples/15-fizz-...
Perhaps not the cleanest, since I support neither `CASE` nor `ELSE IF`. But it seems to be correct.
#include <stdlib.h>
#include <stdio.h>
static const char str[] = "fizzbuzz";
static inline void out(int i, size_t offset, size_t sz)
{
if (sz) {
fwrite(str + offset, sz, 1, stdout);
} else {
fprintf(stdout, "%d", i);
}
putchar('\n');
}
int main(void)
{
for (int i = 1; i <= 100; i++) {
int a = i % 3 == 0;
int b = i % 5 == 0;
out(i, 4*((a^b)&b), 4*(a+b));
}
exit(0);
}
There's a way to remove that conditional, too. Probably. {:[~x!15;"fizzbuzz";~x!3;"fizz";~x!5;"buzz";$x]}'1+!100
{:[0<#w::[x!3;"";"fizz"],:[x!5;"";"buzz"];w;$x]}'1+!100 {∊(3↑(0=3 5|⍵)∪1)/'Fizz' 'Buzz'⍵}¨⍳100
https://tryapl.org/?a=%7B%u220A%283%u2191%280%3D3%205%7C%u23...write Spectre/timing attacks resilient fizzbuzz.
But using Wordpress is no more overengineering than buying a car. (Versus building your own 2 stroke engine because it's simpler).