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 |
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 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 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
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
# 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
# Create a dictionary of english words mapped to number values | |
# Take in a number | |
# Start with the largest value in the dictionary, see if the number is evenly divisible by it | |
# IF it is, then add that word to the method called on the number with the value of the word divided out | |
# Return the string | |
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
function parse_git_branch () { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
function today () { | |
today=$(date +"%m%d") | |
# Modify the line below to your local dropbox path from ~ | |
# Ex: /Users/Keith/Dropbox/Fireflies/Keith |
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
/* Here is your chance to take over Socrates! | |
Spend 10 minutes on each of the following hacks to the Socrates website. | |
Enter them in the console to make sure it works and then save | |
your results here. | |
Choose a new pair for each. Add your names to the section you complete. | |
*/ |
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
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css"> | |
<link rel="stylesheet" href="main.css"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900"> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css"> | |
</head> |
OlderNewer