repl.it
@thechalkface2/

Ritangle2018_P1

Python

Solution to the Ritangle problem: how many 8 digit numbers are both multiples of 18 and comprise only the digits 1, 2 or 3?

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def check_digits(n):
  """Returns True if all digits are 1, 2 or 3, and False otherwise"""
  while n > 0:
    if n % 10 not in [1, 2, 3]:
      return False
    n //= 10
  return True

count = 0
for i in range(11111112, 33333333, 90):
  if check_digits(i):
    count += 1
    print(i)
print(f"Done: final tally is {count}.")