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
fizzbuzz 从字面上看只是一个测试,旨在查看您是否能够掌握绝对的编程基础知识并自己解决一个非常简单的问题,而不是您的模数知识
>>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.
将模式的一次完整迭代作为数组写入程序内存中,但内容是“函数”(实际上只是内联它,但将它们视为更高抽象级别上的函数),它们采用基数并返回该数字的偏移量(例如 x + 1,或模式的适当步骤的 fizz/buzz)。主循环迭代函数数组,然后将基数增加模式的长度。
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
就按照马上>>109570570所说的去做
>>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.
不需要。只需对 15 步后重复的模式使用单个重置计数器即可。
The you optimize for lines 1, 3, and 5 that all have n, n+1, fizz and move that to a subroutine.
您对第 1、3 和 5 行进行优化,这些行都具有 n、n+1、fizz 并将其移至子例程。
>>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
- 如果 k 除以 n --> I_k(n) = 1
- If k !divides n --> I_k(n) = 0
- 如果 k !除以 n --> I_k(n) = 0
>Example 1: k = 3 ("Fizz")
>示例 1:k = 3(“嘶嘶声”)
The 3rd roots of unity are z_0 = 1, z_1 = -0.5 + i*(√3/2), z_2 = -0.5 - i*(√3/2)
三阶单位根为 z_0 = 1、z_1 = -0.5 + i*(√3/2)、z_2 = -0.5 - i*(√3/2)
Testing n = 3 (Divisible):
测试 n = 3(可整除):
(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"
I_3(3) = (1/3) * (1 + 1 + 1) = 3/3 = 1 --> “嘶嘶”
Testing n = 2 (Not Divisible):
测试 n = 2(不可整除):
(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"
I_3(2) = (1/3) * (1 - 0.5 - 0.5 + 0i) = 0 --> 无“嘶嘶声”
>Example 2: k = 5 ("Buzz")
>示例 2:k = 5(“嗡嗡声”)
The 5th roots of unity form a 5 pointed regular star/pentagon around the complex unit circle spaced at 72°
单位圆的 5 次根在复数单位圆周围形成一个 5 角正星/五边形,间隔为 72°
Testing n = 5 (Divisible):
测试 n = 5(可整除):
Every root (z_m)^5 = e^(i * 2π * m) = 1
每个根 (z_m)^5 = e^(i * 2π * m) = 1
I_5(5) = (1/5) * (1 + 1 + 1 + 1 + 1) = 5/5 = 1 --> "Buzz"
I_5(5) = (1/5) * (1 + 1 + 1 + 1 + 1) = 5/5 = 1 --> “嗡嗡声”
Testing n = 1 (Not Divisible):
测试 n = 1(不可整除):
Summing the vertices of a centered 5-gon:
对中心 5 边形的顶点求和:
Re = 1 + 2*cos(72°) + 2*cos(144°) = 1 + (√5-1)/2 - (√5+1)/2 = 0
Re = 1 + 2*cos(72°) + 2*cos(144°) = 1 + (√5-1)/2 - (√5+1)/2 = 0(数学推导:实部为 0)
Im = sin(72°) - sin(72°) + sin(144°) - sin(144°) = 0
Im = sin(72°) - sin(72°) + sin(144°) - sin(144°) = 0(数学推导:虚部为 0)
I_5(1) = (1/5) * (0 + 0i) = 0 --> No "Buzz"
I_5(1) = (1/5) * (0 + 0i) = 0 --> 无“嗡嗡声”
(如果你觉得这篇文章有启发,可以点击这里付费)