LINES = [[0, 1], [0, 2, 4, 6], [0, 3, 7, 9], [0, 5, 8, 10], [1, 2, 3, 5], [1, 4, 7, 8], [1, 6, 9, 10]] def points(x, y=None): return filter((lambda a: a != x), reduce((lambda a, b: a+b), [l for l in LINES if x in l and y not in l])) def solve_challenge(): results = [] for x in dict([(k, k) for k in reduce((lambda a, b: a+b), LINES, [])]).keys(): cx = points(x) for y in [i for i in cx if not i < x]: for z in points(y, x): if z > y and z in cx: results.append([x, y, z]) return results print "%d triangles:" % len(solve_challenge()), solve_challenge()