Advertisement
OreganoHauch

Calculate rest of palindrome candidates/reverse candidate

Apr 5th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. def show_rest_palindrome(my_number, limit=100, print_calc=False):
  2.  
  3. my_number = str(my_number)
  4.  
  5. loop = 1
  6. last_rest = int(my_number)%int(my_number[::-1])
  7. last_change = 0
  8. for i in range(1, limit):
  9. palindrom = int(my_number[::-1])
  10. multiplied_digits = my_number * i
  11. number = int(multiplied_digits)
  12. quotient = number//palindrom
  13. rest = number%palindrom
  14. #print(f"{rest} ({type(rest)}), {last_rest} ({type(last_rest)})")
  15. if rest != last_rest:
  16. last_change = loop
  17. if print_calc:
  18. if limit <= 10:
  19. print(f"{number} ÷ {palindrom} = {quotient} R {rest}")
  20. else:
  21. print(f"Loop {loop}: R = {rest}")
  22. last_rest = rest
  23. loop += 1
  24.  
  25. print(f"Last change of rest for {my_number} with {limit-1} loops at loop #{last_change}.")
  26.  
  27. show_rest_palindrome(my_number=23, print_calc=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement