Skip to content

Instantly share code, notes, and snippets.

Write a method mode which takes an Array of numbers
as its input and returns an Array of the most frequent values.
If there's only one most-frequent value, it returns a
single-element Array.
For example,
mode([1,2,3,3]) # => [3]
mode([4.5, 0, 0]) # => [0]
@mhriess
mhriess / gist:3452431
Created August 24, 2012 16:15
Reverse Polish Notation Calculator
Create an RPNCalculator class which can evaluate expressions
written in Reverse Polish notation.
It should have an evaluate instance method which takes as its
input a valid RPN expression and returns its evaluation. Your
calculator only needs to handle addition, multiplication, and
subtraction (not division).
Operators and numbers should be separated by a single space.
# Put your answers here!
Michael-Riess-Computer:~ michaelriess$ rvm list
rvm rubies
ruby-1.8.7-p302 [ i686 ]
ruby-1.9.2-p290 [ x86_64 ]
=* ruby-1.9.2-p318 [ x86_64 ]
ruby-1.9.2-p320 [ x86_64 ]
# Put your answers here!
Michael-Riess-Computer:sample_project michaelriess$ rvm list
rvm rubies
ruby-1.8.7-p302 [ i686 ]
ruby-1.9.2-p290 [ x86_64 ]
* ruby-1.9.2-p318 [ x86_64 ]
ruby-1.9.2-p320 [ x86_64 ]
@mhriess
mhriess / RPS_pseudocode.md
Created October 5, 2012 05:46
Rock-Paper-Scissors Pseudocode

Script: ROCK - PAPER - SCISSOR Iteration One: COMPUTERS HANDSIGN

RETURN a random hand sign (Rock-Paper-Scissor)

Iteration Two: CHECK WHO WON

IF COMPUTERS HANDSIGN beats PLAYERS HANDSIGN RETURN "You loose" ELSIF PLAYERS HANDSIGN beats COMPUTERS HANDSIGN RETURN "You win" ELSE RETURN "Draw" ENDIF

Iteration Three: GET A HANDSIGN OF A PLAYER

@mhriess
mhriess / rock_paper_scissors.rb
Created October 5, 2012 05:47
Rock-Paper-Scissors
CHOICES = ["Rock", "Paper", "Scissors"]
def player_choice
print "Enter your choice below:
>"
player_input = gets.chomp.capitalize
CHOICES.include?(player_input) ? player_input : player_choice
end
@mhriess
mhriess / RPS_bad.rb
Created October 5, 2012 05:48
Rock-Paper-Scissors bad
CHOICES = ["Rock", "Paper", "Scissors"]
def new_game
print %q"Let's play some Rock-Paper-Scissors!
Enter your choice below:
>"
outcome
end
@mhriess
mhriess / card.rb
Created October 18, 2012 19:11 — forked from dbc-challenges/card.rb
FlashCardinator
require 'csv'
require 'term/ansicolor'
# Use this trick to work around namespace cluttering that
# happens if you just include Term::ANSIColor:
class Color
extend Term::ANSIColor
end
require 'simplecov'
SimpleCov.start
require './binary_search.rb'
describe "#binary_search" do
let(:array_1) { [1,2,3,4,5,6,7] }
let(:array_2) { ["apple", "pear", "banana", "pineapple", "kiwi"].sort}
it "is defined as a method" do
@mhriess
mhriess / card.rb
Created October 25, 2012 04:38 — forked from dbc-challenges/card.rb
FlashCardinator
class Session
attr_reader :output_stream
def initialize(game, input_stream = $stdin, output_stream = $stdout)
@game = game
@input_stream = input_stream
@output_stream = output_stream
end