This file contains 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
# Poker | |
require_relative "PokerHand.rb" | |
class Deck | |
@@CLASSIC_DECK = ['2d','3d','4d','5d','6d','7d','8d','9d','Td','Jd','Qd','Kd','Ad'] + | |
['2h','3h','4h','5h','6h','7h','8h','9h','Th','Jh','Qh','Kh','Ah'] + | |
['2s','3s','4s','5s','6s','7s','8s','9s','Ts','Js','Qs','Ks','As'] + | |
['2c','3c','4c','5c','6c','7c','8c','9c','Tc','Jc','Qc','Kc','Ac'] |
This file contains 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
class PokerHand | |
attr_reader :hand, :score | |
def initialize (hand) | |
@hand = hand | |
@straight = @flush = @full_house = @quad = @triple = @two_pair = @pair = false | |
@score = 0 | |
end | |
def evaluate | |
hands = @hand.scan(/[cdsh]/) # Creates array for suits |
This file contains 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
def sum ( *args ) | |
args.length > 1 ? args.pop + sum(*args) : args.pop | |
end | |
test_array = [1,2,3,4] | |
puts sum(1,2) # ==> 3 | |
puts sum(*test_array) # ==> 10 |
This file contains 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
def flatten(array) | |
return Array(array) unless array.is_a?(Array) && array.length > 0 | |
flatten(array.shift) + flatten(array) | |
end | |
array = ["bananas", [1,2,3], ["apple", "cheese", [100, 20]], [true], [4.0, 7, 32]] | |
puts flatten(array).to_s | |
array = ["bananas"] |
This file contains 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
def flatten(array) | |
return nil unless array.is_a?(Array) | |
array.each do |item| | |
if item.is_a?(Array) | |
flatten(item).reverse_each do |inner_item| | |
#add to array at index of item | |
array.insert(array.index(item)+1, inner_item) | |
end | |
#remove pre-existing array | |
array.delete(item) |
This file contains 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
def roman input | |
if input < 0 || input >= 10000 | |
'Out of bounds' | |
elsif input >= 1000 && input < 10000 | |
'M' * (input / 1000) + roman(input % 1000) | |
elsif input >=900 && input < 1000 | |
'CM' + roman(input-900) | |
elsif input >= 500 && input < 900 | |
'D' + roman(input-500) | |
elsif input >= 400 && input < 500 |
NewerOlder