I decided to try some google codejam problems to get some more experience coding. The problem is at http://code.google.com/codejam/contest/6254486/dashboard, my solution is below. It gets the correct solution but would appreciate any tips on coding.
Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on. Whenever she names a number, she thinks about all of the digits in that number. She keeps track of which digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) she has seen at least once so far as part of any number she has named. Once she has seen each of the ten digits at least once, she will fall asleep.
Bleatrix must start with N and must always name (i + 1) × N directly after i × N. For example, suppose that Bleatrix picks N = 1692. She would count as follows:
N = 1692. Now she has seen the digits 1, 2, 6, and 9. 2N = 3384. Now she has seen the digits 1, 2, 3, 4, 6, 8, and 9. 3N = 5076. Now she has seen all ten digits, and falls asleep. What is the last number that she will name before falling asleep? If she will count forever, print INSOMNIA instead.
The first line of the input gives the number of test cases, T. T test cases follow. Each consists of one line with a single integer N, the number Bleatrix has chosen.
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the last number that Bleatrix will name before falling asleep, according to the rules described in the statement.
import os def getnumber(number,numberoftries): N = number digitlist =  print "new case number = " + str(number) for j in range(1,numberoftries): N = str(N) N.rstrip() digits =  for l in range(0,len(N)): if N[l] not in digits: digits.append(N[l]) # print digits for l in range(0,len(digits)): k = digits[l] # Add digits to digitlist if k not in digitlist: digitlist.append(k) print digitlist # check if we have all digits count = 0 for k in range (0,10): if str(k) in digitlist: count = count + 1 if count == 10: print "count = 10" return str(N) else: N = number * (j+1) print "number = " + str(N) return "INSOMNIA" numberoftries = 1000 path = '/home/username/GoogleCodeJam/' inputfile = 'A-large-practice.in' inputfilename = path + inputfile outputfilename = path + 'largeoutput' f = open(inputfilename, "r") numberofcases = f.readline() o = open(outputfilename,"w") for i in range (1,int(numberofcases)+1): N = f.readline() N = int(N) result = getnumber(N,numberoftries) outputline = 'Case #' + str(i) + ': ' + str(result) + '\n' o.write(outputline) o.close()