Created
December 2, 2025 13:10
-
-
Save jmarrec/3466f43e341f7416f78fab0f03f4a6ee to your computer and use it in GitHub Desktop.
Day 2 Part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| RESOURCES_DIR = Path(__file__).parent.absolute() | |
| DAY_2 = RESOURCES_DIR / 'day_2.txt' | |
| assert DAY_2.is_file() | |
| DAY_2_CONTENT = DAY_2.read_text() | |
| def parse_content(content: str) -> list[(int, int)]: | |
| return [(int(x.split('-')[0]), int(x.split('-')[1])) for x in content.split(',')] | |
| def day_2_part2(content: str, verbose: bool = False) -> int: | |
| result = 0 | |
| ranges = parse_content(content=content) | |
| for start, end in ranges: | |
| for i in range(start, end+1): | |
| s = str(i) | |
| str_size = len(s) | |
| for n in range(str_size - 1, 0, -1): | |
| if str_size % n != 0: | |
| continue | |
| if len({s[j:j + n] for j in range(0, str_size, n)}) == 1: | |
| result += i | |
| if verbose: | |
| print(f"Found {i} with {n}") | |
| break | |
| return result | |
| if __name__ == "__main__": | |
| print(day_2_part2(content=DAY_2_CONTENT)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 503950-597501,73731-100184,79705998-79873916,2927-3723,35155-50130,52-82,1139-1671,4338572-4506716,1991-2782,1314489-1387708,8810810-8984381,762581-829383,214957-358445,9947038-10058264,4848455367-4848568745,615004-637022,5827946-5911222,840544-1026063,19-46,372804-419902,486-681,815-1117,3928-5400,28219352-28336512,6200009-6404247,174-261,151131150-151188124,19323-26217,429923-458519,5151467682-5151580012,9354640427-9354772901,262-475,100251-151187,5407-9794,8484808500-8484902312,86-129,2-18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment