def test_day_4(): input_day_4 = open_single_line_file('day4') assert brute_force_hash_finding('abcdef') == 609043 assert brute_force_hash_finding('pqrstuv') == 1048970 assert brute_force_hash_finding(input_day_4, 5) == answers['day4']['part1'] assert brute_force_hash_finding(input_day_4, 6) == answers['day4']['part2']
def test_day_3(): input_day_3 = open_single_line_file('day3') assert number_of_distributed_presents('>') == 2 assert number_of_distributed_presents('^>v<') == 4 assert number_of_distributed_presents('^v^v^v^v^v') == 2 assert number_of_distributed_presents(input_day_3) == \ answers['day3']['part1'] assert number_of_distributed_presents_with_robot('^>') == 3 assert number_of_distributed_presents_with_robot('^>v<') == 3 assert number_of_distributed_presents_with_robot('^v^v^v^v^v') == 11 assert number_of_distributed_presents_with_robot(input_day_3) == \ answers['day3']['part2']
def test_day_1(): input_day_1 = open_single_line_file('day1') assert find_floor('(())') == 0 assert find_floor('()()') == 0 assert find_floor('(((') == 3 assert find_floor('(()(()(') == 3 assert find_floor('))(((((') == 3 assert find_floor('())') == -1 assert find_floor('))(') == -1 assert find_floor(')))') == -3 assert find_floor(')())())') == -3 assert find_floor(input_day_1) == answers['day1']['part1'] assert find_basement_entry_char(')') == 1 assert find_basement_entry_char('()())') == 5 assert find_basement_entry_char(input_day_1) == answers['day1']['part2']
If your secret key is abcdef, the answer is 609043, because the MD5 hash of abcdef609043 starts with five zeroes (000001dbbfa...), and it is the lowest such number to do so. If your secret key is pqrstuv, the lowest number it combines with to make an MD5 hash starting with five zeroes is 1048970; that is, the MD5 hash of pqrstuv1048970 looks like 000006136ef.... --- Part Two --- Now find one that starts with six zeroes. """ from importer import open_single_line_file from hashlib import md5 def brute_force_hash_finding(input, lenght_of_0=5): hash = md5(input.encode()) number = -1 while hash.hexdigest()[:lenght_of_0] != '0' * lenght_of_0: number += 1 entry = input + str(number) hash = md5(entry.encode()) return number # Results data = open_single_line_file('day4') print("Result for part 1 :", brute_force_hash_finding(data, 5)) print("Result for part 1 :", brute_force_hash_finding(data, 6))