python - Optimized way for finding the number which satisfies specific conditions -
i saw question somewhere. there 8 digit number. first digit left right tells how many zeroes in number. second digit tells how many 1s in number, third digit tells u how many 2 in number , on till 8th digit tells u how many 7 in number. find number. wrote piece of code in python find out digit. apart conditions mentioned above, have few additional checks 'sum of digits should 8' , 'no 8 or 9 should present in number'. i've pasted code below. brute force since take every number , check conditions. curious know if there better way of solving problem def returnstat(number, digit, count): number = str(number) digit = str(digit) print "analysing ",digit," see if appears ",count, " times in ",number,"." actcnt = number.count(digit) count = str(count) actcnt = str(actcnt) if (actcnt == count): return 1 else: return 0 def validatenum(number): numlist = str(number...