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
| possibilities = %w(wed thur fri) | |
| (1..possibilities.size).reduce([]) do |accumulator, count| | |
| accumulator + possibilities.combination(count).to_a | |
| end | |
| # => [["wed"], ["thur"], ["fri"], ["wed", "thur"], ["wed", "fri"], ["thur", "fri"], ["wed", "thur", "fri"]] |
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 | |
| # Dynamic Programming solution to "Tower Hoppers" problem. | |
| # Walk backwards through the towers, filling in the hash with a true/false flag | |
| # if that position is hoppable or not. | |
| def hoppable_dp?(towers) | |
| hash = {} # index in towers, and if it's hoppable or not. | |
| idx = towers.size - 1 |
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 | |
| # Fibonacci - sum of previous 2 numbers, where 1 & 2 = 1. | |
| # Recursive | |
| def fib_r(n) | |
| return 1 if n == 1 || n == 2 | |
| fib_r(n - 1) + fib_r(n - 2) | |
| 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
| // This was just an fun project from some years ago, where we attempted to | |
| // determine the efficiency (CFM) of a house celling fan by creating a bag | |
| // vacum around the fan, and then timing how long it took for the bag to | |
| // completely deflate. | |
| // | |
| // An arduino system performed the timing with a sensor being depressed | |
| // upon the collapse of the bag to stop the experiment. | |
| // | |
| // Code is C for Ardunio. |
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
| package main | |
| import "fmt" | |
| // Fizzbuzz: | |
| // Write a program that prints the numbers from 1 to 100. | |
| // But for multiples of three print "Fizz" instead of the number and for the | |
| // multiples of five print "Buzz". For numbers which are multiples of both | |
| // three and five print "FizzBuzz". | |
| func main() { |
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
| # Performs a ranged BITCOUNT based on start + finish as BITS | |
| # instead of BYTES like Redis's BITCOUNT does. Pass in ints. | |
| # index starts from zero. start + finish are inclusive. | |
| # | |
| # Works by fetching the byte bit count and fetching the lower and | |
| # upper bytes of the range, then removing any set bits in those bytes | |
| # that are outside of the counting range if set. | |
| # | |
| # usage: | |
| # count = real_bitcount("mykey", 20, 30) |
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
| # A shoulda macro for verifying a class has the writer attribute readers, | |
| # writers and accessors. NOTE: I could be silly for wanting this. But it was | |
| # there. So here it is. | |
| # | |
| # (c) Copyright 2009 Adam Keys. MIT license. | |
| module AccessorMacros | |
| def should_have_reader(name) | |
| should "have an attribute reader for #{name.to_s}" do |