Week 12 - Math Olympiad through Brute Force Search

posted Jan 13, 2017, 8:03 AM by Attila Lengyel
number = 2 * 3 * 5 * 7 * 11
for x in range(1, 6):
  guess = number * 2 * x
  sGuess = str(guess)
  if len(sGuess) != 4: continue 
  if sGuess.count("6") > 0: continue
  if sGuess.count("9") != 1: continue
  print(guess)
  


multipliers = input("How many multipliers?")
multi = []
for x in range(1, int(multipliers) + 1):
  multi.append(int(input("Give me a multi:")))
print(multi)

digits = int(input("How many digits:"))
lower = 10**(digits-1)
upper = 10**(digits)-1

okdigit = input("What digit you look for?:")
notokdigit = input("What digit you don't look for?:")

for x in range(lower, upper + 1):
  found = True
  
  for y in multi:
    if x%y != 0: 
      found = False
      break
  if found == False: continue
  
  if str(x).count(okdigit) == 0: continue
  if str(x).count(notokdigit) != 0: continue
    
  if found: print(x)
  
 
Comments