Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #504

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
392adb1
CHapter 9 - Ask file modified to include return statement
alexanderwjrussell Sep 8, 2016
bb67619
CHapter 9 - Old Roman Numeral Converter Created
alexanderwjrussell Sep 8, 2016
6278084
CHapter 9 - New Roman Numeral Converter complete
alexanderwjrussell Sep 8, 2016
77da74e
CHapter 10 - Shuffle exercise complete (with help from the solutions)
alexanderwjrussell Sep 8, 2016
c84ea57
Chapter 10 - Sorting exercise complete (with help from the solution)
alexanderwjrussell Sep 8, 2016
f793330
Chapter 10 - Dictionary Sort complete (without aid from solutions, us…
alexanderwjrussell Sep 8, 2016
8e1c389
Chapter 10 - English Number Generator complete (with help from the so…
alexanderwjrussell Sep 8, 2016
c0839f3
CHapter 10 - Ninety-Nine Bottles of Beer complete (own solution with …
alexanderwjrussell Sep 8, 2016
25fdad7
CHapter 11 - Safer Picture Downloading, not complete. Struggled with …
alexanderwjrussell Sep 10, 2016
089a326
Chapter 11 - Built a PLaylist. Completed with aid from the solutions.
alexanderwjrussell Sep 10, 2016
71491bb
Chapter 11 - Build a Better Playlist. Completed using the solution an…
alexanderwjrussell Sep 10, 2016
015ef22
Chapter 12 - One Billion Seconds complete. Self worked.
alexanderwjrussell Sep 10, 2016
055331e
CHapter 12 - Happy Birthday Spanking completed. Self worked. Horrible…
alexanderwjrussell Sep 10, 2016
e715df8
Chapter 12 - Party Roman Numerals complete. Solution used and annotated
alexanderwjrussell Sep 10, 2016
035ed36
Chapter 12 - Birthday Helper completed. Solution used and annotated.
alexanderwjrussell Sep 10, 2016
b43272d
Chapter 13 - Extending Built in Classes complete. Roman numeral conve…
alexanderwjrussell Sep 10, 2016
6dc94d5
Chapter 13 - Orange Tree complete. Solution used to help with the ali…
alexanderwjrussell Sep 10, 2016
1ac1927
Chapter 13 - Interactive Baby Dragon complete. Solution used and anno…
alexanderwjrussell Sep 10, 2016
20518ed
Chapter 14 - Grandfather Clock complete. Self worked.
alexanderwjrussell Sep 10, 2016
0aa2dfd
Chapter 14 - Even Better Profiling complete. Modified the solution gi…
alexanderwjrussell Sep 11, 2016
fac85de
CHapter 14 - Program Logger complete. Solution modified to work with …
alexanderwjrussell Sep 11, 2016
ad4b7fd
Chapter 14 - Better Program Logger complete. Solution modiefied to wo…
alexanderwjrussell Sep 11, 2016
c6c0ce4
Fixes to pass the pull
alexanderwjrussell Sep 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions ch09-writing-your-own-methods/ask.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
def ask question
# your code here
end
while true
puts question
reply = gets.chomp.downcase
if (reply == 'yes' || reply == 'no')
if reply == 'yes'
return true
else
return false
end
else
puts 'Please answer "yes" or "no".'
end
end
end

puts 'Hello, and thank you for...'
puts
ask 'Do you like eating tacos?'
wets_bed = ask 'Do you wet the bed?'
ask 'Do you like eating sopapillas?'
puts 'Just a few more questions...'
ask 'Do you like drinking horchata?'
ask 'Do you like eating flautas?'
puts
puts 'DEBRIEFING:'
puts 'Thank you for...'
puts
puts wets_bed
13 changes: 11 additions & 2 deletions ch09-writing-your-own-methods/old_school_roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
def old_roman_numeral num
# your code here
end
roman_numeral = ""
roman_numeral = roman_numeral + "M" * (num / 1000)
roman_numeral = roman_numeral + "D" * (num % 1000 / 500)
roman_numeral = roman_numeral + "C" * (num % 500 / 100)
roman_numeral = roman_numeral + "L" * (num % 100 /50)
roman_numeral = roman_numeral + "X" * (num % 50 / 10)
roman_numeral = roman_numeral + "V" * (num % 10 / 5)
roman_numeral = roman_numeral + "I" * (num % 5 / 1)
end

puts old_roman_numeral(2456)
43 changes: 41 additions & 2 deletions ch09-writing-your-own-methods/roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
def roman_numeral num
# your code here
end
roman_numeral = ""

thousands = (num / 1000)
hundreds = (num % 1000 / 100)
tens = (num % 100 / 10)
singles = (num % 10 / 1)

roman_numeral = "M" * thousands

if hundreds == 9
roman_numeral = roman_numeral + "CM"
elsif hundreds == 4
roman_numeral = roman_numeral + "CD"
else
roman_numeral = roman_numeral + "D" * (num % 1000 / 500)
roman_numeral = roman_numeral + "C" * (num % 500 / 100)
end

if tens == 9
roman_numeral = roman_numeral + "XC"
elsif tens == 4
roman_numeral = roman_numeral + "XL"
else
roman_numeral = roman_numeral + "L" * (num % 100 / 50)
roman_numeral = roman_numeral + "X" * (num % 50 / 10)
end

if singles == 9
roman_numeral = roman_numeral + "IX"
elsif singles == 4
roman_numeral = roman_numeral + "IV"
else
roman_numeral = roman_numeral + "V" * (num % 10 / 5)
roman_numeral = roman_numeral + "I" * (num % 5 / 1)
end

roman_numeral

end

puts roman_numeral(2644)
26 changes: 23 additions & 3 deletions ch10-nothing-new/dictionary_sort.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
def dictionary_sort arr
# your code here
end
def dictionary_sort array
recursive_dictionary_sort array, []
end

def recursive_dictionary_sort unsorted, sorted
if unsorted.length <= 0
return sorted
end
smallest = unsorted.pop
still_unsorted = []
unsorted.each do |test_object|
if test_object.downcase < smallest.downcase
still_unsorted.push smallest
smallest = test_object
else
still_unsorted.push test_object
end
end
sorted.push smallest
recursive_dictionary_sort still_unsorted, sorted
end

puts(dictionary_sort(['can','feel','singing','Like','A','can']))
129 changes: 128 additions & 1 deletion ch10-nothing-new/english_number.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
def english_number number
# your code here
if number < 0 # No negative numbers.
return 'Please enter a number that isn\'t negative.'
end
if number == 0
return 'zero'
end

# No more special cases! No more returns!

num_string = '' # This is the string we will return.

ones_place = ['one', 'two', 'three',
'four', 'five', 'six',
'seven', 'eight', 'nine']

tens_place = ['ten', 'twenty', 'thirty',
'forty', 'fifty', 'sixty',
'seventy', 'eighty', 'ninety']


teenagers = ['eleven', 'twelve', 'thirteen',
'fourteen', 'fifteen', 'sixteen',
'seventeen', 'eighteen', 'nineteen']

zillions = [['hundred', 2],
['thousand', 3],
['million', 6],
['billion', 9],
['trillion', 12],
['quadrillion', 15],
['quintillion', 18],
['sextillion', 21],
['septillion', 24],
['octillion', 27],
['nonillion', 30],
['decillion', 33],
['undecillion', 36],
['duodecillion', 39],
['tredecillion', 42],
['quattuordecillion', 45],
['quindecillion', 48],
['sexdecillion', 51],
['septendecillion', 54],
['octodecillion', 57],
['novemdecillion', 60],
['vigintillion', 63],
['googol', 100]]

# "left" is how much of the number
# we still have left to write out.
# "write" is the part we are
# writing out right now.
# write and left...get it? :)
left = number

while zillions.length > 0
zil_pair = zillions.pop
zil_name = zil_pair[0]
zil_base = 10 ** zil_pair[1]
write = left/zil_base # How many zillions left?
left = left - write*zil_base # Subtract off those zillions.

if write > 0
# Now here's the recursion:
prefix = english_number write
num_string = num_string + prefix + ' ' + zil_name

if left > 0
# So we don't write 'two billionfifty-one'...
num_string = num_string + ' '
end
end
end

write = left/10 # How many tens left?
left = left - write*10 # Subtract off those tens.

if write > 0
if ((write == 1) and (left > 0))
# Since we can't write "tenty-two" instead of
# "twelve", we have to make a special exception
# for these.
num_string = num_string + teenagers[left-1]
# The "-1" is because teenagers[3] is
# 'fourteen', not 'thirteen'.

# Since we took care of the digit in the
# ones place already, we have nothing left to write.
left = 0
else
num_string = num_string + tens_place[write-1]
# The "-1" is because tens_place[3] is
# 'forty', not 'thirty'.
end

if left > 0
# So we don't write 'sixtyfour'...
num_string = num_string + '-'
end
end

write = left # How many ones left to write out?
left = 0 # Subtract off those ones.

if write > 0
num_string = num_string + ones_place[write-1]
# The "-1" is because ones_place[3] is
# 'four', not 'three'.
end

# Now we just return "num_string"...
num_string
end

# puts english_number( 0)
# puts english_number( 9)
# puts english_number( 10)
# puts english_number( 11)
# puts english_number( 17)
# puts english_number( 32)
# puts english_number( 88)
# puts english_number( 99)
# puts english_number(100)
# puts english_number(101)
# puts english_number(234)
# puts english_number(3211)
# puts english_number(999999)
# puts english_number(1000000000000)
# puts english_number(109238745102938560129834709285360238475982374561034)
80 changes: 79 additions & 1 deletion ch10-nothing-new/ninety_nine_bottles_of_beer.rb
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
# your code here
def englishNumber number

if number < 0
return "Please enter a number which isn't negative"
end
if number == 0
return "zero"
end

numString = ""

onesPlace = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
tensPlace = ["ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
teenPlace = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
hugeNumber = [["hundred", 2],["thousand", 3], ["million", 6], ["billion", 9], ["trillion", 12], ["quadrillion", 15]]

left = number

while hugeNumber.length > 0
hugeNumber_pair = hugeNumber.pop
hugeNumber_name = hugeNumber_pair[0]
hugeNumber_base = 10 ** hugeNumber_pair[1]
write = left / hugeNumber_base
left = left - write * hugeNumber_base

if write > 0
prefix = englishNumber write
numString = numString + prefix + "-" + hugeNumber_name
end

if left > 0
numString = numString + ""
end
end


write = left/10
left = left - write*10

if write > 0
if ((write == 1) and (left > 0))
numString = numString + teenPlace[left-1]
left = 0
else
numString = numString + tensPlace[write-1]
end

if left > 0
numString = numString + "-"
end
end

write = left
left = 0

if write > 0
numString = numString + onesPlace[write-1]
end

numString

end


bottle_starting_count = 10
bottle_count = bottle_starting_count
while bottle_count > 1
puts englishNumber(bottle_count).capitalize + " bottles of beer on the wall"
puts englishNumber(bottle_count).capitalize + " bottles of beer"
puts "You take 1 down, pass it around"
bottle_count = bottle_count - 1
puts englishNumber(bottle_count).capitalize + " bottles of beer on the wall"

end

puts "One bottle of beer on the wall"
puts "One bottle of beer"
puts "You take 1 down, pass it around"
puts "No more bottles of beer on the wall"
28 changes: 25 additions & 3 deletions ch10-nothing-new/shuffle.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
def shuffle arr
# your code here
end
def shuffle array
shuffled = []

while array.length > 0

random_index = rand(array.length)

current_index = 0
new_array = []

array.each do |index|
if current_index == random_index
shuffled.push index
else
new_array.push index
end
current_index = current_index + 1
end

array = new_array
end
shuffled
end

puts(shuffle(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]))
26 changes: 23 additions & 3 deletions ch10-nothing-new/sort.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
def sort arr
# your code here
end
def sort array
recursive_sort array, []
end

def recursive_sort unsorted, sorted
if unsorted.length <= 0
return sorted
end
smallest = unsorted.pop
still_unsorted = []
unsorted.each do |test_object|
if test_object < smallest
still_unsorted.push smallest
smallest = test_object
else
still_unsorted.push test_object
end
end
sorted.push smallest
recursive_sort still_unsorted, sorted
end

puts(sort(['can','feel','singing','like','a','can']))
Loading