How do you solve it efficiently without the use of a modulo operator.
How do you solve it efficiently without the use of a modulo operator.
divide to decimal and check if its a whole number
just make two resetting counters
fizzbuzz literally was just a test designed to see if you're able to do the absolute basics of programming and solve a really simple problem yourself, not your modulo knowledge
>>109570561
>>109570570
Thats a slimy way to solve it, you are doing modulo repackaged.
>>109570549
study number theory op
>>109570549
>cycle efficiency
Write one full iteration of the pattern into the program memory as an array, but contents are "functions" (just inline it in practice, but consider them functions on the higher level of abstraction) that take a base number and return an offset from that number (e.g. x + 1, or fizz/buzz for the appropriate steps of the pattern). Your main loop iterates over the array of functions, then increments the base number by the length of the pattern.
The base number can sit in a secondary register since it doesn't need to be updated that often, so the assembly code is just loading a value into the primary register, adding the secondary register (if your assembly language doesn't let you do that in one step...), and writing it out to console. Plus a few diversions into whatever the string handling code looks like.
>(program) memory efficiency / lines of code
Just do what this anon >>109570570 said
>>109570826
>so the assembly code is just loading a value into the primary register
Oh, right, or you can just use increments since the values will always be sequential (except for the gaps created by fizz/buzz outputs)
>>109570570
>just make two resetting counters
No. Just use a single resetting counter for a pattern that repeates after 15 steps.
The you optimize for lines 1, 3, and 5 that all have n, n+1, fizz and move that to a subroutine.
>>109570549
I make the ai do it while I think what I will cook for dinner
I_k(n) = (1/k) * SUM_{m=0..k-1} e^(2 * pi * i * m * n / k)
- If k divides n --> I_k(n) = 1
- If k !divides n --> I_k(n) = 0
>Example 1: k = 3 ("Fizz")
The 3rd roots of unity are z_0 = 1, z_1 = -0.5 + i*(√3/2), z_2 = -0.5 - i*(√3/2)
Testing n = 3 (Divisible):
(z_0)^3 = 1^3 = 1
(z_1)^3 = e^(i * 2π) = 1
(z_2)^3 = e^(i * 4π) = 1
I_3(3) = (1/3) * (1 + 1 + 1) = 3/3 = 1 --> "Fizz"
Testing n = 2 (Not Divisible):
(z_0)^2 = 1
(z_1)^2 = -0.5 - i*(√3/2)
(z_2)^2 = -0.5 + i*(√3/2)
I_3(2) = (1/3) * (1 - 0.5 - 0.5 + 0i) = 0 --> No "Fizz"
>Example 2: k = 5 ("Buzz")
The 5th roots of unity form a 5 pointed regular star/pentagon around the complex unit circle spaced at 72°
Testing n = 5 (Divisible):
Every root (z_m)^5 = e^(i * 2π * m) = 1
I_5(5) = (1/5) * (1 + 1 + 1 + 1 + 1) = 5/5 = 1 --> "Buzz"
Testing n = 1 (Not Divisible):
Summing the vertices of a centered 5-gon:
Re = 1 + 2*cos(72°) + 2*cos(144°) = 1 + (√5-1)/2 - (√5+1)/2 = 0
Im = sin(72°) - sin(72°) + sin(144°) - sin(144°) = 0
I_5(1) = (1/5) * (0 + 0i) = 0 --> No "Buzz"
(如果你觉得这篇文章有启发,可以点击这里付费)