|
| 1 | +# -------------------------------- Input data -------------------------------- # |
| 2 | +import os |
| 3 | + |
| 4 | +test_data = {} |
| 5 | + |
| 6 | +test = 1 |
| 7 | +test_data[test] = {"input": """abcdef |
| 8 | +bababc |
| 9 | +abbcde |
| 10 | +abcccd |
| 11 | +aabcdd |
| 12 | +abcdee |
| 13 | +ababab""", |
| 14 | + "expected": ['Unknown', 'Unknown'], |
| 15 | + } |
| 16 | + |
| 17 | +test = 2 |
| 18 | +test_data[test] = {"input": """abcde |
| 19 | +fghij |
| 20 | +klmno |
| 21 | +pqrst |
| 22 | +fguij |
| 23 | +axcye |
| 24 | +wvxyz""", |
| 25 | + "expected": ['Unknown', 'Unknown'], |
| 26 | + } |
| 27 | + |
| 28 | +test = 'real' |
| 29 | +input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt')) |
| 30 | +test_data[test] = {"input": open(input_file, "r+").read().strip(), |
| 31 | + "expected": ['7688', 'lsrivmotzbdxpkxnaqmuwcchj'], |
| 32 | + } |
| 33 | + |
| 34 | +# -------------------------------- Control program execution -------------------------------- # |
| 35 | + |
| 36 | +case_to_test = 'real' |
| 37 | +part_to_test = 2 |
| 38 | +verbose_level = 1 |
| 39 | + |
| 40 | +# -------------------------------- Initialize some variables -------------------------------- # |
| 41 | + |
| 42 | +puzzle_input = test_data[case_to_test]['input'] |
| 43 | +puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1] |
| 44 | +puzzle_actual_result = 'Unknown' |
| 45 | + |
| 46 | + |
| 47 | +# -------------------------------- Actual code execution -------------------------------- # |
| 48 | + |
| 49 | +if part_to_test == 1: |
| 50 | + count_2_letters = 0 |
| 51 | + count_3_letters = 0 |
| 52 | + |
| 53 | + for string in puzzle_input.split('\n'): |
| 54 | + if any(string.count(x) == 2 for x in string): |
| 55 | + count_2_letters += 1 |
| 56 | + if any(string.count(x) == 3 for x in string): |
| 57 | + count_3_letters += 1 |
| 58 | + |
| 59 | + puzzle_actual_result = count_2_letters*count_3_letters |
| 60 | + |
| 61 | + |
| 62 | +else: |
| 63 | + list_strings = puzzle_input.split('\n') |
| 64 | + for string in list_strings: |
| 65 | + for i in range(len(string)): |
| 66 | + new_strings = [string[:i] + x + string[i+1:] for x in 'azertyuiopqsdfghjklmwxcvbn'] |
| 67 | + new_strings.remove(string) |
| 68 | + if any(x in list_strings for x in new_strings): |
| 69 | + puzzle_actual_result = string[:i] + string[i+1:] |
| 70 | + break |
| 71 | + if puzzle_actual_result != 'Unknown': |
| 72 | + break |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +# -------------------------------- Outputs / results -------------------------------- # |
| 78 | + |
| 79 | +if verbose_level >= 3: |
| 80 | + print ('Input : ' + puzzle_input) |
| 81 | +print ('Expected result : ' + str(puzzle_expected_result)) |
| 82 | +print ('Actual result : ' + str(puzzle_actual_result)) |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
0 commit comments