SHARE
TWEET

Untitled

a guest Feb 29th, 2020 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def isSpecial(nr):
  2.     lastC = nr % 10
  3.     nr = nr // 10
  4.     while(nr>0):
  5.         c = nr % 10
  6.         if abs(lastC - c) != 1:
  7.             return False
  8.         lastC = c
  9.         nr = nr //10
  10.     return True
  11.  
  12.  
  13. def nrAsList(nr):
  14.     list = []
  15.     while(nr > 0):
  16.         list.insert(0, nr % 10)
  17.         nr = nr // 10
  18.     return list
  19.  
  20. def makeSpecial(nr):
  21.     nrStr = str(nr)
  22.     listNr  = nrAsList(nr)
  23.     print(listNr)
  24.     l = len(nrStr)
  25.     print(str(l))
  26.     posC = 0
  27.     while(posC <l):
  28.         print(posC)
  29.         potentialSpecial = int(nrStr[0:posC]+ nrStr[posC+1:l])
  30.         print(str(potentialSpecial))
  31.         if(isSpecial(potentialSpecial)):
  32.             return potentialSpecial
  33.         posC+=1
  34.     return 0
  35.  
  36. n = 9873654
  37. special = makeSpecial(n)
  38. print(str(special))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top