Skip to content

Instantly share code, notes, and snippets.

@MttWld
MttWld / Greed
Created May 29, 2013 14:56
Ruby Koans Greed Dice Game
points = 0
points = 0
(1..6).each do |num|
if dice.count(num) >= 3
points += num == 1? 1000 : num * 100
end
end
one_count = dice.count(1)
@MttWld
MttWld / prime_sieve
Created May 20, 2013 21:31
models the Sieve of Eratosthenes to find all the prime numbers up to and including a given number max.
def sieve(max)
set = (2..max).to_a
start_time = Time.now
set.each_with_index do |number, index|
(set-[number]).each_with_index do |number_to_check, index_to_check|
set.delete(number_to_check) if (number_to_check % number) == 0
end
end
end_time= Time.now
p set
@MttWld
MttWld / CoughDrops
Created May 7, 2013 01:22
models a pack of Halls cough drops
class CoughDrops
attr_accessor :drops
@@messages = []
File.readlines('messages.txt').each {|line| @@messages << line.chomp}
def initialize
@drops = ["A Pep Talk in Every Drop"]
until @drops.length == 10