Guest User

Untitled

a guest
May 24th, 2020
92
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×