-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
1,390 additions
and
1,736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from lib import * | ||
|
||
input = read_input(2019, 1) | ||
|
||
out = 0 | ||
for line in input.splitlines(): | ||
out += int(line) // 3 - 2 | ||
print(out) | ||
|
||
|
||
out = 0 | ||
for line in input.splitlines(): | ||
fuel = int(line) // 3 - 2 | ||
while fuel > 0: | ||
out += fuel | ||
fuel = fuel // 3 - 2 | ||
print(out) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from lib import * | ||
|
||
input = read_input(2019, 2) | ||
|
||
(*mem,) = map(int, input.strip().split(",")) | ||
i = 0 | ||
mem[1] = 12 | ||
mem[2] = 2 | ||
while i < len(mem): | ||
if mem[i] == 99: | ||
break | ||
elif mem[i] == 1: | ||
mem[mem[i + 3]] = mem[mem[i + 1]] + mem[mem[i + 2]] | ||
elif mem[i] == 2: | ||
mem[mem[i + 3]] = mem[mem[i + 1]] * mem[mem[i + 2]] | ||
i += 4 | ||
print(mem[0]) | ||
(*mem,) = map(int, input.strip().split(",")) | ||
|
||
|
||
def simulate(a, b, mem): | ||
i = 0 | ||
mem[1] = a | ||
mem[2] = b | ||
while i < len(mem): | ||
if mem[i] == 99: | ||
break | ||
elif mem[i] == 1: | ||
mem[mem[i + 3]] = mem[mem[i + 1]] + mem[mem[i + 2]] | ||
elif mem[i] == 2: | ||
mem[mem[i + 3]] = mem[mem[i + 1]] * mem[mem[i + 2]] | ||
i += 4 | ||
return mem[0] | ||
|
||
|
||
print(*[a * 100 + b for a in range(100) for b in range(100) if simulate(a, b, mem[:]) == 19690720]) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from lib import * | ||
|
||
input = read_input(2019, 3) | ||
|
||
|
||
def parse_wire(wire): | ||
x = 0 | ||
y = 0 | ||
out = set() | ||
for e in wire.split(","): | ||
dx, dy = {"U": (0, -1), "D": (0, 1), "L": (-1, 0), "R": (1, 0)}[e[0]] | ||
for _ in range(int(e[1:])): | ||
x += dx | ||
y += dy | ||
out.add((x, y)) | ||
return out | ||
|
||
|
||
wire1, wire2 = map(parse_wire, input.splitlines()) | ||
print(min(abs(x) + abs(y) for x, y in (wire1 & wire2))) | ||
|
||
|
||
def parse_wire(wire): | ||
x = 0 | ||
y = 0 | ||
out = {} | ||
count = 0 | ||
for e in wire.split(","): | ||
dx, dy = {"U": (0, -1), "D": (0, 1), "L": (-1, 0), "R": (1, 0)}[e[0]] | ||
for _ in range(int(e[1:])): | ||
x += dx | ||
y += dy | ||
count += 1 | ||
if (x, y) not in out: | ||
out[(x, y)] = count | ||
return out | ||
|
||
|
||
wire1, wire2 = map(parse_wire, input.splitlines()) | ||
print(min(wire1[intersection] + wire2[intersection] for intersection in (wire1.keys() & wire2.keys()))) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from lib import * | ||
|
||
input = read_input(2019, 4) | ||
|
||
a, b = map(int, input.split("-")) | ||
count = 0 | ||
for i in range(a, b + 1): | ||
string = str(i) | ||
if list(string) != sorted(string): | ||
continue | ||
if any(x == y for x, y in zip(string[1:], string)): | ||
count += 1 | ||
print(count) | ||
|
||
|
||
a, b = map(int, input.split("-")) | ||
count = 0 | ||
for i in range(a, b + 1): | ||
string = str(i) | ||
if list(string) != sorted(string): | ||
continue | ||
if any(string.count(c) == 2 for c in string): | ||
count += 1 | ||
print(count) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from lib import * | ||
|
||
input = read_input(2019, 5) | ||
|
||
(*mem,) = map(int, input.split(",")) | ||
pc = 0 | ||
while pc < len(mem): | ||
opcode = mem[pc] % 100 | ||
mode1 = mem[pc] // 100 % 10 | ||
mode2 = mem[pc] // 1000 % 10 | ||
|
||
if opcode == 1: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
mem[mem[pc + 3]] = arg1 + arg2 | ||
pc += 4 | ||
elif opcode == 2: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
mem[mem[pc + 3]] = arg1 * arg2 | ||
pc += 4 | ||
elif opcode == 3: | ||
mem[mem[pc + 1]] = 1 | ||
pc += 2 | ||
elif opcode == 4: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
if arg1: | ||
print(arg1) | ||
pc += 2 | ||
elif opcode == 99: | ||
break | ||
|
||
|
||
(*mem,) = map(int, input.split(",")) | ||
pc = 0 | ||
while pc < len(mem): | ||
opcode = mem[pc] % 100 | ||
mode1 = mem[pc] // 100 % 10 | ||
mode2 = mem[pc] // 1000 % 10 | ||
|
||
if opcode == 1: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
mem[mem[pc + 3]] = arg1 + arg2 | ||
pc += 4 | ||
elif opcode == 2: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
mem[mem[pc + 3]] = arg1 * arg2 | ||
pc += 4 | ||
elif opcode == 3: | ||
mem[mem[pc + 1]] = 5 | ||
pc += 2 | ||
elif opcode == 4: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
print(arg1) | ||
pc += 2 | ||
elif opcode == 5: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
if arg1: | ||
pc = arg2 | ||
else: | ||
pc += 3 | ||
elif opcode == 6: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
if not arg1: | ||
pc = arg2 | ||
else: | ||
pc += 3 | ||
elif opcode == 7: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
mem[mem[pc + 3]] = int(arg1 < arg2) | ||
pc += 4 | ||
elif opcode == 8: | ||
arg1 = mem[pc + 1] if mode1 else mem[mem[pc + 1]] | ||
arg2 = mem[pc + 2] if mode2 else mem[mem[pc + 2]] | ||
mem[mem[pc + 3]] = int(arg1 == arg2) | ||
pc += 4 | ||
elif opcode == 99: | ||
break |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.