Solving Fizz Buzz with Cosines

susam.net

99 points by hprotagonist 6 hours ago


nine_k - 3 hours ago

Well, there must be an obvious solution where the fizzbuzz sequence is seen as a spectrum of two frequencies (1/3 and 1/5), and a Fourier transform gives us a periodic signal with peaks of one amplitude at fizz spots, another amplitude at buzz spots, and their sum at fizzbuzz spots. I mean. that would be approximately the same solution as the article offers, just through a more straightforward mechanism.

thomasjudge - 5 hours ago

https://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/

ok123456 - 2 hours ago

I once had a coworker who used the FFT to determine whether coordinates formed a regular 2D grid. It didn't really work because of the interior points.

isoprophlex - 3 hours ago

What a neat trick. I'm thinking you can abuse polynomials similarly. If the goal is to print the first, say, 100 elements, a 99-degree polynomial would do just fine :^)

EDIT: the llm gods do recreational mathematics as well. claude actually thinks it was able to come up with and verify a solution...

https://claude.ai/share/5664fb69-78cf-4723-94c9-7a381f947633

layer8 - 3 hours ago

I think that implementation will break down around 2^50 or so.

siegelzero - 4 hours ago

Very cool! There's definitely some similarity to Ramanujan Sums, though the approach here sort of packages the fizz-buzz divisibility properties into one function. https://en.wikipedia.org/wiki/Ramanujan%27s_sum

tantalor - 4 hours ago

There are several mentions of "closed-form expression" without precisely defining what that means, only "finite combinations of basic operations".

TFA implies that branches (if statements and piecewise statements) are not allowed, but I don't see why not. Seems like a basic operation to me.

Nevermind that `s[i]` is essentially a piecewise statement.

throwaway81523 - an hour ago

Where the madness leads: https://cspages.ucalgary.ca/~robin/class/449/Evolution.htm

- 4 hours ago
[deleted]
ivan_ah - 5 hours ago

This is very nice.