GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AdventOfCode/languages/py/2019/04_SecureContainer.py at main · wolflu05/AdventOfCode Expand file tree/ Copy path04_SecureContainer.pyMore file actions 44 lines (33 loc) · 802 Bytes / Copy path04_SecureContainer.pyFile metadata and controls44 lines (33 loc) · 802 Bytes 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 from lib import * a,b = [int(x) for x in get_input()[0].split('-')] def is_valid(x): for i in range(0, len(str(x))-1): if str(x)[i] > str(x)[i+1]: return False, False fnd1 = False fnd2 = False for s in set(str(x)): c = str(x).count(s) if c == 2: fnd2 = True if c > 1: fnd1 = True return fnd1, fnd2 p1 = 0 p2 = 0 for x in range(a, b+1): r1, r2 = is_valid(x) if r1: p1 += 1 if r2: p2 += 1 print(p1) print(p2) # Part 1 assert is_valid(111111) == (True, False) assert is_valid(223450) == (False, False) assert is_valid(123789) == (False, False) # Part 2 assert is_valid(112233) == (True, True) assert is_valid(123444) == (True, False) assert is_valid(111122) == (True, True) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |