day04 package

Subpackages

Submodules

day04.day4 module

Day 4 solution.

class day04.day4.Card(input_string: str)[source]

Bases: object

a card with winners and numbers we own.

get_matches() int[source]

Returns how many winners intersect with what we have.

get_points() int[source]

Returns how many points the card is worth.

Returns:

0 for no match, otherwise 2^(matches-1)

Return type:

int

have: set[int]
id: int = 0
winners: set[int]
class day04.day4.Inventory(all_cards: list[Card])[source]

Bases: object

Total inventory of cards based on Question2 accumulation.

all_cards: list[Card]
calculate_mappings() dict[int, int][source]

Returns map of card_id -> cards owned.

memoized: dict[int, int]
total_cards() int[source]

Return total cards in inventory.

day04.day4.grab_data(filename: str) list[Card][source]

Converts file into wellformed cards.

day04.day4.main() None[source]

Loads input file then runs part1 and part2.

day04.day4.part1(cards: list[Card]) int[source]

Return sum of points for each card in list.

day04.day4.part2(cards: list[Card]) int[source]

Return total number of cards in our inventory.

day04.day4.split_numbers(string: str) set[int][source]

Splits a list of string’ed numbers into a set.

E.g: `` 39 40 41 42 `` -> set(39,40,41,42)

Parameters:

string (str) – a list of string’ed numbers

Returns:

a set of integers

Return type:

set[int]

Module contents

day04 solution.