Hacker Newsnew | past | comments | ask | show | jobs | submit | philcrissman's commentslogin

Not sure how this came back around into the zeitgeist today, but this is my post from awhile back. Thanks to all who had nice things to say about it.

I'm definitely an amateur mathematician, though I tried my best to write the post like I think I'd try to write a proof. It came about because I stumbled across the equation, but I did not know _why_ it worked, so I was semi-obsessed with figuring out the _why_ for a long time.

I have nothing else to promote, haven't even put anything on the site since this one and only post... Anyways, thanks, news-YC.


This is a nice post; thanks for writing it! (A minor thing: the margin notes completely disappear on mobile, i.e. at width of 760px or less.)

You probably know this already, but I'd think of this the following way. There are two main mathematical ideas involved here:

• The first, easy to underrate because it can seem "obvious", is the Chinese remainder theorem. This, for instance, here implies that any function of the quantities (x mod 3) and (x mod 5) can be rewritten as a function of just (x mod 15). So if you used just this one idea and not the next one, you could implement FizzBuzz as

    lambda n: ['FizzBuzz', n, n, 'Fizz', n, 'Buzz', 'Fizz', n, n, 'Fizz', 'Buzz', n, 'Fizz', n, n][n % 15]
• The second is Fermat's little theorem. It says (x^(p-1) mod p) = [x is not a multiple of p], where the notation […] is Iverson bracket, i.e. 1 or 0 depending on whether the condition is true or not. So the question of whether x is a multiple of 5 or not is equivalent to whether x^4 mod 5 is 0 or 1. This just gives us a convenient way of restating the divisibility condition.

To get from Fermat's little theorem to Euler's theorem (or to be pedantic, Carmichael's theorem, as you're not using φ(15) which is technically 2*4 = 8, but rather using lcm(2, 4)=4: https://en.wikipedia.org/w/index.php?title=Carmichael_functi... ) is itself an application of the Chinese remainder theorem, which is why I think it's important and mentioned it first.

And putting these two ideas together gives the function in your post. Namely: the FizzBuzz you want is a function of [x is a multiple of 3] and [x is a multiple of 5], so you can (using the second idea) rewrite it as a function of (x^2 mod 3) and (x^4 mod 5), and put them together (using the CRT) as a function of (x^4 mod 15).

Coincidentally, both the ideas here are connected to Lagrange: the Chinese remainder theorem is the same kind of thing as the Lagrange interpolation formula (https://artofproblemsolving.com/community/c1157h990758_the_c...), and Fermat's/Euler's/Carmichael's theorem is the same kind of thing as Lagrange's theorem in group theory.


Thanks!

Re the margin notes, the footnote numbers are clickable to toggle them inline when the width is too small... I should add a bit of color or underline to them in the css so that this is easier to intuit. :/


Ah, clicking the footnote numbers worked for footnotes 1 to 4, but not for 5 and 6.

BTW, for the question “Where do the constant values 0, 6, 10, and 1 come from?”, though it's implicit in the post, it is useful to note explicitly that as x^4 takes only the values 0 or 1 either mod 3 or mod 5, these four possibilities—namely (0,0), (0,1), (1,0), (1,1)—precisely account for those values:

    (0 mod 3) and (0 mod 5) ⇔ (0 mod 15)
    (0 mod 3) and (1 mod 5) ⇔ (6 mod 15)
    (1 mod 3) and (0 mod 5) ⇔ (10 mod 15)
    (1 mod 3) and (1 mod 5) ⇔ (1 mod 15)
This would also simplify the post considerably maybe, as much of the algebra wouldn't be needed.


Thanks - this comment nicely summarizes the math involved here!


I was actually asked Fizz Buzz in an interview once, but I did not have this solution at the time.

My favorite FizzBuzz solution is actually:

``` ->(n){[[["Fizz"][n%3],["Buzz"][n%5]].join].find(->{n}){|w| w if !w.empty?}} ```

This is Ruby, of course, probably something very similar can be done in several other languages.


Congrats, guys!


I don't even ask anymore. If I'm writing an app for you, I'm starting with tests, before I even write a line of executable code. If you don't want tests for your app, you'll need to find a different developer. It's not an optional part of the process, it's how the app is developed.


Maybe this is nitpicking, but did the author this article do zero fact-checking?

>Mr. Mitnick, who ... is publishing his first book in August...

Er... Following the link to his "first book" leads to Mr. Mitnick's website, whose products page lists his... other books...

Not to mention the well-known tech writer Stevy Levy. :-)


Rspec doesn't really need to be in the default stack; switching to it takes what; a minute? That's not a benchmarked timestamp, but I'm just saying... :-)


April 1st was 19 days ago... ;-)


Totally agree. Reading HN, blogs/etc is fine, but the net result is: more time reading == less time doing [whatever].

Play + Build should absolutely be 90% of the activity of a would-be developer. Most of the rest of the list could go away. Research is fine, but really only if you're going to _use_ it.

I do find local meetups beneficial, _particularly_ if you can work yourself up to do a presentation on something. Presenting on a topic is a great way to make yourself learn it better.

++FIND A CUSTOMER: Maybe the best advice ever. Has the additional benefit that unless you completely mess up, you get paid. And if you do mess up so badly that you don't get paid, hopefully you learn something about how not to repeat that.

I have to add (since this is a list for people learning): learn git or mercurial. If you know one, you can pick up the other. I don't really think this is optional.


Mini-ask HN: Why link to a techcruch article when you could just link to the startup's website? I'm not trying to be ornery, sincerely asking.

I'm not interested in reading a techcrunch article about a new startup. I'd rather go straight to the startup and look at it.


I'm not sure about it being the "first"; The Minnesota Cup (http://breakthroughideas.org/) has been around for awhile, and http://minnestar.org has done some micro-seed funding.

http://speedylemur.com is also local to Minneapolis, though I don't know how many startups they've funded yet.

Regardless, still cool news for entrepreneurs in this part of the midwest...



I know toto (and jekyll as well) but as I told you I can't afford hosting... And Heroku's network performance is really not good at this time (at least for Lisbon, Portugal, Europe with a 100MB Fiber Up-Down Link).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: