Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Lock code cracker by @CodingComputing
- def count_correct(com, ref):
- return len([a for a in com if a in ref])
- def count_correct_well_placed(com, ref):
- return len([a for a,b in zip(com,ref) if a==b])
- def count_correct_wrongly_placed(com, ref):
- n_correct = count_correct(com, ref)
- n_well_placed = count_correct_well_placed(com, ref)
- return n_correct - n_well_placed
- condition_checkers = [
- lambda com: count_correct_well_placed(com, '682') == 1,
- lambda com: count_correct_wrongly_placed(com, '614') == 1,
- lambda com: count_correct_wrongly_placed(com, '206') == 2,
- lambda com: count_correct(com, '738') == 0,
- lambda com: count_correct_wrongly_placed(com, '780') == 1,
- ]
- def check_all(com):
- return all([check(com) for check in condition_checkers])
- valid_coms = []
- for num in range(1000):
- com = f"{num:03}"
- if check_all(com):
- valid_coms.append(com)
- print("Valid combinations:", valid_coms)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement