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
void init_lcd(); | |
void set_xy(char row, char col, char chip); | |
void draw_sprite(const char const *sprite, char chip); | |
void asm_helpers(); | |
const char CS2 = 0x10; | |
const char CS1 = 0x08; | |
const char arrow[8] = { | |
0b00010000, | |
0b00100000, |
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
import re | |
class Bot: | |
def __init__(self, group, low, high): | |
self._queue = [] | |
self._low_target = low | |
self._high_target = high | |
self._group = group |
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
import re | |
from functools import * | |
def read_file(filename): | |
with open(filename) as f: | |
return f.readline() | |
def decompressed_string(str, version=1): |
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
import io, re | |
def read_instructions(filename): | |
file = io.open(filename) | |
rect_pat = re.compile('rect (\d+)x(\d+)') | |
row_pat = re.compile('rotate row y=(\d+) by (\d+)') | |
col_pat = re.compile('rotate column x=(\d+) by (\d+)') | |
instructions = [] |
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
def flipx(arr) | |
arr.map(&:dup).reverse | |
end | |
def flipy(arr) | |
arr.map(&:reverse) | |
end | |
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
class Particle | |
attr_reader :num | |
def initialize(line, num) | |
@num = num | |
if line =~ /p=<(.*?),(.*?),(.*?)>, v=<(.*?),(.*?),(.*?)>, a=<(.*?),(.*?),(.*?)>/ | |
@px=$1.to_i | |
@py=$2.to_i | |
@pz=$3.to_i |
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
layers = {} | |
File.open('day13.txt') do |f| | |
f.each do |line| | |
if line =~ /(\d+): (\d+)/ | |
depth, range = $1.to_i, $2.to_i | |
layers[depth] = range | |
end | |
end | |
end |
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
pipes = {} | |
File.open('day12.txt') do |f| | |
f.each do |line| | |
if line =~ /(\d+) <-> (.*)/ | |
prog1 = $1.to_i | |
$2.split(', ').map(&:to_i).each do |prog2| | |
pipes[prog1] ||= [] | |
pipes[prog2] ||= [] | |
pipes[prog1] << prog2 | |
pipes[prog2] << prog1 |
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
dirs = { | |
'n' => [0, 1, -1], | |
's' => [0, -1, 1], | |
'ne' => [1, 0, -1], | |
'sw' => [-1, 0, 1], | |
'nw' => [-1, 1, 0], | |
'se' => [1, -1, 0] | |
} |
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
lengths = [187,254,0,81,169,219,1,190,19,102,255,56,46,32,2,216] | |
arr = (0..255).to_a | |
pos = 0 | |
def twist(arr, pos, len, skip) | |
arr = arr.dup | |
pos.times { arr.push(arr.shift) } | |
first, rest = if len > 0 | |
[arr[0..len-1], arr[len..arr.size]] | |
else |