What's a "disguised Boolean" in this context?
[deleted]
41–50 of 72 posts
What's a "disguised Boolean" in this context?
Do indexes count? If not, there's a simple one liner
def fizzbuzz(n):
return [str(n), "fizz", "buzz", "fizzbuzz"][1-min(1, n%3) + (1-min(1,n%5))*2]What's a "disguised Boolean" in this context?
Earlier quoted context omitted.
There's a conditional, though?
Yeah this is weird. It's against the rules to speculate about whether a commenter read the article, but what about the title of the article?
#include
#include
#include
void fizzbuzz(int i) {
uint32_t r3 = i % 3;
uint32_t r5 = i % 5;
uint32_t is_nonzero_3 = (r3 | -r3) >> 31;
uint32_t is_nonzero_5 = (r5 | -r5) >> 31;
uint32_t is_zero_3 = is_nonzero_3 ^ 1;
uint32_t is_zero_5 = is_nonzero_5 ^ 1;
uint32_t idx = (is_zero_5 > 31;
}
func_t actions_table[] = { run_loop, stop_loop };
void run_loop_wrapper(int i) {
fizzbuzz(i);
int d = 99 - i;
uint32_t is_neg = ((uint32_t)d) >> 31;
actions_table[is_neg](i + 1);
}
int main() {
actions_table[0] = run_loop_wrapper;
run_loop_wrapper(1);
return 0;
} fizzbuzz = [None, None, "Fizz", None, "Buzz", "Fizz", None, None, "Fizz", "Buzz", None, "Fizz", None, None, "FizzBuzz"]
for i in range(1,100):
print(fizzbuzz[i % 15] or i)
Edit: I see I was a few hours late, and someone posted nearly the exact same solution. :( from math import cos, pi
for n in range(1, 101):
print([n, 'Fizz', 'Buzz', 'FizzBuzz'][round((1 + 2 * cos(2 * pi * n / 3)) / 3 + 2 * (1 + 2 * cos(2 * pi * n / 5) + 2 * cos(4 * pi * n / 5)) / 5)]) def main():
fizz_array = ["Fizz", "", ""]
buzz_array = ["Buzz", "", "", "", ""]
for n in range(1, 101):
# Use modulo to index into arrays
f = fizz_array[n % 3]
b = buzz_array[n % 5]
# Combine fizz and buzz
result = f + b
output = result + str(n)[len(result):]
print(output)
main()
I couldn't figure out this line and had to rely on AI for it. output = result + str(n)[len(result):] from itertools import cycle
fizz = cycle(["","","fizz"])
buzz = cycle(["","","","","buzz"])
for z in zip(fizz,buzz):
print(f"{z[0]}{z[1]}")