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 AoC7 | |
attr_reader :weights, :child_map, :root_name | |
PATTERN = /^([a-z]+) \(([0-9]+)\)( -> ([a-z ,]+))?$/ | |
def initialize | |
lines = IO.read("./input7.txt").strip.split("\n") | |
@weights = {} | |
@child_map = {} | |
lines.each do |line| |
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 inputs(): | |
for line in open("./input4.txt"): | |
yield line.split() | |
def sort_string(s): | |
l = list(s) | |
l.sort() | |
return "".join(l) | |
def has_dupes(words): |
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
from itertools import cycle, islice | |
def coords(): | |
dirs = cycle([(1,0), (0,1), (-1,0), (0, -1)]) | |
(dx, dy) = next(dirs) | |
yield (0,0) | |
minx = miny = maxx = maxy = 0 | |
x = y = 0 | |
while True: | |
(x,y) = (x + dx, y + dy) |
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
defmodule AoC3 do | |
def coord_stream do | |
directions = [{1,0}, {0,1}, {-1,0}, {0, -1}] | |
Stream.unfold({{0,0}, {0,0,0,0}, directions}, | |
fn {{x,y}, {minx, miny, maxx, maxy}, dirs = [{dx,dy} | rest]} -> | |
{x_,y_} = {x+dx, y+dy} | |
{minx, miny, maxx, maxy, dirs} = | |
if (x_ > maxx) || (x_< minx) || (y_ > maxy) || (y_ < miny) do | |
{min(minx, x_), min(miny, y_), max(maxx, x_), max(maxy, y_), rest ++ [{dx,dy}]} | |
else |
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
filetype on | |
filetype off | |
execute pathogen#infect() | |
syntax on | |
filetype plugin indent on | |
" ruby-friendly tab defaults | |
set tabstop=2 | |
set smarttab | |
set shiftwidth=2 |
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
var fs = require("fs"); | |
var express = require("express"); | |
var jsdom = require("jsdom"); | |
var serializeDocument = require("jsdom").serializeDocument; | |
var elmSrc = fs.readFileSync("./elm.js"); // Elm program with Main module and signalInit port | |
var html = ` | |
<!DOCTYPE html> | |
<html> |
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
module BatchesRandomStart | |
# `find_in_batches`, but starting from a random position in the set of | |
# records, then continuing from the beginning of the set. Give up early | |
# if `time_limit` elapses. | |
def find_in_batches_random_start(batch_size: 10, time_limit: nil) | |
relation = scoped | |
c = relation.count | |
return if c == 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
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' |
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
filetype on | |
filetype off | |
execute pathogen#infect() | |
syntax on | |
filetype plugin indent on | |
" ruby-friendly tab defaults | |
set tabstop=2 | |
set smarttab | |
set shiftwidth=2 |
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
if has("gui_macvim") | |
macmenu &File.New\ Tab key=<nop> | |
map <D-t> :CtrlP<CR> | |
endif |
NewerOlder