Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/local/bin/env python3
- import math
- def spool(i: int):
- """
- This method takes the current stack, divides it by 5 and wastes one parcel
- :return: The number being taken, the parcels being wasted
- """
- m: int = i % 5 # The amount beeing wasted
- l = math.floor(i / 5) # The amount beeing taken
- if m == 1 and l > 0:
- return m, l
- return -1, -1
- def check(n, i, p):
- """
- This method checks if the current tree is resolvable
- :param: n The current tree deph
- :param: i The current stack size
- :param: p A bool flag indicating the printing
- :return: true if it is resolvable or otherwise false
- """
- if n == 0:
- return True
- m, l = spool(i)
- if m == -1 or l == -1:
- return False
- if p:
- print("Next stack size: " + str(i - l - m) + " with " + str(m) + " parcels wasted (takes " + \
- str(l) + " parcels).")
- return check(n - 1, i - m - l, p)
- def search_brute_force(maximum):
- """
- This method checks all numbers until a maximum is reached
- :param: maximum The maximum int to check
- """
- i: int = 1
- exit: bool = False
- while not exit:
- if i > maximum:
- exit = True
- print("There was no number found until " + str(maximum))
- else:
- exit = check(5, i, False)
- if exit:
- print("Found with pos " + str(i))
- check(5, i, True)
- i += 1
Add Comment
Please, Sign In to add comment