SHARE
TWEET

Untitled

a guest May 24th, 2020 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Parting the number
  2. def num_parts(x):
  3.     if x == 0:
  4.         return []
  5.     last_number = x%10
  6.     x = (x-last_number)/10
  7.     numar = [last_number]
  8.     numar.extend(num_parts(x))
  9.     return numar
  10.  
  11. # Joining it together
  12. def join_num(arr):
  13.     num = 0
  14.     for i in arr[::-1]:
  15.         num = num*10
  16.         num += i
  17.     return num
  18.  
  19. # Finds the next big number // Switching 2 of the parts
  20. def next_bigger(x):
  21.     arr = num_parts(x)
  22.     for i in range(len(arr)):
  23.         if i+1 >= len(arr):
  24.             return -1
  25.         if arr[i] > arr[i+1]:
  26.             arr[i], arr[i+1] = arr[i+1], arr[i]
  27.             return join_num(arr)
  28.     return -1
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