{{ message }}

Instantly share code, notes, and snippets.

# joshbduncan

Created Oct 2, 2020
View ansi-colors,sh
 #!/bin/bash # https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors # TEXT COLOR DEFAULT="\033[0m" BLACK="\033[30m" RED="\033[31m" GREEN="\033[32m" ORANGE="\033[33m"
Last active Dec 9, 2020
View aoc2020-day8.py
 from copy import deepcopy def solve(instructions): # setup vars to track acc = 0 pos = 0 visited = set()
Created Dec 9, 2020
View aoc2020-day9.py
 # read in aoc input data = open("day9.in").read().strip().split('\n') # setup vars to track pre = 25 pos = 25 # solve for part 1 while True: p1 = int(data[pos])
Created Dec 15, 2020
View aoc2020-day13.py
 # read in aoc input and setup to vars from instructions time = int(open("day13.in").read().strip().split()) buses = open("day13.in").read().strip().split().split(',') departures = {} # part 1 for bus in buses: if bus != 'x': bus_id = int(bus) # calculate closest departure to your time for each bus
Created Dec 28, 2020
View aoc2020-day15.py
 # read in aoc input data = open("day15.in").read().strip().split(',') def solve(match): # add starting numbers to dict for tracking pdict = {} for i, p in enumerate(data): pdict[int(p)] = [i + 1]
Created Dec 28, 2020
View aoc2020-day15-v2.py
 def solve(match): pdict = {} for i, p in enumerate(data): pdict[int(p)] = i + 1 turn = len(pdict) + 1 same = 0 while turn < match:
Created Dec 31, 2020
View aoc2020-day17.py
 def p1(active): for _ in range(6): new = set() xvals = [x for x in active] yvals = [y for y in active] zvals = [z for z in active] for x in range(min(xvals) - 1, max(xvals) + 2): for y in range(min(yvals) - 1, max(yvals) + 2): for z in range(min(zvals) - 1, max(zvals) + 2):
Created Jan 1, 2021
View aoc2020-day18.py
 def calc1(line): nums = [int(x) for x in line if x not in ['+', '*']] ops = [x for x in line if x in ['+', '*']] total = nums.pop(0) for n in nums: if ops == []: break else: total = eval(str(total) + ops.pop(0) + str(n))
Created Jan 23, 2021
View make_banner.py
 def make_banner(txt: str, padding: int = 5, border: str = '*') -> str: return ( f'{border * (len(txt) + padding * 2)}\n' f'{" " * padding}{txt}\n' f'{border * (len(txt) + padding * 2)}' ) banner = make_banner('Banner as a variable', 4, '#') print(banner)
Created Feb 1, 2021
View todoist-2-things.py
 import os import webbrowser from datetime import datetime from dotenv import load_dotenv from todoist.api import TodoistAPI load_dotenv() try: