Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do you find the function that describes this sequence?

  1. Feb 26, 2012 #1
    I'm not and expert in math and have only high school level math which has mostly faded from memory. I've been searching the net to see if there is an algorithm or something to derive a function from a given input and output sequence of numbers. I'm guessing you just have to do it by hand as one person said on a question answer site, using common sense and experience. But I don't have much ^^, please help.

    This is the sequence:

    It starts from one and the there are three numbers as you can see with the space between the first set of number and the second being 46 numbers. After the 182 gap it's starts over again with gaps of 46, then 96 and so on, supposedly forever.

    Forgive me if I'm not describing this problem too well but here goes. This is related to a programming/mathematics project I'm working on as a hobby but more maths than programming. So I'm not looking for the algorithm that produces that sequence which I can find on my own. And here's where I'm not even sure I know what it is I'm looking for but, say the numbers in that sequence are bad numbers that I don't want. So when I pick a random number, I want to first check to see if it belongs to that sequence without actually creating the sequence up to the number. So is there a function or equation that I can derive from the sequence that I could use to tell me whether any given number belongs to this sequence?

    I don't know where to start but the result I'm looking for is something like this:
    if the sequence was something simple like multiples of 3 (3,6,9,12,15,...) then to test if a given number belongs to the sequence I would use the following equation in my code:
    if x mod 3 = 0: True
    as in: if dividing the number by 3 produces no remainders then it is True it is a multiple of 3, I think?

    I'm willing to work at it but could use some pointers and general help. Much appreciated.

    Sorry for the long story but I hope that describes the problem well enough.


    I apologize for not being clear, I really didn't know how to express it.
    If you take all the numbers from 1 up to say 1000 and put them in boxes like:
    [1][2][3][4] etc
    Then and then mark off the numbers in the following sequence:
    they follow a consistent pattern.
    I think I was supposed to say it starts at 91 not 1 again sorry about the confusion. They are all odd numbers. The first three are 91,93,95 then there is a gap of 46 numbers(or boxes) before the numbers appear again which are 141,143,145,147 then a gap of 96 and they start again 243,245,247,249 and then back to the gap of 46 before they appear again at 295,297,299 then a gap of 182(which is twice the size of the 96 gap) before it starts over again in that same order of gaps and the same order for the length of each set.

    So if I were to create an algorithm to create the sequence it should look like this(I don't know pseudocode but please bare with me):
    let x = 89
    while True:
    ....for length = 3:
    ........x = x + 2
    ........add x to sequence
    ....x = x + 46
    ....for length = 4:
    ........x = x + 2
    ........add x to sequence
    ....x = x + 96
    ....for length = 4:
    ........x = x + 2
    ........add x to sequence
    ....x = x + 182

    That will generate the sequence to infinity. Assuming that these numbers are special in some way, if I wanted to test any random number to see if it belonged to the sequence then I could generate the sequence with that algorithm until the last number in the sequence is greater than or equal to the number I'm testing and see if the number is found in the sequence. That is too inefficient for a very large random number. So instead of generating the sequence with the algorithm I'm looking for something like an equation where I can put the number into the equation and see the result.
    Last edited: Feb 26, 2012
  2. jcsd
  3. Feb 26, 2012 #2
    I find the specifications of this sequence rather unclear. One guess, disregarding your cryptical sentence "it starts from one...", is that we are just talking about 14 different values modulo 390. If not, it would be informative if you could clearly include some numbers that does not fit that pattern.
  4. Feb 26, 2012 #3
    The awesome Online Encyclopedia of Integer Sequences is a great resource for this type of question.


    Your particular sequence isn't specified clearly enough for anyone to know what numbers are in the sequence. You can't just say, "It starts with x, y, and z and then there are 46 other numbers ..." and expect anyone to know what the sequence is.
  5. Feb 26, 2012 #4
    Thank you for the suggestion it showed me the correct way to display a sequence and it was stupid the way I showed it.

    I search for it on that site but it picked up no results.
  6. Feb 26, 2012 #5
    It's still unclear what the sequence of gaps is. You have 46, 96, 46, 182 ...

    Is there a pattern or algorithm for the gaps?
  7. Feb 26, 2012 #6
    Yes there is a pattern for the gaps I included it in the algorithm I showed but it's not pseudocode so i don't know if it's understandable but close to the python language. If you take 141 and subtract 95 you get 46. So 46 is the gap between the third number in the sequence and the fourth. Otherwise the gap is just 1 as you can see there are sets of consecutive odd numbers. First a set of three consecutive odds, a big gap(46), then a set of four consecutive odds, another bigger gap(96) then a set of four consecutive odds and then another gap and so on.
    But I think it's best if I just say here is the sequence
    91,93,95,141,143,145,147,243,245,247,249,295,297,2 99,481,483,485,...up to infinity

    Ignore everything else including the algorithm and try to see the pattern the sequence follows.

    All I need is to find and equation to use for testing if a number belongs to this sequence.
    If I knew a bit about maths I wouldn't have confused everyone but I'm trying to change that.
    Last edited: Feb 26, 2012
  8. Feb 26, 2012 #7
    The sequence is:
    91,93,95,141,143,145,147,243,245,247,249,295,297,2 99,481,483,485,...

    Thank you for pointing out the need for clarification I was very unclear the way I described it and yes the starting point was totally wrong it's not 1 but 91.

    I hope that helps a bit, if it does I would much appreciate any further help.

    Thanks again
  9. Feb 28, 2012 #8
    OK, if there is nothing else to this sequence, your code to check x for inclusion would be:

    S = list of the 14 first numbers in the sequence.
    y = x mod 390
    if y in S then: YES
    else: NO
  10. Feb 28, 2012 #9

    It works!!!

    The solution seems so simple it's almost embarrassing. But before I say anything else, THANK YOU NORWEGIAN!

    I'm still fiddling with a calculator and pen and paper but I simply cannot figure out how you got it. If I had to guess I'd say it's got something to do with factors or multiples of some property of the first iteration of the sequence? I dinno, but if your still around I would kill to know.

    Thanks again.
  11. Feb 28, 2012 #10
    Ok I figured out where the 390 comes from.

    The length of each iteration of the algorithm is 390(from 91 to 481).
    So it's the difference between the 1st number in the sequence and the 15th.

    Yet I know that the mod operator calculates the remainder. I can't yet understand how it works in this equation.


    I think I'm getting warmer, so far I've established this much but not 100% sure if it's correct. There are two types of integer sequences. One is where the algorithm modifies itself, as in if the algorithm takes a value from the list it's creating to create the next value like the Fibonacci sequence. The other is where the algorithm works independent of the sequence it's creating so the length between the first number in the sequence and the first number of the next run of the algorithm will always be the same. Having identified that this sequence is of the second type you only need to list the number in one run of the algorithm and also note the length of integers between the first run and second. Then the equation to test for inclusion will always be:

    list = numbers in first run of algorithm.
    x = random number
    y = difference between first number in first run and first number in second run
    z = x mod y
    if z in list: True
    else: False

    Is all of that correct, if so I'll save it somewhere as I'll be using it allot in future.

    One more long shot question, is it possible to combine two or more sequence and use the same or similar method to test for inclusion?
    Last edited: Feb 28, 2012
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook