My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2019/04

+39
+36
2019/day04.py
··· 1 + import fileinput 2 + 3 + password_range = fileinput.input()[0] 4 + start, end = (int(x) for x in password_range.split('-')) 5 + 6 + def increasing(n): 7 + s = [int(c) for c in str(n)] 8 + if s[0] <= s[1] <= s[2] <= s[3] <= s[4] <= s[5]: 9 + return True 10 + 11 + def part_1_valid(n): 12 + if not increasing(n): 13 + return False 14 + 15 + s = [int(c) for c in str(n)] 16 + if s[0] == s[1] or s[1] == s[2] or s[2] == s[3] or s[3] == s[4] or s[4] == s[5]: 17 + return True 18 + 19 + return False 20 + 21 + def part_2_valid(n): 22 + if not increasing(n): 23 + return False 24 + 25 + s = [int(c) for c in str(n)] 26 + if ((s[0] == s[1] and s[1] != s[2]) or 27 + (s[1] == s[2] and s[1] != s[0] and s[1] != s[3]) or 28 + (s[2] == s[3] and s[2] != s[1] and s[2] != s[4]) or 29 + (s[3] == s[4] and s[3] != s[2] and s[3] != s[5]) or 30 + (s[4] == s[5] and s[4] != s[3])): 31 + return True 32 + 33 + return False 34 + 35 + print "Part 1 passwords:", sum(part_1_valid(n) for n in range(start, end + 1)) 36 + print "Part 2 passwords:", sum(part_2_valid(n) for n in range(start, end + 1))
+1
2019/inputs/04.txt
··· 1 + 367479-893698
+2
2019/outputs/04.txt
··· 1 + 495 2 + 305