Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
#161d
import math
import copy

K = int(input())

keta = 1
lunlun_numbers_list = [1,2,3,4,5,6,7,8,9]
lunlun_numbers_numer = 9

if K <=9:
    print(lunlun_numbers_list[K-1])
else:
    while 1:
        new_lunlun_numbers_list = list()
        for lower_keta in lunlun_numbers_list:
            ketasu = int(math.log10(lower_keta)//1 + 1)
            top_keta = lower_keta // 10**(ketasu-1)

            if top_keta !=1: 
                
                new_lunlun_numbers_list.append((top_keta-1)*10**ketasu + lower_keta)

            
            new_lunlun_numbers_list.append((top_keta+0)*10**ketasu + lower_keta)

            if top_keta !=9:
                
                new_lunlun_numbers_list.append((top_keta+1)*10**ketasu + lower_keta)

        
        ketasu = int(math.log10(new_lunlun_numbers_list[-1])//1 + 1)
        new_lunlun_numbers_list.append((1)*10**(ketasu-1))
        
        if ketasu !=2: 
            new_lunlun_numbers_list.append((1)*10**(ketasu-1)+1)


        if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:
            new_lunlun_numbers_list.sort(reverse=False)
            print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])
            print(new_lunlun_numbers_list)
            break


        lunlun_numbers_list = copy.copy(new_lunlun_numbers_list) 


K = int(input())

def get_next_lun(before_number,keta):  

  if keta == 1: 
      if before_number == 9:
        return [8,9]
      if before_number == 0:
        return [1,2]
      else:
        return [before_number-1,before_number,before_number+1]
  else:
      if before_number == 9:
        for i in get_next_lun(before_number,keta-1):
        return []
      if before_number == 0:
        return []
      else:
        return [before_number-1,before_number,before_number+1]
      
      return 


#161d
import math
import copy

K = int(input())

keta = 1
lunlun_numbers_list = [1,2,3,4,5,6,7,8,9]
lunlun_numbers_numer = 9

if K <=9:
    print(lunlun_numbers_list[K-1])
else:
    while 1:
        new_lunlun_numbers_list = list()
        for lower_keta in lunlun_numbers_list:
            ketasu = int(math.log10(lower_keta)//1 + 1)

            if lower_keta>=10:
                last_keta = lower_keta - ((lower_keta//10) * 10)
            else:
                last_keta = lower_keta

            #print(lower_keta,ketasu,last_keta)

            if last_keta !=0: 
                new_lunlun_numbers_list.append(lower_keta*10 + last_keta - 1)
            
            new_lunlun_numbers_list.append(lower_keta*10 + last_keta)

            if last_keta !=9:
                new_lunlun_numbers_list.append(lower_keta*10 + last_keta + 1)

        if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:
            new_lunlun_numbers_list.sort(reverse=False)
            print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])
            #print(new_lunlun_numbers_list)
            break
        else:
            lunlun_numbers_numer+=len(new_lunlun_numbers_list)

        lunlun_numbers_list = copy.copy(new_lunlun_numbers_list) 

Verdicts: Wrong Answer

Runtime Error

Accepted