Exemplo n.º 1
0
def main():
    test()

    input_data = utils.get_input_data(8).split('\n')
    memory = run(input_data)
    print(f'part a: {memory.max}')
    print(f'part b: {memory.global_max}')
Exemplo n.º 2
0
def main():
    test()

    instructions = utils.get_input_data(18).split('\n')
    program = Program(instructions)
    freq = program.run()
    print(f'part a: {freq}')
Exemplo n.º 3
0
def main():
    test()

    input_data = utils.get_input_data(19, strip=False)
    diagram = Diagram(input_data)
    diagram.run()
    print(f'part a: {diagram.path}')
    print(f'part b: {diagram.steps}')
Exemplo n.º 4
0
def main():
    test()

    input_directions = utils.get_input_data(11).split(',')
    steps = min_steps(input_directions)
    print(f'part a: {steps}')
    furthest = max_steps(input_directions)
    print(f'part b: {furthest}')
Exemplo n.º 5
0
def main():
    test()

    input_data = utils.get_input_data(12).split('\n')

    connections = connected_programs(input_data, 0)
    print(f'part a: {connections}')
    num_groups = connected_groups(input_data)
    print(f'part b: {num_groups}')
Exemplo n.º 6
0
def main():
    test()

    input_data = utils.get_input_data(13).split('\n')
    firewall_score = score(input_data)
    print(f'part a: {firewall_score}')

    wait = required_wait(input_data)
    print(f'part b: {wait}')
Exemplo n.º 7
0
def main():
    test()

    input_data = utils.get_input_data(1)

    part_a = calc_sum(input_data, next_idx_a)
    print('part a: {}'.format(part_a))

    part_b = calc_sum(input_data, next_idx_b)
    print('part b: {}'.format(part_b))
Exemplo n.º 8
0
def main() -> None:
    """Entry point of the script"""

    mode, value = get_input_data()
    if mode == 'file':
        solve_maze_from_file(value)
    elif mode == 'test':
        solve_test_mazes()
    else:
        display_help()
Exemplo n.º 9
0
def main():
    test()

    input_data = utils.get_input_data(5)
    input_data = [int(line) for line in input_data.split('\n')]

    part_a = steps_til_exit(input_data)
    print('part a: {}'.format(part_a))

    part_b = steps_til_exit(input_data, decrement_large_jumps)
    print('part b: {}'.format(part_b))
Exemplo n.º 10
0
def main():
    test()

    input_data = utils.get_input_data(2)
    input_data = [_parse_row(row) for row in input_data.split('\n')]

    part_a = checksum_a(input_data)
    print('part a: {}'.format(part_a))

    part_b = checksum_b(input_data)
    print('part b: {}'.format(part_b))
Exemplo n.º 11
0
def main():
    test()

    input_data = utils.get_input_data(4).split('\n')

    part_a = num_valid_passphrases(input_data, [words_unique])
    print('part a: {}'.format(part_a))

    part_b = num_valid_passphrases(input_data,
                                   [words_unique, words_not_anagrams])
    print('part b: {}'.format(part_b))
Exemplo n.º 12
0
def main():
    test()

    input_data = utils.get_input_data(7).split('\n')

    stack = Stack.parse(input_data)

    part_a = stack.bottom_program()
    print(f'part a: {part_a}')

    part_b = aoc_07b(stack)
    print(f'part b: {part_b}')
Exemplo n.º 13
0
def main():
    test()

    instructions = utils.get_input_data(16).split(',')
    dance = Dance(instructions)

    dance.perform()
    print(f'part a: {dance}')

    dance = Dance(instructions)

    dance_period = period(dance)

    for _ in range(int(1E9) % dance_period):
        dance.perform()

    print(f'part b: {dance}')
Exemplo n.º 14
0
            if grid[row][col] >= 2:
                count += 1
    return count


def get_grid_sum(grid, lo, to, w, h):
    total = 0
    for row in range(to, to + h):
        row_sum = sum(grid[row][lo:lo + w])
        total += row_sum
    return total


def get_nonoverlap_id(grid, claims):
    for claim in claims:
        id, lo, to, w, h = claim
        if get_grid_sum(grid, lo, to, w, h) == w * h:
            return id


if __name__ == "__main__":
    claims = get_input_data("day3input.txt")
    max_w, max_h, processed_claims = preprocess_data(claims)
    grid = get_overlap_grid(max_w, max_h, processed_claims)

    #part 1
    print(get_overlap_count(grid))

    #part 2
    print(get_nonoverlap_id(grid, processed_claims))
Exemplo n.º 15
0
    curr_player = 0
    while turn < num_marbles:
        if turn % 23 == 0:
            bonus = board.move_23()
            scores[curr_player + 1] += bonus + turn
        else:
            board.insert(turn)
        turn += 1
        curr_player = (curr_player + 1) % num_players
    return (scores, board)


# def

if __name__ == "__main__":
    rules = get_input_data("day9input.txt")
    split = rules[0].split(" ")
    num_players = int(split[0])
    num_marbles = int(split[-2]) + 1  # add one b/c of marble 0

    # part 1
    scores, board = play_game(num_players, num_marbles)
    k, v = max(scores.iteritems(), key=operator.itemgetter(1))
    print(k, v)

    # part 2
    start = time.time()
    large_num_marbles = int(split[-2]) * 100 + 1
    scores, board = play_game(num_players, large_num_marbles)
    end = time.time()
    k, v = max(scores.iteritems(), key=operator.itemgetter(1))
Exemplo n.º 16
0
	return twos * threes

def get_edit_distance(w1, w2):
	if len(w1) != len(w2):
		print("Invalid inputs: varying length")
		return
	distance = 0
	for i in range(len(w1)):
		if w1[i] != w2[i]:
			distance += 1
	return distance

def find_edit_distance_one(labels):
	len_labels = len(labels)
	for i in range(len_labels):
		for j in range(i, len_labels):
			if get_edit_distance(labels[i], labels[j]) == 1:
				return (labels[i], labels[j])

if __name__ == "__main__":
	labels = get_input_data("day2input.txt")
	# part 1
	print(get_product(labels))
	# part 2
	word1, word2 = find_edit_distance_one(labels)
	common_letters = ""
	for i in range(len(word1)):
		if word1[i] == word2[i]:
			common_letters += word1[i]
	print(common_letters)
Exemplo n.º 17
0
            acc_freq -= num
    print(acc_freq)


def get_first_repeated_freq(freqs):
    i = 0
    len_freq = len(freqs)
    seen_freqs = set([0])
    acc_freq = 0
    while True:
        curr_ind = i % len_freq
        freq = freqs[curr_ind]
        num = int(freq[1:])
        if freq[0] == "+":
            acc_freq += num
        else:
            acc_freq -= num
        if acc_freq in seen_freqs:
            print(acc_freq)
            return
        seen_freqs.add(acc_freq)
        i += 1


if __name__ == "__main__":
    freqs = get_input_data("day1input.txt")
    # part 1
    calc_freq(freqs)
    # part 2
    get_first_repeated_freq(freqs)
Exemplo n.º 18
0
                self.id = grid.carts[up].tile
                grid.removed_carts.add(self.id)
                grid.removed_carts.add(up)
            self.process_v_move(up)
            self.move_up(up, grid.grid)

        else:
            down = grid.get_down(self.x, self.y)
            if not down in PATH_OBJECTS:
                grid.collision = (self.x, self.y + 1)
                self.id = grid.carts[down].tile
                grid.removed_carts.add(self.id)
                grid.removed_carts.add(down)
            self.process_v_move(down)
            self.move_down(down, grid.grid)


if __name__ == "__main__":
    data = get_input_data("day13input.txt")
    grid = Grid(data)
    # part 1
    while grid.collision == None:
        grid.next_tick()
    grid.print_grid()
    print(grid.collision)

    #part 2
    while grid.last_cart == None:
        grid.next_tick()
    grid.print_grid()
    print(grid.last_cart.x, grid.last_cart.y)
Exemplo n.º 19
0
from utils import get_input_data


def preprocess_data(events):
    split_events = []
    for event in events:
        split = event.split("]")
        time = split[0][1:]
        desc = split[1].strip()
        split_events.append((time, desc))
    sorted_events = sorted(split_events, key=lambda tup: tup[0])
    return sorted_events


if __name__ == "__main__":
    events = get_input_data("day4input.txt")
    sorted_events = preprocess_data(events)
    print(sorted_events[:20])
Exemplo n.º 20
0
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

from utils import show_output, get_input_data

x = np.arange(1000).reshape(-1, 1)
y = np.arange(1, 1001)

x, x_test, y, y_test = train_test_split(x, y, test_size=0.2)

model = LinearRegression()

model.fit(x, y)

score = model.score(x_test, y_test)

input_data = get_input_data()

prediction = model.predict(input_data)

show_output(input_data, score, prediction)