Advertisement
yclee126

Display duplicate digits in the next interations

May 11th, 2022
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # track each digits and display duplicates in the next iterations
  2.  
  3. import time
  4.  
  5. num = 1 # starting number
  6.  
  7. def func(x):
  8.     return x*2 # multiplying number
  9.  
  10. delay = 0.05
  11. digits = 40
  12.  
  13. digit_arr = [' ']*digits
  14.  
  15. while True:
  16.     num_str = f'{num:{digits}d}'
  17.  
  18.     result_str = ''
  19.     for i, c in enumerate(num_str):
  20.         if digit_arr[i] == c:
  21.             result_str += c #'█'
  22.         else:
  23.             result_str += ' '
  24.             digit_arr[i] = c
  25.    
  26.     print(result_str+'|')
  27.  
  28.     num = func(num)
  29.     num %= 10**digits
  30.  
  31.     time.sleep(delay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement