Hello! I wrote this post. I know your comment was a lighthearted one, but I found it interesting, so I just wanted to share that it is quite straightforward to extend the solution to numbers divisible by 7. The indicator functions-based solution simply becomes:
for n in range(1, 1001):
s = [n, 'Fizz', 'Buzz', 'FizzBuzz', 'Jazz', 'FizzJazz', 'BuzzJazz', 'FizzBuzzJazz']
i = (n % 3 == 0) + 2 * (n % 5 == 0) + 4 * (n % 7 == 0)
print(s[i])
For the cosine-based solution, we only need to translate the additional term 4 * (n % 7 == 0) to 4 * (1/7) * sum_{k=0}^6 e^(2 * pi * i * k * n / 7) = 4 * (1/7 + (2/7) * cos(2 * pi * n / 7) + (2/7) * cos(4 * pi * n / 7) + (2/7) * cos(6 * pi * n / 7)). When we add it to the existing solution, we get this:
from math import cos, pi
for n in range(1, 1001):
s = [n, 'Fizz', 'Buzz', 'FizzBuzz', 'Jazz', 'FizzJazz', 'BuzzJazz', 'FizzBuzzJazz']
i = round((137 / 105) + (2 / 3) * cos(2 * pi * n / 3)
+ (4 / 5) * cos(2 * pi * n / 5)
+ (4 / 5) * cos(4 * pi * n / 5)
+ (8 / 7) * cos(2 * pi * n / 7)
+ (8 / 7) * cos(4 * pi * n / 7)
+ (8 / 7) * cos(6 * pi * n / 7))
print(s[i])
It is worth noting that i can be viewed as a flag in which each bit corresponds to whether Fizz, Buzz or Jazz appears in the nth term of the sequence. All other details follow from this idea.
from math import cos, pi
for n in range(1, 101):
print([n, 'Fizz', 'Buzz', 'FizzBuzz'][round(11 / 15 + (2 / 3) * cos(2 * pi * n / 3) + (4 / 5) * (cos(2 * pi * n / 5) + cos(4 * pi * n / 5)))])
from math import cos, pi
for n in range(1, 101):
print([n, 'Fizz', 'Buzz', 'FizzBuzz'][round(11 / 15 + (2 / 3) * cos(2 * pi * n / 3) + (4 / 5) * (cos(2 * pi * n / 5) + cos(4 * pi * n / 5)))])
Jwosty@reddit
This is the exactly kind of thing that should win an obfuscation contest. I hate it but also I love it
obetu5432@reddit
me vs. the other guy interviewing for the same position:
SergiusTheBest@reddit
Hah, nowadays it's solved by a simple LLM that requires an Nvidia GPU with 16 GB of VRAM.
currentscurrents@reddit
RNNs are turing complete, it should be possible to implement FizzBuzz within neural network weights.
Trang0ul@reddit
It reminds me jQuery hype...
gerthworm@reddit
"Do FizzBuzz, but solve it like an EE"
KamiKagutsuchi@reddit
You asked for it... https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
SpringDifferent9867@reddit
Hah. Imagine being an electrical engineer and realize what you just got yourself into there.
FlyingRhenquest@reddit
I LOLED entirely too hard at this.
sccrstud92@reddit
Might be having an "EE" overloading issue here
Lucas_F_A@reddit
I wonder if an implementation in Rust or C of the indicator function version and the typical if else version might optimize down into the same code.
aaronsb@reddit
Don't forget, FizzBuzz as tensor representations: https://github.com/aaronsb/fizzbuzztensor
Isogash@reddit
Gonna memorize this for my next technical interview so I can say "and then we apply the FizzBuzz formula"
Trang0ul@reddit
Recruiter: "Great! Now please extent it by using 'Jazz' if the number is divisible by 7."
susam@reddit
Hello! I wrote this post. I know your comment was a lighthearted one, but I found it interesting, so I just wanted to share that it is quite straightforward to extend the solution to numbers divisible by 7. The indicator functions-based solution simply becomes:
For the cosine-based solution, we only need to translate the additional term 4 * (n % 7 == 0) to 4 * (1/7) * sum_{k=0}^6 e^(2 * pi * i * k * n / 7) = 4 * (1/7 + (2/7) * cos(2 * pi * n / 7) + (2/7) * cos(4 * pi * n / 7) + (2/7) * cos(6 * pi * n / 7)). When we add it to the existing solution, we get this:
It is worth noting that
ican be viewed as a flag in which each bit corresponds to whetherFizz,BuzzorJazzappears in the nth term of the sequence. All other details follow from this idea.mr_birkenblatt@reddit
That just adds three (?) extra terms and you need to change the coefficients a bit. I didn't do the math but it's not that hard
omepiet@reddit
This is morally degenerate. Also, it works.
bythenumbers10@reddit
The things you have to do with low-level languages like math and VHDL.
brightlystar@reddit
The working code is buried at the bottom:
Plank_With_A_Nail_In@reddit
Its in the conclusion where it is supposed to be not buried lol.
brightlystar@reddit
TL;DR
sad_cosmic_joke@reddit
This is grotesque.... Love it! <3
speicherwerk@reddit
Tought it was cosiness, but the math caused me distress.