Project Euler #45: Triangular, pentagonal, and hexagonal

  • + 0 comments

    Python3. Simple brute force. Boring.

    param = {3:(1, 1, 1), 5:(1, 1, 3), 6:(1, 1, 4)}
    
    def double_seq(n, a, b):
        v1, d1, dd1 = param[a]
        v2, d2, dd2 = param[b]
        while v2 < n:
            if v1 == v2: print(v1)
            if v1 < v2:
                d1 += dd1
                v1 += d1
            else:
                d2 += dd2
                v2 += d2
            
    n, a, b = map(int, input().split())
    double_seq(n, a, b)