Earlier quoted context omitted.
> Sort of fun to muse whether almost all FizzBuzz implementations are a bit wrong. They're only wrong if they provide output that isn't in the spec. Adding "bazz" isn't in the spec, and assuming that something indeterminate MIGHT come later is also not part.
Yep, that's how people answer. Folks really really don't like thinking that "FizzBuzz" case maybe shouldn't be there, future extension or factor edit or no. // And as long as we're just manually computing factor times factor and typing out the results for it like "FizzBuzz" we might as well just hardcode the whole series...
Solving Fizz Buzz with Cosines
41–50 of 69 posts
Re: Solving Fizz Buzz with Cosines
#42I wonder where this is coming from. I saw on USENET in comp.os.linux.misc a conversation about fizzbuzz too. That was on Nov 12. Anyway an interesting read.
Re: Solving Fizz Buzz with Cosines
#43Re: Solving Fizz Buzz with Cosines
#44While it's cute use of mathematics, it's extremely inefficient in the real world because it introduces floating point multiplications and cos() which are very expensive. The only thing it lacks is branching which reduces the chances of a pipeline stall due to branch prediction miss. (The divisions will get optimized away.)
This can be translated to the discrete domain pretty easily, just like the NTT. Pick a sufficiently large prime with order 15k, say, p = 2^61-1. 37 generates the whole multiplicative group, and 37^((2^61-2)/3) and 37^((2^61-2)/5) are appropriate roots of unity. Putting it all together yields f(n) = 5226577487551039623 + 1537228672809129301*(1669582390241348315^n + 636260618972345635^n) + 3689348814741910322*(72555445…
Re: Solving Fizz Buzz with Cosines
#45- increases i on every \n,
- prints i when that produces x, otherwise prints the character
(Disregarding rounding errors)
That would be fairly obfuscated, I think.
Re: Solving Fizz Buzz with Cosines
#46Re: Solving Fizz Buzz with Cosines
#47 from pysr import PySRRegressor
def f(n):
if n % 15 == 0:
return 3
elif n%5 == 0:
return 2
elif n%3 == 0:
return 1
return 0
n = 500
X = np.array(range(1,n)).reshape(-1,1)
Y = np.array([f(n) for n in range(1,n)]).reshape(-1,1)
model = PySRRegressor(
maxsize=25,
niterations=200, #
) model.fit(X,Y)
Result I got is this:((cos((x0 + x0) * 1.0471969) * 0.66784626) + ((cos(sin(x0 * 0.628323) * -4.0887628) + 0.06374673) * 1.1508249)) + 1.1086457
with compleixty 22 loss: 0.000015800686 The first term is close to 2/3 * cos(2pi*n/3) which is featured in the actual formula in the article. the constant doesn't compare to 11/15 though
Re: Solving Fizz Buzz with Cosines
#48https://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
There was another great satirical take on FizzBuzz which had something to do with runes and incantation and magical spells...? I sort of remember that the same author maybe even wrote a follow up? to this extremely experienced developer solving FizzBuzz in the most arcane way possible. Does this ring a bell for anyone? --- Found it! https://aphyr.com/posts/340-reversing-the-technical-intervie... https://aphyr.com/pos…
Does aphyr even have comments, or is it a pure political protest?
That's the first thing that's tempted to break out an ssh tunnel - I can live without the occasional NSFW reddit group.
Re: Solving Fizz Buzz with Cosines
#49What 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
That's the most expletive-laden LLM output I've ever seen. ChatGPT would have aborted half way through to protect its pure and unsullied silicon mind from the filthy impure thoughts.
That was a fun read, but I can see that persona quickly becoming wearing. I had a "talk like a wiki article" persona for a while that worked better (for me) than any attempt to inject personality. The greyer the better, when it comes to tools.
(Being a child of the internet rather than the classroom my abusive solution would be to look up the sequence in OEIS, but I think fizzbuzz could be encoded into an L-system quite neatly).
Re: Solving Fizz Buzz with Cosines
#50Earlier quoted context omitted.
There was another great satirical take on FizzBuzz which had something to do with runes and incantation and magical spells...? I sort of remember that the same author maybe even wrote a follow up? to this extremely experienced developer solving FizzBuzz in the most arcane way possible. Does this ring a bell for anyone? --- Found it! https://aphyr.com/posts/340-reversing-the-technical-intervie... https://aphyr.com/pos…
"Unavailable Due to the UK Online Safety Act" Does aphyr even have comments, or is it a pure political protest? That's the first thing that's tempted to break out an ssh tunnel - I can live without the occasional NSFW reddit group.