Skip to content

Instantly share code, notes, and snippets.

View agentfin's full-sized avatar

alexis finch agentfin

View GitHub Profile
@agentfin
agentfin / 9_4_psych_test.rb
Created January 29, 2012 22:04
Chris Pine PragProg 9.4
# First version with a bunch of excess variables
# direct from Mr. Pine
def ask question
good_answer = false
while (not good_answer)
puts question
reply = gets.chomp.downcase
if (reply == 'yes' or reply == 'no' )
@agentfin
agentfin / repo_man.rb
Created January 27, 2012 04:48
Nesting your method calls
# Repo Man
def thirsty_bitch
puts "get me another"
beer
end
def beer
puts "Red Stripe."
end
@agentfin
agentfin / contented_array.rb
Created December 21, 2011 05:15
Table of Content... CP
# table of contentssss
line_width = 40
puts ('Table of Contents'.center(line_width))
table = [
[1, 'Getting Started', 1],
[2, 'Numbers', 9],
[3, 'Letters', 13]
]
@agentfin
agentfin / alphebetizer.rb
Created December 21, 2011 04:53
Sorting my array [Chris Pine Ch 8]
# alphabetting
puts 'Tell us some of your favorite things!'
# create an array
words = []
puts words
while (thing = gets.chomp) != ''
words.push thing
@agentfin
agentfin / deaf_grandma.rb
Created December 14, 2011 14:19
Deaf Grandma from Chris Pine...
# deaf gramma
# so she says hi and stuff
puts 'MORNIN SONNY! HOW YOU DOIN\' TODAY?'
hwat = gets.chomp
# set a counter that tracks how many times you tell her to DIE
counter = 1
# tell her to shut the fuck up
while counter != 3
@agentfin
agentfin / branching_name_game.rb
Created December 14, 2011 14:15
Branching and while
# branching again
puts 'Hello, world.'
puts 'My name is Inigo Montoya. What\'s your name?'
name = gets.chomp
if name == name.capitalize
# be all kinds of sweet
puts 'I\'ve always loved the name ' + name + ','
puts '...but I\'m going to call you Pretty-Pretty.'
puts 'You\'re very pretty, Pretty-Pretty'.'
@agentfin
agentfin / 99_bottles.rb
Created December 14, 2011 14:08
Start from anywhere, 99bottles of beer song.
# 99 bottles of beer on the wall
# get a number of bottles
puts 'How many bottles do you have?'
bottles = gets.chomp.to_i
# set the loop to go til there are no more bottles
# we should be able to do this as an ".each do ||"
# but ruby has the hate today.
while bottles != 0
# get the song going
@agentfin
agentfin / leap_year.rb
Created December 14, 2011 14:06
Leap year checker, chapter 7 of Chris Pine
# Leap Years
# well, we need a year.
puts 'Pick a year any year!'
year = gets.chomp
# then we need to see if it is divisible by 4
# and not 100
# unless it's also divisible by 400
# could use % which is 'modulus' and divides the number but
@agentfin
agentfin / sassy_palindrome_checker.rb
Created October 11, 2011 16:06
Palindrome Checker
puts "Tell us a palindrome"
palindrome = gets.chomp
if palindrome == palindrome.reverse
puts "WOW! " + palindrome.upcase + " IS AN AWESOME PALINDROME!"
else
puts "Uhhh... " + palindrome.reverse.upcase + " ? Really? That is so not the same as " + palindrome.upcase + "."
end
@agentfin
agentfin / greed_koan.rb
Created August 2, 2011 14:10
Ruby Koans Greed solution or "about_scoring_project.rb"
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
# * A set of three numbers (other than ones) is worth 100 times the
# number. (e.g. three fives is 500 points).