def solve():
    data = read_data("p059_cipher.txt")
    data = parse_list(data, separator=",", parse_item=int)

    text = brute_force(data)

    return sum((map(ord, text)))
Beispiel #2
0
def read_poker_hands():
    poker_hands = []

    for cards in read_data("p054_poker.txt").splitlines():
        poker_hands.append((PokerHand(cards[:14]), PokerHand(cards[15:])))

    return poker_hands
Beispiel #3
0
def solve():
    data = read_data("p022_names.txt")
    names = parse_list(data,
                       separator=",",
                       parse_item=lambda s: s.replace('"', ""))
    names.sort()

    return sum([
        alphabetical_value(name) * (position + 1)
        for position, name in enumerate(names)
    ])
def solve():
    data = read_data("p089_roman.txt").splitlines()
    result = 0

    for roman in data:
        arabic = to_arabic(roman)
        minimal_roman = to_roman(arabic)
        saved_characters = len(roman) - len(minimal_roman)

        result += saved_characters

    return result
def solve():
    data = read_data("p098_words.txt")
    words = parse_list(data,
                       separator=",",
                       parse_item=lambda s: s.replace('"', ""))

    anagrams = find_anagrams(words)
    largest = 0

    for pair in anagrams:
        square = largest_anagramic_square(*pair)
        if square > largest:
            largest = square

    return largest
Beispiel #6
0
def solve():
    data = read_data("p042_words.txt")
    words = parse_list(data,
                       separator=",",
                       parse_item=lambda s: s.replace('"', ""))

    limit = 10_000
    triangle_numbers = set(itertools.islice(gen_triangle_numbers(), limit))

    count = 0
    for word in words:
        if alphabetical_value(word) in triangle_numbers:
            count += 1

    return count
Beispiel #7
0
def solve():
    data = read_data("p096_sudoku.txt")
    sudokus = parse_sudokus(data)
    result = 0

    for i, sudoku in enumerate(sudokus, 1):
        solved = solve_sudoku(sudoku)
        top_left = join_digits(sudoku[0][0:3])
        result += top_left

        info(f"Sudoku {i} {'solved' if solved else 'FAILED'}: {top_left}")
        info(sudoku)
        info("")

    return result
from math import inf
from common.data import read_data, parse_grid
from solutions.problem_081 import parse_graph, dijkstra, EXAMPLE_DATA


def solve(data=EXAMPLE_DATA):
    grid = parse_grid(data, separator=",", parse_item=int)
    graph = parse_graph(grid, directions=[(0, 1), (1, 0), (-1, 0)])

    height = len(grid)
    width = len(grid[0])

    result = inf

    for start_row in range(height):
        dist, prev = dijkstra(graph, (start_row, 0))

        for end_row in range(height):
            distance = grid[start_row][0] + dist[(end_row, width - 1)]

            if distance < result:
                result = distance

    return result


if __name__ == "__main__":
    data = read_data("p082_matrix.txt")
    print(solve(data))
from common.data import read_data
from solutions.problem_018 import parse_triangle, maximum_path

data = read_data("p067_triangle.txt")

triangle = parse_triangle(data)
print(maximum_path(triangle))
def solve():
    keylog = read_data("p079_keylog.txt").splitlines()
    keylog = set(keylog)

    return crack_passcode(keylog)
from math import log
from common.data import read_data

data = read_data("p099_base_exp.txt")

highest = 0
highest_line = 0

for line_number, base_exp in enumerate(data.splitlines(), 1):
    base, exp = map(int, base_exp.split(","))

    # https://www.rapidtables.com/math/algebra/logarithm/Logarithm_Rules.html#power%20rule
    number = log(base) * exp

    if number > highest:
        highest = number
        highest_line = line_number

print(highest_line)