Determine the smallest positive integer whose first 6 multiples (including itself) contain the digit 2.
As a hobby I've decided I'm going to try to learn some programming (I've picked up bits and pieces through the years but it's not something I've ever really studied). I'm starting with Python. Here's a program I wrote to find the solution to this problem:
num = 2
ans = 0
while ans == 0:
ans = num
for m in range(1,7):
mult = num * m
if '2' not in list(str(mult)):
ans = 0
break
num += 1
print ans, ans*2, ans*3, ans*4, ans*5, ans*6
I imagine this is not the most elegant solution, and I welcome comments from Charlie or anyone else who knows anything about programming. But it ran quickly and produced the answer 642.
|
Posted by tomarken
on 2014-02-28 11:58:05 |