An increasing sequence whose terms contain only odd digits

94 Views Asked by At

Consider the increasing sequence: $13579, 13597, \dots,199153773,\dots$, where every term contains all (and only) the digits $1,3,5,7,9$ (every digit must appear at least once in every term, so repetition is allowed).

What is the $1992^\text{nd}$ term in the sequence?

What is the order (the term number) of $199153773$?


I am not sure how to start.

I am just thinking that the $1992^\text{nd}$ contains $\left \lfloor \frac{1992}{5!} \right \rfloor = \left \lfloor \frac{1992}{120} \right \rfloor = \left \lfloor 16.6 \right \rfloor = 16$ digits.

I am not sure. And I am not asking for the answer, I am just asking for help/hints, then I will edit my post to show you my attempt, if right or wrong.

Thanks a lot!

Edit:

I give up. Barry Cipra and Wolfgang Kais commented (really appreciated).

I just confused about counting the $6$-digit numbers.

1

There are 1 best solutions below

1
On

$1992^{nd}$ term is 1137597.

Index of term 199153773 is 306430.

def isValidNumList(numList):
    for x in [1, 3, 5, 7, 9]:
        if not x in numList:
            return False
    return True

def nextNumList(numList):
    numList.reverse()
    valid = False
    while not valid:
        overflow = 1
        for i in range(0, len(numList)):
            if overflow == 0:
                break;
            if numList[i] == 9:
                numList[i] = 1
            else:
                numList[i] += 2
                overflow = 0
        if overflow > 0:
            numList.append(1)
        valid = isValidNumList(numList)
    numList.reverse()

def getNumber(numList):
    res = 0
    for digit in numList:
        res *= 10
        res += digit
    return res

def findNumber(index):
    n = 1
    numList = [1, 3, 5, 7, 9]
    while n != index:
        nextNumList(numList)
        n += 1
    return getNumber(numList)

def findIndex(number):
    n = 1
    numList = [1, 3, 5, 7, 9]
    while getNumber(numList) != number:
        nextNumList(numList)
        n += 1
    return n

# prints 1137597
print(findNumber(1992))

# prints 306430
print(findIndex(199153773))