commit d98128cf7c4865fe421b3d688eaf25cad34819fc
parent 242c2e925eb7250789d8ed3aec603ece32e5028b
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Wed, 15 Dec 2021 10:54:40 -0500
Moving function to `utils` now that I need it again
Diffstat:
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/day11_part1.py b/day11_part1.py
@@ -22,7 +22,7 @@ from typing import Tuple
import itertools
import functools
import numpy as np
-from utils import get_puzzle_input
+from utils import get_puzzle_input, convert_input_to_array
EXAMPLE_INPUT = \
"""5483143223
@@ -37,13 +37,6 @@ EXAMPLE_INPUT = \
5283751526
"""
-def convert_input_to_array(input_string: str) -> np.ndarray:
- """Convert the input into a 2d int array"""
- return (
- np.array([list(line) for line in input_string.rstrip('\n').split('\n')])
- .astype(int)
- )
-
def increment_neighbors(increments: np.ndarray,
row: int, col: int) -> np.ndarray:
"""Increase the value of the given `increments` 2d array by 1 in the
diff --git a/day11_part2.py b/day11_part2.py
@@ -8,9 +8,8 @@ want to find the `step` at which they all flash simultaneously."""
import numpy as np
from day11_part1 import (EXAMPLE_INPUT,
- convert_input_to_array,
simulate_step)
-from utils import get_puzzle_input
+from utils import get_puzzle_input, convert_input_to_array
def all_flashed(energy_levels: np.ndarray) -> bool:
"""Detects the moment when all energy levels have been reset to 0"""
diff --git a/utils.py b/utils.py
@@ -6,6 +6,13 @@ import requests
import numpy as np
import pandas as pd
+def convert_input_to_array(input_string: str) -> np.ndarray:
+ """Convert the (newline-delimited) input string into a 2d int array"""
+ return (
+ np.array([list(line) for line in input_string.rstrip('\n').split('\n')])
+ .astype(int)
+ )
+
def convert_lines_to_series(input_string: str) -> pd.Series:
"""Return a pandas Series consisting of the lines in the
(newline-delimited) input string"""