Message Boards Message Boards

0
|
6386 Views
|
9 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Find a missing number in a sequence of numbers.

I try to solve a typical question appering in many magzins etc. as follows:

Find the missing number in the sequence, e.g. 1, 8, 27, 64, 125, ???, 343, 512

There is obviously a missing pattern that you have to find out in order to find the missing number. My approach with mathematica is this:

a = Predict[{1 -> 1, 2 -> 8, 3 -> 27, 4 -> 64, 5 -> 125, 7 -> 343, 8 -> 512}]
a[6]

which gives the obvious wrong number 125. I have tried adding different methods at Predict without any success to predict the correct answer. As a hint I have the option of the following answers: A. 216, B. 218, C. 244, D. 324, E. 220. How can I find the hidden pattern in general in such kind of problems with mathematica ?

9 Replies

Thank you for your answer. I understand that it is not possible to have a general solution for such problems (although it would be good). I experimented with another simple case without any result. For example consider the simple sequence 1, 3, 4, 7, 11, 18, 29, ???, 76, 123. Here the obvious pattern is that the third number is the addition of the previous two i.e. 1+3=4 the forth 4+3=7 etc.

ClearAll["`*"];
y[1] = 1;
y[2] = 3;
y[n_] := y[n] = (y[n - 1] + y[n - 2])
data = Table[{i, y[i]}, {i, {1, 2, 3, 4, 5, 6, 7, 9, 10}}]
FindFormula[data][8]
Interpolation[data][8.]

None of the suggested solutions produce the correct answer 47 neither reveals the hidden pattern.

FindSequenceFunction[{1, 3, 4, 7, 11, 18, 29}]
(*  Out:  LucasL  *)
LucasL[8]
(*  Out:  47   *)

Isn't Mathematica just great ?!?

POSTED BY: Henrik Schachner

Great answers as always! Thanks.

BUT

it is in principle impossible to guess a missing number, because the missing number could have ANY value, depending on the function used to create the non-missing ones.

Look at this

data = Transpose[{Range[8], {1, 8, 27, 64, 125, y, 343, 512}}]

Now define

f[x_] := Plus @@ Table[
   data[[i, 2]] Times @@ Table[
      If[j != i, (x - data[[j, 1]])/(data[[i, 1]] - data[[j, 1]]), 1]
      , {j, 1, 8}]
   , {i, 1, 8}]

Then this f will reproduce all the numbers given

f/@Range[8]

and you may insert for the missing y ANY value you want!

And of course you can as alternative get the given numbers by { x, x^3 }.

POSTED BY: Hans Dolhaine
Posted 4 years ago

Agreed. However, my biases are that many of those who post such "puzzles" on the internet don't understand that it is possible to put any value in for the missing number (which might not even be an integer and could be a complex number or anything else).

What one is looking for is a simple/parsimonious function to reproduce the (usually) integers given. One has to look for such simple functions to pass college entrance exams as such "puzzles" are included. (Well, 40 years ago they were.)

POSTED BY: Jim Baldwin

Thank you very much for your reply. This is really another option by taking the sequence at the begining. The site you sugest is also very interesting.

Posted 4 years ago

You could try FindSequenceFunction on subset that is contiguous:

FindSequenceFunction[{1, 8, 27, 64, 125}]
(* #1^3 & *)

Then use that function to predict the rest. If the predictions for the remaining known numbers match up, then you're home free.

If one doesn't have Mathematica, you can try https://oeis.org/.

POSTED BY: Jim Baldwin

If one entirely refuses to think one approach could simply be:

data = {{1, 1}, {2, 8}, {3, 27}, {4, 64}, {5, 125}, {7, 343}, {8, 512}};
formula = FindFormula[data]
(*  Out:  #1^3&  *)
formula[6]
(*  Out: 216  *)

But in this simple case even interpolation will give the correct result:

func = Interpolation[data];
func[6]
(*  Out:  216  *)
POSTED BY: Henrik Schachner

Thank you very much for the answer. I was completely unaware that there is a function FindFormula.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract