Skip to content

Instantly share code, notes, and snippets.

View combinations.rb
def combos(items, k, s = 0, combo = [])
return [combo] if k == 0
(s .. items.size - k).flat_map do |i|
combos(items, k - 1, i + 1, combo + [items[i]])
end
end
combos([:a, :b, :c, :d, :e, :f], 3).each do |combo|
p combo
View rocket_fuel.rb
input_path = File.expand_path('../input.txt', __FILE__)
masses = File.read(input_path).lines.map(&:to_i)
def fuel(mass)
(mass / 3.0).floor - 2
end
p masses.reduce(0) { |s, m| s + fuel(m) }
def required_fuel(init)
View rust-types.md

Rust types reference

Prelude

  • std::borrow::ToOwned
  • std::boxed::Box
  • std::clone::Clone
  • std::cmp::{PartialEq, PartialOrd, Eq, Ord}
  • std::convert::{AsRef, AsMut, Into, From}
  • std::default::Default
View blame.rb
require_relative "./base"
require_relative "../diff"
require_relative "../rev_list"
module Command
class Blame < Base
def run
@lines = []
@commits = []
View call_monitor.rb
require "set"
mods = Class.ancestors +
Method.ancestors +
UnboundMethod.ancestors
reserved = %i[
==
===
=~
View maze.txt
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o---o o o---o o o o o o o o o o o o o o o o o o o o
| | | |
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o---o---
View git-log-times.sh
#!/bin/bash
cd ~/src
dir="git-long-uninteresting-branch"
git init $dir > /dev/null
cd $dir
export GIT_COMMITTER_DATE="1600000000"
View water.txt
.................................................................................................|...............................................................#....#..................
........#........................................................................................|...............................................................#....#..................
........#.............#..........................................................................|...............................................................#....#..................
........#.............#..........................................................................|...............................................................#....#..................
........#.............#..........................................................................|...#....#......................................................#....#..................
........#.............#.......................................................................
View numbers.rb
module Pack
module Numbers
module VarIntLE
def self.write(size, shift)
bytes = []
mask = 2 ** shift - 1
until size <= mask
bytes << (0x80 | size & mask)
View superpermutation.rb
class SuperPermutation
CHARS = ('a'..'z').map(&:to_sym)
def initialize(size)
@size = size
@chars = CHARS.take(@size)
@used = {}
@index = Hash.new { |h, k| h[k] = [] }
@chars.permutation.each do |seq|
You can’t perform that action at this time.