This file contains hidden or 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
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/11 | |
INPUT = "hepxcrrq" | |
THREE_LETTER_RUN = Regexp.union(("a".."z").each_cons(3).map(&:join)) | |
ILLEGAL_LETTER = /[iol]/ | |
def unique_pairs(s) |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/10 | |
INPUT = "1113222113" | |
def look_and_say(s) | |
s.gsub(/(.)\1*/) do | |
"#{$&.size}#{$1}" | |
end |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/9 | |
require "set" | |
class Map | |
attr_reader :cities |
This file contains hidden or 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
r/bin/env ruby | |
# http://adventofcode.com/day/8 | |
class Literal | |
def initialize(line) | |
@s = line.chomp | |
end |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/7 | |
class Operation | |
attr_reader :source | |
def initialize(source:, inputs:, opcode:, output:) | |
@source = source |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "digest/md5" | |
# http://adventofcode.com/day/4 | |
INPUT = "yzbqklnj" | |
def find(regex) | |
loop.with_index do |_, i| |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# http://adventofcode.com/day/3 | |
require "set" | |
class Visits | |
def initialize | |
@locations = Set.new |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Advent of code, day 1 | |
# http://adventofcode.com/day/2 | |
input = File.read("input") | |
floors = Enumerator.new do |yielder| | |
floor = 0 | |
input.chars.each do |c| | |
floor += case c |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Advent of code, day 2 | |
# http://adventofcode.com/day/2 | |
class Box | |
def self.from_input(line) | |
dims = line.split("x").map do |s| | |
Integer(s) |
This file contains hidden or 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
gem "activerecord", "4.2.5" | |
# Given that I am using the sqlserver adapter | |
gem "activerecord-sqlserver-adapter", "~> 4.2.5" | |
require "active_record" | |
# And the model is defined before establishing a connection | |
class DataStagePropertyAttributes < ActiveRecord::Base | |
self.table_name = "foo" |