{}
run-icon
main.py
# Let's calculate the number of unique ancestors needed for each # generation with 0 inbreeding # 1st gen - foundation horse # 2nd gen - 2 foundation horses - B grade foal # 3rd gen - 4 foundation horses + 2 parents - A grade foal # 4th gen - 8 foundation horses + 4 grandparents + 2 parents - *Star foal # As we can see it's always a sum of power of 2s, where 2 is the base and exponenta values ranging from 1 to (target generation - 1) import time NEW_LINE = "\n" def get_total_number_of_horses(target_generation: int) ->int: result = 0 for generation in range(1, target_generation): result += (2 ** generation) return result print("""# Let's calculate the number of unique ancestors needed for each # generation with 0 inbreeding # 1st gen - foundation horse # 2nd gen - 2 foundation horses - B grade foal # 3rd gen - 4 foundation horses + 2 parents - A grade foal # 4th gen - 8 foundation horses + 4 grandparents + 2 parents - *Star foal # As we can see it's always a sum of power of 2s, where 2 is the base and exponenta values ranging from 1 to (target generation - 1)""") print(NEW_LINE) time.sleep(5) def print_default_output(): print("Test 1: Number of unique ancestors needed to get 2nd generation foal with B papers: ", get_total_number_of_horses(2)) assert(get_total_number_of_horses(2) == 2) time.sleep(2) print(NEW_LINE) print("Test 2: Number of unique ancestors needed to get 3rd generation foal with A papers:", get_total_number_of_horses(3)) time.sleep(2) assert(get_total_number_of_horses(3) == 6) print(NEW_LINE) assert(get_total_number_of_horses(4) == 14) print("Test 3: Number of unique ancestors needed to get 4th generation foal with low *Star/Gold papers:",get_total_number_of_horses(4)) time.sleep(2) print(NEW_LINE) assert(get_total_number_of_horses(5) == 30) print("Test 4: Number of unique ancestors needed to get 4th generation foal with low *Star/Gold papers:",get_total_number_of_horses(5)) time.sleep(2) print(NEW_LINE) print("Now that we had proven that the script calculates values correctly let's calculate unique ancestors for other generations!") print(NEW_LINE) print("Number of unique ancestors needed to get one cap breeding ability foal - 7th generation: ", get_total_number_of_horses(7)) time.sleep(2) print(NEW_LINE) print("Number of unique ancestors needed to get aan 8th generation 0% inbred foal: ", get_total_number_of_horses(8)) time.sleep(2) print(NEW_LINE) print("Number of unique ancestors needed to get one 0% inbreeding foal of 11th generation: ", get_total_number_of_horses(11)) time.sleep(2) print(NEW_LINE) print("Number of unique ancestors needed to get one 0% inbreeding foal of 20th generation: ", get_total_number_of_horses(20)) time.sleep(2) print(NEW_LINE) def generate_input(): user_input = input("Please enter Y if you want to see the test output or any other symbol if you want to generate the number of unique ancestors for your target generation: ") if user_input.lower() == 'y': print_default_output() else: try: user_input_generation = int(user_input) print(f"Number of unique ancestors needed to get one 0% inbreeding foal of {user_input_generation} generation: ", get_total_number_of_horses(int(user_input_generation))) except Exception: print("Error! Please enter Y or a number!") while True: generate_input()
Output