day01 package

Subpackages

Submodules

day01.day1a module

day1a solution.

day01.day1a.get_first_last(line: str) tuple[str, str][source]

Returns first and last numeric character of a string.

It can be the same character.

Parameters:

line (str) – string to parse

Raises:

ValueError – When there are no numbers in the string

Returns:

first char, last char

Return type:

tuple[str, str]

day01.day1a.get_input(input_file: str) list[str][source]

Grabs list of lines to parse from input file.

Parameters:

input_file (str) – input file’s name

Returns:

list of lines to parse

Return type:

list[str]

day01.day1a.main() None[source]

Grabs input then processes it.

day01.day1a.part1(lines: list[str]) int[source]

Runs day1/part1 of adventofcode2023.

Parameters:

lines (list[str]) – list of lines to parse

Returns:

sum of results for each line.

Return type:

int

day01.day1b module

day1b solution.

class day01.day1b.IndexValue(index: int = 0, value: str = '1')[source]

Bases: object

index to value mapping.

index: int = 0
value: str = '1'
class day01.day1b.WordNumber(word: str = 'one', number: str = '1')[source]

Bases: object

Simple mapping from word to integer.

number: str = '1'
word: str = 'one'
day01.day1b.get_input(input_file: str) list[str][source]

Opens a file and returns a list of strings to handle.

Parameters:

input_file (str) – filepath of input

Returns:

list of strings to parse

Return type:

list[str]

day01.day1b.main() None[source]

Grabs input and then processes it.

day01.day1b.part2(lines: list[str]) int[source]

Returns sum of “first/last” numbers in line.

Parameters:

lines (list[str]) – list of lines to handle

Returns:

sum of “first/last” numbers in line

Return type:

int

day01.day1b.process_line(line: str) int[source]

Processes a line, returning the first and last integer.

Substrings like nine and one count as integers, as do 1 and 9.

Parameters:

line (str) – a line to process

Returns:

integer value of the two numbers concatenated

Return type:

int

Module contents

day01 package.