Instantly share code, notes, and snippets.

# Colin KelleyColinDKelley

• Sort options
Last active May 25, 2017
View gist:b936217351450310118533176f19fa62
 Race 5 horses. Take the fastest 3 and race them against 2 chosen from the remainder. Repeat until there are are no remaining. The final 3 from the last race are the fastest of the group. races = 1 + (25 - 5)/2 = 11
Last active Sep 13, 2016
View three_gods.md

# Solution to Three Gods Logic Puzzle

1. Ask god A: "Would the other non-random god answer 'Ja' to the question 'Does the random god sit to your left1?'"

=> If the answer is 'Ja', then it's false (or random), therefore NonRandom1 = C; else it's true (or random), therefore NonRandom1 = B

1. Ask gods[NonRandom1]: "Would the other non-random god answer 'Ja' to the question 'Does the random god sit to your left1?"
Last active Dec 25, 2015
prisoner hat riddle
View prisoner_hat.md

The tallest prisoner counts the white hats in front of him. If odd, he calls out "white"; if even he calls out "black".

Then each prisoner down the line makes the same calculation. If the color they compute is different from what was called out before them, they know their color is "white"; if it's the same, their color is "black". They call out their color.

# Reasoning

Created Mar 9, 2015
View meltdown.rb
 tiles = {} STDIN.readlines.map.with_index do |line, y| x = 0 line.chomp.split(".").each do |segment| unless segment.empty? tile = [x, segment.size, segment[0]] if value = tiles[tile] tiles[tile] = [value.first, value.last + 1] else
Last active Aug 29, 2015
retry_on_exception
View example_usage.rb
 result = retry_on_exception(Timeout::Error, total_tries: 2) do http_fe.post(...) end
Created Aug 15, 2014
Fig leaf to intercept parse with American date formats like 03/04/05
View parse_fig_leaf.rb
 module ParseFigLeaf def parse(*args) arg0 = args.first arg0.is_a?(String) && arg0 =~ /\A\d\d[-\/]\d\d[-\/]\d\d/ and raise "Ambiguous parse format in #{arg0.inspect}" super end end class << Date prepend ParseFigLeaf
Created Aug 15, 2014
View new_mysql2_improvements.rb