Skip to content

Instantly share code, notes, and snippets.

View rendyanthony's full-sized avatar

Rendy Anthony rendyanthony

  • Singapore
View GitHub Profile
@rendyanthony
rendyanthony / Install_ADE_on_Fedora.md
Last active April 27, 2024 16:43
Install Adobe Digital Editions (ADE) and Calibre DeDRM on Fedora
@rendyanthony
rendyanthony / AoC2020_day17.py
Created December 28, 2020 06:43
Advent of Code 2020 Day 17
def build(initial, dim_sz=3):
cubes = {}
for y, line in enumerate(initial):
for x, state in enumerate(line):
cubes[(x, y, 0, 0)] = state
fill(cubes, dim_sz=dim_sz)
return cubes
def should_flip(cubes, pos, dim_sz=3):
DW_MOV = (0,) if dim_sz == 3 else (-1, 0, 1)
@rendyanthony
rendyanthony / AoC2020_day25.py
Last active December 28, 2020 03:41
Advent of Code 2020 Day 25
def get_loops(*search, max_iter=10000000):
value = 1
n = 1
while search and n <= max_iter:
value = (value * 7) % 20201227
if value in search:
yield (value, n)
n += 1
## Part 1
@rendyanthony
rendyanthony / AoC2020_day24.py
Last active December 24, 2020 07:27
Advent of Code 2020 Day 24
from io import StringIO
def parse(line):
fp = StringIO(line)
while True:
d1 = fp.read(1)
if not d1:
break
if d1 in ('s', 'n'):
@rendyanthony
rendyanthony / AoC2020_day23.py
Created December 24, 2020 03:22
Advent of Code 2020 Day 23
def crab_cups(cycle, n=10):
cur_val = cycle[0]
max_val = max(cycle)
cycle_dict = dict(zip(cycle, cycle[1:]))
cycle_dict[cycle[-1]] = cycle[0]
def pick_up(n=3):
pick = [cycle_dict[cur_val]]
for _ in range(n-1):
@rendyanthony
rendyanthony / AoC2020_day21.py
Last active December 21, 2020 10:29
Advent of Code 2020 Day 21
from functools import reduce
import re
def get_allergens(input):
ingredient_list = []
allergen_map = {}
for line in input:
m = re.match("^([\w\s]+) \(contains ([\w\s,]+)\)$", line).groups()
@rendyanthony
rendyanthony / AoC2020_day14.py
Last active December 14, 2020 07:05
Advent of Code 2020 Day 14
import re
## Part 1
def day14_p1(program):
mask = None
mem = {}
for line in program:
lh, rh = line.split(" = ")
if lh == "mask":
@rendyanthony
rendyanthony / AoC2020_day11_p2.py
Created December 12, 2020 07:37
Advent of Code Day 11 (Part 2)
import copy
def num_adj_occupied_2(x, y, in_array):
num = 0
dim_x, dim_y = len(in_array[0]), len(in_array)
for ym in (-1, 0, 1):
for xm in (-1, 0, 1):
if ym == 0 and xm == 0: continue
xp, yp = x+xm, y+ym
@rendyanthony
rendyanthony / AoC2020_day12_p2.py
Last active December 12, 2020 10:25
Advent of Code Day 12 (Part 2)
COMPASS = {
"E": (+1, 0),
"S": (0, +1),
"W": (-1, 0),
"N": (0, -1)
}
ship_pos = [0, 0]
waypoint = [10, -1]
@rendyanthony
rendyanthony / AoC2020_day12_p1.py
Created December 12, 2020 07:20
Advent of Code Day 12 (Part 1)
COMPASS = {
"E": (+1, 0),
"S": (0, +1),
"W": (-1, 0),
"N": (0, -1)
}
ship_pos = [0, 0]
ship_heading = 0