This works from 1 to 100000000000000000000 before it overflows, and 100000000000000000000 is above the max size of a unsigned 64 bit int, so I feel that it's good enough
fizzbuzz = [
"fizzbuzz ",
"", "",
"fizz ",
"",
"buzz ",
"fizz ",
"", "",
"fizz ",
"buzz ",
"",
"fizz ",
"", "" ]
for n in range(99999999999999999999-30, 100000000000000000000):
print(f"{n}\r{fizzbuzz[n%15]}") const Fizzbuzz = "1 2. Fizz, 4 ... "
Print Fizzbuzz import (
"fmt"
"math/rand"
)
var fb [4]string = [4]string{"", "fizz", "buzz", "fizzbuzz"}
var lucky int64 = 176064004
func main() {
for i := 1; i <= 100; i++ {
if i%15 == 1 {
rand.Seed(lucky)
}
fmt.Printf("%d: %s\n", i, fb[rand.Int63()%4])
}
}Now I see it's the same solution as in the post.
Saying the code doesn’t have conditions or booleans is only true if you completely ignore how the functions being called are being implemented.
Cycle involves conditionals, zip involves conditionals, range involves conditionals, array access involves conditionals, the string concatenation involves conditionals, the iterator expansion in the for loop involves conditionals.
This has orders of magnitude more conditionals than normal fizz buzz would.
Even the function calls involve conditionals (python uses dynamic dispatch). Even if call site caching is used to avoid repeated name lookups, that involves conditionals.
There is not a line of code in that file (even the import statement) that does not use at least one conditional.
So… interesting implementation, but it’s not “fizzbuzz without booleans or conditionals”.
baring that I too got nerd sniped by this and unsatified by the limitations of the authors solution here is my attempt. and when I read up on fizzbuz to make sure I was solving the correct thing. (I was not and my elagent duel state engine was wasted) it turns out the problem solution could be as simple as
f_out = ['', '', 'fizz']
b_out = ['', '', '', '', 'buzz']
def fizzbuz(n):
return(f_out[n % 3] + b_out[n % 5])I mean, if we want to play fast and loose with those definitions then this also has no conditionals and no booleans.(Warning: Perl, somewhat golfed)
$s = '', $i % 3 || ($s .= 'fizz'), $i % 5 || ($s .= 'buzz'), $s ||= $i, print "$s\n" while (++$i < 101)
stop50•5d ago