From 08fbe07c7b020539fa57f43d6b1070a94f64719d Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Tue, 20 May 2025 00:01:20 -0700 Subject: [PATCH 1/2] [2018] Remove Python 2.7 support --- 2018/day01/day01.py | 2 -- 2018/day02/day02.py | 2 -- 2018/day03/day03.py | 2 -- 2018/day04/day04.py | 2 -- 2018/day05/day05.py | 2 -- 2018/day06/day06.py | 12 ++++-------- 2018/day07/day07.py | 2 -- 2018/day08/day08.py | 2 -- 2018/day09/day09.py | 2 -- 2018/day10/day10.py | 2 -- 2018/day11/day11.py | 2 -- 2018/day12/day12.py | 2 -- 2018/day13/day13.py | 2 -- 2018/day14/day14.py | 2 -- 2018/day15/day15.py | 2 -- 2018/day16/day16.py | 2 -- 2018/day17/day17.py | 2 -- 2018/day18/day18.py | 19 +++++++------------ 2018/day19/day19.py | 2 -- 2018/day20/day20.py | 2 -- 2018/day21/day21.py | 2 -- 2018/day22/day22.py | 2 -- 2018/day23/day23.py | 2 -- 2018/day24/day24.py | 2 -- 2018/day25/day25.py | 2 -- 25 files changed, 11 insertions(+), 66 deletions(-) diff --git a/2018/day01/day01.py b/2018/day01/day01.py index 16c4772..4da2bd4 100644 --- a/2018/day01/day01.py +++ b/2018/day01/day01.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/1 """ -from __future__ import print_function - from functools import reduce diff --git a/2018/day02/day02.py b/2018/day02/day02.py index 1df90e2..0861afb 100644 --- a/2018/day02/day02.py +++ b/2018/day02/day02.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/2 """ -from __future__ import print_function - from collections import Counter, defaultdict from functools import reduce diff --git a/2018/day03/day03.py b/2018/day03/day03.py index a985a7f..86f5c7c 100644 --- a/2018/day03/day03.py +++ b/2018/day03/day03.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/3 """ -from __future__ import print_function - import re from collections import defaultdict from functools import reduce diff --git a/2018/day04/day04.py b/2018/day04/day04.py index d570efa..f84840e 100644 --- a/2018/day04/day04.py +++ b/2018/day04/day04.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/4 """ -from __future__ import print_function - import re from collections import defaultdict diff --git a/2018/day05/day05.py b/2018/day05/day05.py index d4b8f36..d2b08c4 100644 --- a/2018/day05/day05.py +++ b/2018/day05/day05.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/5 """ -from __future__ import print_function - from string import ascii_lowercase diff --git a/2018/day06/day06.py b/2018/day06/day06.py index bda8c53..c8fd7d6 100644 --- a/2018/day06/day06.py +++ b/2018/day06/day06.py @@ -4,13 +4,9 @@ https://adventofcode.com/2018/day/6 """ -from __future__ import print_function - import sys from functools import reduce -_MIN_INT = -sys.maxsize - 1 - class Point: """Represents a point in 2D space.""" @@ -37,10 +33,10 @@ class Rect: @staticmethod def bounding_box(points): """Returns a rectangle which forms the boundary of all points""" - min_x = sys.maxsize - min_y = sys.maxsize - max_x = _MIN_INT - max_y = _MIN_INT + min_x = float('inf') + min_y = float('inf') + max_x = float('-inf') + max_y = float('-inf') for point in points: min_x = min(min_x, point.coord_x) diff --git a/2018/day07/day07.py b/2018/day07/day07.py index d2df6ad..1d3cd9c 100644 --- a/2018/day07/day07.py +++ b/2018/day07/day07.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/7 """ -from __future__ import print_function - import re from collections import defaultdict diff --git a/2018/day08/day08.py b/2018/day08/day08.py index 1db786b..83fa20b 100644 --- a/2018/day08/day08.py +++ b/2018/day08/day08.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/8 """ -from __future__ import print_function - class TreeNode: # pylint: disable=too-few-public-methods """Represents a single node in the tree.""" diff --git a/2018/day09/day09.py b/2018/day09/day09.py index 0bbdcdf..e3da41e 100644 --- a/2018/day09/day09.py +++ b/2018/day09/day09.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/9 """ -from __future__ import print_function - import re from collections import defaultdict diff --git a/2018/day10/day10.py b/2018/day10/day10.py index 2345a13..b85aaeb 100644 --- a/2018/day10/day10.py +++ b/2018/day10/day10.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/10 """ -from __future__ import print_function - import re _ENTRY_REGEX = re.compile( diff --git a/2018/day11/day11.py b/2018/day11/day11.py index 5479e37..be3c57e 100644 --- a/2018/day11/day11.py +++ b/2018/day11/day11.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/11 """ -from __future__ import print_function - def get_power_level(serial_number, coord_x, coord_y): """Gets the power level for a given coordinate.""" diff --git a/2018/day12/day12.py b/2018/day12/day12.py index ee99594..7c25771 100644 --- a/2018/day12/day12.py +++ b/2018/day12/day12.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/12 """ -from __future__ import print_function - import re from collections import defaultdict, deque from functools import reduce diff --git a/2018/day13/day13.py b/2018/day13/day13.py index 15a922b..66cdea9 100644 --- a/2018/day13/day13.py +++ b/2018/day13/day13.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/13 """ -from __future__ import print_function - _TURN_ORDER = [ -1, 0, diff --git a/2018/day14/day14.py b/2018/day14/day14.py index c138eba..7964061 100644 --- a/2018/day14/day14.py +++ b/2018/day14/day14.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/14 """ -from __future__ import print_function - class RecipeGenerator: """Generator for the recipe combinations.""" diff --git a/2018/day15/day15.py b/2018/day15/day15.py index 6c34722..be5d804 100644 --- a/2018/day15/day15.py +++ b/2018/day15/day15.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/15 """ -from __future__ import print_function - from collections import defaultdict, deque from operator import attrgetter diff --git a/2018/day16/day16.py b/2018/day16/day16.py index cc759a5..0761b89 100644 --- a/2018/day16/day16.py +++ b/2018/day16/day16.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/16 """ -from __future__ import print_function - import re from collections import defaultdict diff --git a/2018/day17/day17.py b/2018/day17/day17.py index b164de5..b42c27f 100644 --- a/2018/day17/day17.py +++ b/2018/day17/day17.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/17 """ -from __future__ import print_function - import re from collections import defaultdict from functools import reduce diff --git a/2018/day18/day18.py b/2018/day18/day18.py index a598031..3fa36ab 100644 --- a/2018/day18/day18.py +++ b/2018/day18/day18.py @@ -4,16 +4,11 @@ https://adventofcode.com/2018/day/18 """ -from __future__ import print_function - from collections import Counter from operator import itemgetter -try: - xrange # pylint: disable=used-before-assignment -except NameError: - xrange = range # pylint: disable=invalid-name + class LumberArea: @@ -33,9 +28,9 @@ def __init__(self, file_content): def __str__(self): lines = [] - for row_index in xrange(self.max_rows + 1): + for row_index in range(self.max_rows + 1): line = [] - for cell_index in xrange(self.max_cells + 1): + for cell_index in range(self.max_cells + 1): line.append(self.area[(row_index, cell_index)]) lines.append(''.join(line)) @@ -48,8 +43,8 @@ def get_counts(self): def execute_minute(self): """Executes a single minute of growth.""" area_copy = self.area.copy() - for row_index in xrange(self.max_rows + 1): - for cell_index in xrange(self.max_cells + 1): + for row_index in range(self.max_rows + 1): + for cell_index in range(self.max_cells + 1): position = (row_index, cell_index) cell = self.area[position] if cell == '.': @@ -94,7 +89,7 @@ def run_part1(file_content): """Implmentation for Part 1.""" area = LumberArea(file_content) - for _ in xrange(10): + for _ in range(10): area.execute_minute() counts = area.get_counts() @@ -108,7 +103,7 @@ def run_part2(file_content): cycle_index = None cycle_patterns = [] - for minute in xrange(1000000000): + for minute in range(1000000000): area.execute_minute() pattern = str(area) diff --git a/2018/day19/day19.py b/2018/day19/day19.py index 717c961..4df1091 100644 --- a/2018/day19/day19.py +++ b/2018/day19/day19.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/19 """ -from __future__ import print_function - import re _IP_REGEX = re.compile(r'^#ip (\d)$') diff --git a/2018/day20/day20.py b/2018/day20/day20.py index c06e01b..eea7d0e 100644 --- a/2018/day20/day20.py +++ b/2018/day20/day20.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/20 """ -from __future__ import print_function - from collections import defaultdict, deque from operator import itemgetter from sys import maxsize diff --git a/2018/day21/day21.py b/2018/day21/day21.py index 140ca54..5ff2052 100644 --- a/2018/day21/day21.py +++ b/2018/day21/day21.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/21 """ -from __future__ import print_function - import re _IP_REGEX = re.compile(r'^#ip (\d)$') diff --git a/2018/day22/day22.py b/2018/day22/day22.py index b8a8265..500e790 100644 --- a/2018/day22/day22.py +++ b/2018/day22/day22.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/22 """ -from __future__ import print_function - import re from collections import defaultdict from operator import itemgetter diff --git a/2018/day23/day23.py b/2018/day23/day23.py index 237fcae..eab6d08 100644 --- a/2018/day23/day23.py +++ b/2018/day23/day23.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/23 """ -from __future__ import print_function - import heapq import re from operator import attrgetter diff --git a/2018/day24/day24.py b/2018/day24/day24.py index ecbccd6..58797db 100644 --- a/2018/day24/day24.py +++ b/2018/day24/day24.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/24 """ -from __future__ import print_function - import re from collections import defaultdict from functools import reduce diff --git a/2018/day25/day25.py b/2018/day25/day25.py index 221558e..c2f9edf 100644 --- a/2018/day25/day25.py +++ b/2018/day25/day25.py @@ -4,8 +4,6 @@ https://adventofcode.com/2018/day/25 """ -from __future__ import print_function - from collections import deque From 5b0af41d13acb45df2b547fcfb0e5f475b3b151b Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Sun, 25 May 2025 11:37:15 -0700 Subject: [PATCH 2/2] Fix readme --- 2018/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2018/README.md b/2018/README.md index 86e04e1..ce0c25f 100644 --- a/2018/README.md +++ b/2018/README.md @@ -5,7 +5,7 @@ https://adventofcode.com/2018 ## Language This year I chose to implement in Python 2, but ported the code such that it -works in either Python 2 or Python 3. +works properly in Python 3. Python 2 support has been removed. ## Preparation