ref: f9483d7ee9a96891fbfaebd73acdc6b6e6895e7f
2019/004/main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
def has_double(n): s = str(n) o = {} for d in s: if d not in o: o[d] = 1 else: o[d] += 1 for v in o.values(): if v == 2: return True return False def does_increase(n): s = str(n) p = 0 for d in s: dd = int(d) if dd < p: return False p = dd return True def matches(n): return has_double(n) and does_increase(n) def main(): assert matches(112233) assert not matches(123444) assert matches(111122) # return c = 0 for n in range(172930, 683082): if matches(n): c += 1 print(c) if __name__ == '__main__': main() |