~dricottone/riddler-230106

riddler-230106/main.py -rwxr-xr-x 2.4 KiB
039efd6eDominic Ricottone Fiddling with a README 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3

"""
You and a friend are shooting some hoops at your local basketball court when
she issues a challenge: She will name a number, which we’ll call N. Your goal
is to score exactly N points in as many ways as possible using only 2-point
and 3-point shots. The order of your shots does not matter.

For example, there are two ways you could score N = 8 points: four 2-pointers
or two 3-pointers and one 2-pointer.

Your apparently sadistic friend chooses 60 for the value of N. You try to
negotiate this number down, but to no avail. However, she says you are welcome
to pick an even larger value of N. Does there exist an integer N greater than
60 such that there are fewer ways to score N points than there are ways to
score 60 points?
"""

def count_combinations(total_points: int) -> int:
    counter = 0
    for i in range(total_points // 3 + 1):
        for j in range(total_points // 2 + 1):
            combination = (3 * i) + (2 * j)
            if combination == total_points:
                counter += 1
            elif combination > total_points:
                break
    return counter

def test():
    """Small test set."""
    assert count_combinations(0) == 1 #no points
    assert count_combinations(1) == 0 #impossible
    assert count_combinations(2) == 1 #1 two-pointer
    assert count_combinations(3) == 1 #1 three-pointer
    assert count_combinations(4) == 1 #2 two-pointers and 0 three-pointers
    assert count_combinations(5) == 1 #0 and 1
    assert count_combinations(6) == 2 #3 and 0; 0 and 2
    assert count_combinations(7) == 1 #1 and 2
    assert count_combinations(8) == 2 #4 and 0; 1 and 2
    assert count_combinations(9) == 2 #3 and 1; 0 and 3

def main():
    """Main function."""
    sixty_points_combinations = count_combinations(60)
    print(f"There are {sixty_points_combinations} ways to score 60 points")

    n = 61
    while True:
        n_points_combinations = count_combinations(n)
        if n_points_combinations < sixty_points_combinations:
            print(f"{n} points can be scored in just {n_points_combinations} ways")
            break
        cursor += 1

def timed_main():
    """Main function without any printing."""
    sixty_points_combinations = count_combinations(60)
    n = 61
    while True:
        n_points_combinations = count_combinations(n)
        if n_points_combinations < sixty_points_combinations:
            break
        cursor += 1

if __name__ == "__main__":
    test()
    main()