Created
April 6, 2026 07:08
-
-
Save simonwhitaker/e09141d73c3cd66ad7328548d68f7f47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from itertools import combinations | |
| # `combinations` gives all possible combinations of a sequence, with each | |
| # combination in sorted order. So e.g. `combinations([1, 2, 3, 4], 3)` will | |
| # yield: | |
| # | |
| # 1, 2, 3 | |
| # 1, 2, 4 | |
| # 2, 3, 4 | |
| # | |
| # Docs: https://docs.python.org/3/library/itertools.html#itertools.combinations | |
| # change this to get the results for a different line length | |
| line_length = 5 | |
| # --- NO NEED TO CHANGE ANYTHING BELOW THIS LINE... --- | |
| # | |
| # ...but you should definitely feel free to tinker! 🤓 | |
| sudoku_digits = range(1, 10) | |
| print("=== All triplets are triangles ===") | |
| for x in combinations(sudoku_digits, line_length): | |
| if all([a + b > c for (a, b, c) in combinations(x, 3)]): | |
| print(x) | |
| print("=== All triplets are anti-triangles ===") | |
| for x in combinations(sudoku_digits, line_length): | |
| if all([a + b <= c for (a, b, c) in combinations(x, 3)]): | |
| print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment