Guest User

Untitled

a guest
Jan 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #! /usr/local/bin/env python3
  2. import math
  3.  
  4. def spool(i: int):
  5. """
  6. This method takes the current stack, divides it by 5 and wastes one parcel
  7. :return: The number being taken, the parcels being wasted
  8. """
  9. m: int = i % 5 # The amount beeing wasted
  10. l = math.floor(i / 5) # The amount beeing taken
  11. if m == 1 and l > 0:
  12. return m, l
  13. return -1, -1
  14.  
  15. def check(n, i, p):
  16. """
  17. This method checks if the current tree is resolvable
  18. :param: n The current tree deph
  19. :param: i The current stack size
  20. :param: p A bool flag indicating the printing
  21. :return: true if it is resolvable or otherwise false
  22. """
  23. if n == 0:
  24. return True
  25. m, l = spool(i)
  26. if m == -1 or l == -1:
  27. return False
  28. if p:
  29. print("Next stack size: " + str(i - l - m) + " with " + str(m) + " parcels wasted (takes " + \
  30. str(l) + " parcels).")
  31. return check(n - 1, i - m - l, p)
  32.  
  33. def search_brute_force(maximum):
  34. """
  35. This method checks all numbers until a maximum is reached
  36. :param: maximum The maximum int to check
  37. """
  38. i: int = 1
  39. exit: bool = False
  40. while not exit:
  41. if i > maximum:
  42. exit = True
  43. print("There was no number found until " + str(maximum))
  44. else:
  45. exit = check(5, i, False)
  46. if exit:
  47. print("Found with pos " + str(i))
  48. check(5, i, True)
  49. i += 1
Add Comment
Please, Sign In to add comment