Skip to content

[2018] Remove Python 2.7 support #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2018/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions 2018/day01/day01.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/1
"""

from __future__ import print_function

from functools import reduce


Expand Down
2 changes: 0 additions & 2 deletions 2018/day02/day02.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/2
"""

from __future__ import print_function

from collections import Counter, defaultdict
from functools import reduce

Expand Down
2 changes: 0 additions & 2 deletions 2018/day03/day03.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 2018/day04/day04.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/4
"""

from __future__ import print_function

import re
from collections import defaultdict

Expand Down
2 changes: 0 additions & 2 deletions 2018/day05/day05.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/5
"""

from __future__ import print_function

from string import ascii_lowercase


Expand Down
12 changes: 4 additions & 8 deletions 2018/day06/day06.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions 2018/day07/day07.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/7
"""

from __future__ import print_function

import re
from collections import defaultdict

Expand Down
2 changes: 0 additions & 2 deletions 2018/day08/day08.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 0 additions & 2 deletions 2018/day09/day09.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/9
"""

from __future__ import print_function

import re
from collections import defaultdict

Expand Down
2 changes: 0 additions & 2 deletions 2018/day10/day10.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/10
"""

from __future__ import print_function

import re

_ENTRY_REGEX = re.compile(
Expand Down
2 changes: 0 additions & 2 deletions 2018/day11/day11.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 0 additions & 2 deletions 2018/day12/day12.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 2018/day13/day13.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/13
"""

from __future__ import print_function

_TURN_ORDER = [
-1,
0,
Expand Down
2 changes: 0 additions & 2 deletions 2018/day14/day14.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/14
"""

from __future__ import print_function


class RecipeGenerator:
"""Generator for the recipe combinations."""
Expand Down
2 changes: 0 additions & 2 deletions 2018/day15/day15.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/15
"""

from __future__ import print_function

from collections import defaultdict, deque
from operator import attrgetter

Expand Down
2 changes: 0 additions & 2 deletions 2018/day16/day16.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/16
"""

from __future__ import print_function

import re
from collections import defaultdict

Expand Down
2 changes: 0 additions & 2 deletions 2018/day17/day17.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 7 additions & 12 deletions 2018/day18/day18.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand All @@ -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 == '.':
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions 2018/day19/day19.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/19
"""

from __future__ import print_function

import re

_IP_REGEX = re.compile(r'^#ip (\d)$')
Expand Down
2 changes: 0 additions & 2 deletions 2018/day20/day20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 2018/day21/day21.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/21
"""

from __future__ import print_function

import re

_IP_REGEX = re.compile(r'^#ip (\d)$')
Expand Down
2 changes: 0 additions & 2 deletions 2018/day22/day22.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 2018/day23/day23.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/23
"""

from __future__ import print_function

import heapq
import re
from operator import attrgetter
Expand Down
2 changes: 0 additions & 2 deletions 2018/day24/day24.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions 2018/day25/day25.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://adventofcode.com/2018/day/25
"""

from __future__ import print_function

from collections import deque


Expand Down