4 ms·
Plus a program to produce the pre-calculated data, to avoid typos. :-)
by a3n 8y ago
Plus a program to produce the pre-calculated data, to avoid typos. :-)
- ben-schaaf 8y agoWhy not both at the same time. All you need is a language with compile-time execution: auto fizzbuzz(size_t n) { return iota(n) .map!((i) { if ((i % 15) == 0) { return "FizzBuzz"; } else if ((i % 3) == 0) { return "Fizz"; } else if ((i % 5) == 0) { return "Buzz"; } else { return i.to!string; } }); } void main() { // enum here forces compile-time execution enum fizzbuzz100 = fizzbuzz(100).join("\n"); writeln(fizzbuzz100); }
- a3n 8y agoOr: $ date +%A Tuesday $ anyfizzbuzzprogram > fizzbuzz100 $ cat fizzbuzz100 [output] $ date +%A Wednesday $ cat fizzbuzz100 [output] :-)