Euler's Fizzbuzz (2020)
31–40 of 92 posts
Re: Euler's Fizzbuzz (2020)
#32Maybe I'm being old and grumpy, but is there really a point to writing python without conditional logic? Each operation is going to have all sorts of stuff going in the interpreter, and the amount of code being executed that tiny snippet is way more than one would expect.
Re: Euler's Fizzbuzz (2020)
#33Re: Euler's Fizzbuzz (2020)
#34Not that anyone cares for FizzBuzz but I'll just note that n**4%15 is more efficiently written using the 3 argument pow function in python, eg pow(n, 4, 15).
>>> timeit("(1>> timeit("pow(1>>
If n gets large then n**4 is very large so the % 15 has to deal with a big number. pow runs the modulo operation at the same time as the power operation so the intermediates never get bigger than 15.Re: Euler's Fizzbuzz (2020)
#35This is of course a really neat solution, but the proof doesn't really give me much value as a reader. I am much more interested in an explanation of how to find this solution, than a theoretical solution of why it is correct. Specifically I don't understand from the article why the trick of raising n to the power of LCM(phi(3), phi(5)) works.
This is because your number theory-fu is poor.
Don't take this in a bad way, I'm probably even less capable. What I mean is that readability is predicated on a reader. Seasoned number theorists might not be as cool with goroutines or walrii operators or virtual DOMs.
Re: Euler's Fizzbuzz (2020)
#36Maybe I'm being old and grumpy, but is there really a point to writing python without conditional logic? Each operation is going to have all sorts of stuff going in the interpreter, and the amount of code being executed that tiny snippet is way more than one would expect.
Re: Euler's Fizzbuzz (2020)
#37Re: Euler's Fizzbuzz (2020)
#38Good luck running ^4 on larger numbers and overflowing integer / long bounds orders of magnitude faster than the plain "boring" solutions
Re: Euler's Fizzbuzz (2020)
#39Good luck running ^4 on larger numbers and overflowing integer / long bounds orders of magnitude faster than the plain "boring" solutions
n^4 % x = m
== (n % x)^4 % x = m
By way of demonstration: n = 18, x = 15
18^4 = 104976 = 6 (mod 15)
----
18 % 15 = 3
3^4 = 81 = 6 (mod 15)
A very handy result to remember for cases where you don't want to use or don't have easy access to arbitrary precision integers.Re: Euler's Fizzbuzz (2020)
#40Was this the expected answer to the coding interview question at places like Renaissance Technologies, Jane Street Capital, and Galois? This is really funny. I had an intuition there must be a lambda function solution for fizzbuzz, but I don't do coding interviews and never pursued it. I can see why now, because it's waaay out of my skillset, but so neat to read.