project euler problem 100 https projecteuler netproblem100 if a box contains twentyone coloured discs composed of fifteen blue discs and six red discs and two discs were taken at random it can be seen that the probability of taking two blue discs pbb 1521 x 1420 12 the next such arrangement for which there is exactly 50 chance of taking two blue discs at random is a box containing eightyfive blue discs and thirtyfive red discs by finding the first arrangement to contain over 1012 1 000 000 000 000 discs in total determine the number of blue discs that the box would contain returns the number of blue discs for the first arrangement to contain over mintotal discs in total solution2 3 solution4 15 solution21 85 returns the number of blue discs for the first arrangement to contain over min_total discs in total solution 2 3 solution 4 15 solution 21 85
def solution(min_total: int = 10**12) -> int:
    

    prev_numerator = 1
    prev_denominator = 0

    numerator = 1
    denominator = 1

    while numerator <= 2 * min_total - 1:
        prev_numerator += 2 * numerator
        numerator += 2 * prev_numerator

        prev_denominator += 2 * denominator
        denominator += 2 * prev_denominator

    return (denominator + 1) // 2


if __name__ == "__main__":
    print(f"{solution() = }")