Skip to content

Instantly share code, notes, and snippets.

View unbibium's full-sized avatar

Nick Bensema unbibium

View GitHub Profile
@unbibium
unbibium / aoc2022d3.bas
Last active December 4, 2022 15:58
Advent of Code 2022, day 3, CBM BASIC, optimized
;/Users/nickb/Downloads/aoc03.prg ==0801==
100 rem *** advent of code ***
110 rem *** december 3, 2022 ***
130 rem
140 rem adventofcode.com/2022/day/3
150 rem
151 rem by nick bensema
152 rem unbibium.github.io
@unbibium
unbibium / bits.py
Created December 16, 2021 17:04
AoC 2021 day 16: BITS interpreter
#!/usr/bin/env python3
import sys, os,math
from collections import deque
class Bitstream:
def __init__(self, hexstring, length=math.inf):
# length only controls when EOF flag is set
self.chars = deque(hexstring)
@unbibium
unbibium / day15.py
Created December 16, 2021 03:56
faulty 2021 day 15
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/15
import sys, os,math
from collections import deque
class Maze:
def __init__(self, lines, size=1):
self.size = size
@unbibium
unbibium / day14.py
Created December 14, 2021 14:21
AoC day 14: polymer, another exponential growth one
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/14
import sys, os,math
from collections import deque, defaultdict
def to_pairs(template):
result = defaultdict(int)
for i in range(len(template)-1):
@unbibium
unbibium / day12.py
Last active December 12, 2021 15:00
AoC 2021 day 12: path finding
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/12
import sys, os,math
from collections import defaultdict
def walk(routes, path, double=None):
for dst in routes[path[-1]]:
if dst == 'end':
@unbibium
unbibium / crabhelp.py
Created December 7, 2021 13:46
AoC 2021 day 7: helping carbs conserve fuel
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/7
def pascal(distance):
if distance<0: return pascal(-distance)
if distance<2: return distance
return (distance*(distance+1))//2
def move_all(xs, destination, func=abs):
@unbibium
unbibium / aoc2021d6b.py
Created December 6, 2021 06:25
AoC 2021 day 6: lanternfish, using deque instead of dict
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/6
from collections import deque
class School:
def __init__(self, allfish, spawntime=7, firstspawntime=8):
if type(allfish) is str: # assume filename
with open(allfish) as fi:
@unbibium
unbibium / aoc2021d6.py
Last active December 6, 2021 06:27
AoC 2021 day 6: lanternfish
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/6
from collections import defaultdict
class School:
def __init__(self, allfish, spawntime=7, firstspawntime=8):
if type(allfish) is str: # assume filename
with open(allfish) as fi:
@unbibium
unbibium / aoc2021d5.py
Created December 5, 2021 15:08
AoC 2021 day 5
#!/usr/bin/env python3
#
# https://adventofcode.com/2021/day/5
def walk(start,end):
if (start > end):
return range(start,end-1,-1)
return range(start,end+1)
class Segment:
@unbibium
unbibium / recursive22.py
Created December 22, 2020 22:51
AoC 2020 day 22 part 2 solution that still works if you add a third player
#!/usr/bin/env python3
print("22: recursive combat")
# I tried to program this without admitting that there
# are only two players.
import sys, os,math
from collections import deque, defaultdict