2026年8月16日 · 星期日
● 每日更新·改变自己
Eurekar·TOP
捕捉真实世界的英语信号
25信息来源
11,906精选文章
168单词卡片
18照片图片
全部7,967口语2,071外贸4免费944帖子3,648新闻1,602hackernews1,157techmeme661tmz640slashdot475techcrunch433arstechnica373随笔323外刊291Cards168simonwillison100sethgodin60bloomberg60图片18youtube7

How do you solve it efficiently without the use of a modulo operator.

4chan /g/ · Anonymous · 2026-08-16 11:12 · 10 帖 · 原文 ↗

← 上一篇返回列表下一篇 →
#1 How do you solve it efficiently without the use of a modulo operator.
Anonymous · 2026-08-16 11:12

How do you solve it efficiently without the use of a modulo operator.

图片: https://i.4cdn.org/g/1786878746314677.png

#2 No.109570561
Anonymous · 2026-08-16 11:15

divide to decimal and check if its a whole number

#3 No.109570570
Anonymous · 2026-08-16 11:17

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

#4 No.109570622
Anonymous · 2026-08-16 11:28

>>109570561

>>109570570

Thats a slimy way to solve it, you are doing modulo repackaged.

#5 No.109570632
Anonymous · 2026-08-16 11:31

>>109570549

study number theory op

#6 No.109570826
Anonymous · 2026-08-16 12:12

>>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

#7 No.109570880
Anonymous · 2026-08-16 12:24

>>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)

#8 No.109570934
Anonymous · 2026-08-16 12:33

>>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.

#9 No.109570952
Anonymous · 2026-08-16 12:37

>>109570549

I make the ai do it while I think what I will cook for dinner

#10 No.109570969
Anonymous · 2026-08-16 12:40

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"

← 上一篇返回列表下一篇 →

(如果你觉得这篇文章有启发,可以点击这里付费