Skip to content

Instantly share code, notes, and snippets.

View SleeplessByte's full-sized avatar
💎
💎 💎 💎

Derk-Jan Karrenbeld SleeplessByte

💎
💎 💎 💎
View GitHub Profile
@SleeplessByte
SleeplessByte / contributions.md
Last active May 14, 2021 17:23
Exercism contributions

I really don't like the notion where we look at commit counts (that's code style), line count (quantity/quality, and highly different per language) or even time investment (indication of efficiency, not effort), so I've only listed the projects and the additions and leave it up to managment to make some pragmatic choices for rewards.

This is a non-comprehensive list of things I think I contributed, which others can use as a basis for their own list.

Tooling I've written from scratch

@SleeplessByte
SleeplessByte / aoc-2020-d16.rb
Last active December 17, 2020 00:19
Advent of Code 2020: Day 16 - Ticket Translation
rules, yours, nearby = File.read('input.txt').split(/\n\n/)
def ticket_values(nearby)
nearby.split("\n")[1..]
end
def category_values(rules)
rules.split("\n").each_with_object({}) do |line, categories|
next if line.empty?
@SleeplessByte
SleeplessByte / aoc-2020-d15.rb
Created December 15, 2020 16:36
Advent of Code 2020: Day 15 - Rambunctious Recitation
numbers = File.read('input.txt').chomp.split(',').map(&:to_i)
turns = numbers.dup
memory = Hash.new { [] }
numbers.each_with_index do |number, turn|
memory[number] = [turn]
puts "Turn #{turn + 1}: #{number}"
end
@SleeplessByte
SleeplessByte / aoc-2020-d14.rb
Last active December 14, 2020 21:21
Advent of Code 2020: Day 14 - Docking Data
require 'benchmark'
def mask_rjust(value, mask)
value.to_s(2).rjust(mask.length, "0")
end
def mask_from_line(maskline)
mask = maskline.chomp.split('mask = ').last
add = mask.tr('01X', '010').to_i(2)
sub = mask.tr('01X', '011').to_i(2)
@SleeplessByte
SleeplessByte / aoc-2020-d13.rb
Created December 13, 2020 23:22
Advent of Code 2020: Day 13 - Shuttle Search
require 'prime'
require 'benchmark'
source = 'input.txt'
timestamp, schedule_line = File.readlines(source)
schedule = schedule_line.split(',').map { |x| x.chomp }
busses = schedule
.each_with_index
@SleeplessByte
SleeplessByte / aoc-2020-d12.rb
Last active December 12, 2020 11:08
Advent of Code 2020: Day 12 - Rain Risk
require 'benchmark'
class Ship
attr_reader :position
def initialize
self.facing = 90
self.position = Position.new(0, 0)
self.waypoint = Waypoint.new
@SleeplessByte
SleeplessByte / aoc-2020-d11.rb
Last active December 11, 2020 06:34
Advent of Code 2020: Day 11 - Seating System
require 'benchmark'
class Seat
def initialize(mark)
self.mark = mark
self.next_mark = mark
end
def valid?
mark != 'X'
@SleeplessByte
SleeplessByte / aoc-2020-d10.rb
Last active December 10, 2020 07:03
Advent of Code 2020: Day 10 - Adapter Array
require 'benchmark'
adapters = File.readlines('input.txt').map(&:to_i).sort
maximum_jolt = adapters.last + 3
adapters.push(maximum_jolt)
# Track the number of options to get to a target jolt value
# and default to 0. The first jolt value is 0, and can only
# be reached in one way.
options = Hash.new(0)
@SleeplessByte
SleeplessByte / aoc-2020-d9.rb
Last active December 9, 2020 06:20
Advent of Code 2020: Day 9 - Encoding Error
require 'benchmark'
def find_sum_of_uniques(candidates, check)
skip = check / 2.to_f
candidates.each do |x|
next if x == skip
candidates.each do |y|
next if y == skip
@SleeplessByte
SleeplessByte / aoc-2020-d8.rb
Created December 8, 2020 05:52
Advent of Code 2020: Day 8 - Handheld Halting
require 'benchmark'
class Instruction
attr_reader :operation, :argument
def self.fix(instruction)
new(instruction.operation == 'nop' ? 'jmp' : 'nop', instruction.argument)
end
def initialize(operation, argument)