1
0
Fork 0
advent2017/4/4p2.py

42 lines
803 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
inputs = ["part2.txt", "input.txt"]
def isvalid(password):
newdict = []
for item in password:
newdict.append(''.join(sorted(item)))
valid = True
for item in newdict:
if newdict.count(item) > 1:
valid = False
break
return valid
def solve(filename):
good = 0
bad = 0
with open(filename, "r") as fp:
for line in fp:
password = line.strip()
passdict = password.split(" ")
valid = isvalid(passdict)
print(password, isvalid(passdict))
if valid is True:
good = good + 1
else:
bad = bad + 1
return (good, bad)
for puzzle in inputs:
print(puzzle, solve(puzzle))