The Generic Number Sequence Puzzle - Puzzling Stack Exchange most recent 30 from puzzling.stackexchange.com 2019-11-19T08:17:58Z https://puzzling.stackexchange.com/feeds/question/60747 https://creativecommons.org/licenses/by-sa/4.0/rdf https://puzzling.stackexchange.com/q/60747 4 The Generic Number Sequence Puzzle Bass https://puzzling.stackexchange.com/users/36023 2018-02-19T10:52:32Z 2018-02-20T09:41:16Z <p>If you are in a hurry, you can skip the story below, there's a TL;DR near the end. </p> <blockquote> <p>The gist is that we are going to solve <em>every number-sequence puzzle ever<sup>&ast;</sup></em>, all in one go.<br> <sub><sub>&ast;: Terms and conditions may apply. May be subject to availability. Contact your local maths department for further information.</sub></sub></p> </blockquote> <hr> <p>Charlie, a university tutor, was having a get-together with his lot of freshmen, fortuitously nicknamed <strong>Won</strong>der, <strong>Too</strong>tsie, and <strong>Tri</strong>llian.</p> <p>Unfortunately, they had 4N+1 cupcakes, so the question arose, who gets the last one.</p> <p><em>Charlie:</em> I don't think there's any other choice, we have to settle this the old-fashioned way.<br> <em>Wonder:</em> What, a duel? Isn't that a bit extreme?<br> <em>Charlie:</em> What? No, not a duel! A <strong>bet</strong> of course!<br> <em>all around</em>: (sighs of relief)<br> <em>Charlie:</em> I'm really good at number sequence puzzles, so here's the deal: You guys pick any fourth order polynomial, and calculate its value at any 5 points. As long as the distance between two consecutive points is always the same, I can tell you the next two numbers in the sequence. If I get them right, I get the cupcake.<br> <em>Tootsie:</em> Well, big whoopty-doo, we all know how to fit polynomials.<br> <em>Charlie:</em> Okay, but what if I do it only using addition and subtraction? No more than ten of either, too. Would that be impressive enough?<br> Trillian: Hey, <a href="https://puzzling.stackexchange.com/q/60644/36023">I know this trick</a>! You are going to combine the numbers into this one huge long string of numbers, and then claim that you are only doing one addition while you are actually doing several at the same time, aren't you?<br> <em>Charlie:</em> (looking a little offended) No, that would be cheating! I won't cheat in any way. I promise!<br> <em>all around:</em> (exchanging glances, hesitant nods gradually turn into a consensus of acceptance)<br> <em>Wonder:</em> Very well. The bet is on.<br> <em>Charlie:</em> Ok, you guys figure out the number sequence, while I go return some of that excellent cider to mother nature.</p> <p>While Charlie is away, the freshmen try to decide how to choose the factors for the polynomial. They'll of course also need a starting point, and the distance between the points. (Names shortened to numbers just because.)</p> <p>1: Well, I'll just jot down a couple of numbers then, we'll use those as the coefficients of the polynomial, and..<br> 2: NOT SO FAST! How do we know you are not colluding with Charlie? We all know you have a crush on him!<br> 1: Well, so do you, so..<br> 3: Shut up, you two. We'll use the digits of pi.<br> 1: ..Yeah, that's probably fair. That would only give positive coefficients though.<br> 2: So we'll subtract 5 from each digit.<br> 3: That should work. There's a 5 in the first digits of pi though, getting a zero in one factor might make the sequence easier to solve.<br> 1: Well, let's use "e" then.<br> 2: Yes, let's.</p> <p>So Trillian rolls up her sleeves, and starts writing. This is what she wrote:</p> <pre> [2, 7, 1, 8, 2, 8, 1] (minus 5) -> [-3, 2, -4, 3, -3, 3, -4] </pre> <p>-> <strong>$\mathbf{-3x^4 + 2x^3 - 4x^2 + 3x - 3}$, First point: 3, Step: -4.</strong></p> <p>"These numbers are going to get big. Anyone have a calculator? Thanks... I really don't think Charlie can solve this. I mean, even <em>I</em> have to do a silly number of multiplications here.."</p> <pre> Point: 3, -1, -5, -9, -13, -17, -21 Polynomial value: -219, -15, -2243, -21495, -90795, -261599, -603795 </pre> <p><em>Trillian</em>: Ok, those got pretty huge. Even it he could somehow figure them out, it's probably going to take a good while.</p> <p>Charlie returns, and is handed this list of numbers: <strong>-219, -15, -2243, -21495, -90795</strong>. He then performs ten simple subtractions, followed by eight additions (the last four he calculates in one go), and grabs the cupcake less than two minutes after his return.</p> <p>The freshmen stare at the correct result incredulously, until Wonder exclaims "That's bloody brilliant!" and goes to fetch Charlie another pint of cider.</p> <p>What were Charlie's calculations?</p> <hr> <p>TLDR:</p> <blockquote> <p>Given a sequence of <strong>five</strong> ($N+1$) numbers, of which you know that they were generated by evaluating an unknown <strong>fourth ($Nth$) order polynomial</strong> at regular intervals, how can you extrapolate the next two values using <strong>10</strong> ($\frac{N^2+N}{2}$) subtractions and <strong>8</strong> ($2N$) additions only?</p> </blockquote> <hr> <p>For extra credit, can you name another Charles whose name is in the history books in big part for implementing this same method very cleverly?</p> <p>For another bonus point, why did Trillian roll up her sleeves?</p> <p>For super-hyper-extra points, what would have happened if Trillian had made a mistake while calculating one of the five numbers?</p> https://puzzling.stackexchange.com/questions/60747/-/60748#60748 4 Answer by Gareth McCaughan for The Generic Number Sequence Puzzle Gareth McCaughan https://puzzling.stackexchange.com/users/19114 2018-02-19T11:42:35Z 2018-02-19T11:47:49Z <p>[I shan't bother spoilering this; it would basically be an entire answer composed of spoiler blocks.]</p> <p>Charlie does this by drawing up a table of differences. So first he writes down the numbers he's been given, the values of a 4th-degree polynomial at equally spaced points:</p> <p>-219 -15 -2243 -21495 -90975</p> <p>and then he computes successive differences (4 subtractions), getting the values of a 3rd-degree polynomial at equally spaced points:</p> <p>204 -2228 -19252 -69480</p> <p>and again, getting the values of a 2nd-degree polynomial at equally spaced points:</p> <p>-2432 -17024 -50228</p> <p>and again (polynomial is linear now):</p> <p>-14592 -33204</p> <p>and again (now we have a <em>constant</em> polynomial):</p> <p>-18612.</p> <p>Since this polynomial is constant, we can write down its value at the <em>next</em> two of our equally-spaced values very straightforwardly:</p> <p>-18612 -18612 -18612</p> <p>and now we can proceed back upwards, adding in order to produce the numbers on the previous line that would give the differences we have here:</p> <p>-14592 -33204 | -51816 -70428<br> -2432 -17024 -50228 | -102044 -172472<br> 204 -2228 -19252 -69480 | -171524 -343996<br> -219 -15 -2243 -21495 -90975 | -262499 -606495</p> <p>... where we can see that at some point I have made an error in my arithmetic, but the principle is correct :-).</p> <p>(Ah, I see. I copied down 90795 as 90975. I initially thought I must have made another error, but that was because of an error in the <em>puzzle</em> that's now been corrected :-).)</p> <p>Extra credit: Charles Babbage's <em>Difference Engine</em> was a device for performing this procedure.</p> <p>Bonus point: Not sure, besides the trivial thing that rolling up one's sleeves before doing some kind of work is a cliche.</p> <p>Super-hyper-extra: The procedure always extrapolates the unique polynomial of degree at most N with the given values. So if Trillian gets one of them wrong by an amount a, the differences between her values and the true values are a times the unique such polynomial that's 1 at the value she got wrong and 0 at the others. That's always of degree N, so the errors will grow like distance^N; there's an obvious-in-hindsight explicit expression for it (mumble product of differences) which means e.g. that the differences will tend to have some nice small factors; and of course because all we're doing is addition and subtraction the extrapolated values will still be integers. So, e.g., the errors in <em>my</em> extrapolation above were 900 and 2700.</p>