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

Started #512

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cf17a96
Ask and 1st numerals excercises
DagmaraSz Sep 12, 2016
5537952
CH9: roman numerals
DagmaraSz Sep 13, 2016
b73819c
sorting
DagmaraSz Sep 13, 2016
45fdfb1
Fixed sorting
DagmaraSz Sep 13, 2016
456ac7b
everyday I'm shufflin
DagmaraSz Sep 13, 2016
49db7d9
reshuffled a bit more
DagmaraSz Sep 13, 2016
5e5b1c0
super large english number translator added
DagmaraSz Sep 14, 2016
c4a929f
Counting bottles
DagmaraSz Sep 14, 2016
56c22ab
Reading and writing
DagmaraSz Sep 14, 2016
35a8571
files for testing read/write
DagmaraSz Sep 14, 2016
4edad43
time stuff
DagmaraSz Sep 14, 2016
672ec51
Party like a Roman
DagmaraSz Sep 14, 2016
064d81b
Birthdays calculated
DagmaraSz Sep 14, 2016
ecfb15a
Adding the birthday list file
DagmaraSz Sep 14, 2016
e442b92
Debbugging roman numerals
DagmaraSz Sep 15, 2016
b1fbd17
extending Integer
DagmaraSz Sep 15, 2016
f406e4f
Growing oranges
DagmaraSz Sep 15, 2016
6862021
A dragon is born
DagmaraSz Sep 15, 2016
79a1d01
Fixed oranges; better profiling
DagmaraSz Sep 15, 2016
e61f6b2
Clock and logger
DagmaraSz Sep 15, 2016
f8b10e8
Fixes
DagmaraSz Sep 15, 2016
4881c83
Better logger
DagmaraSz Sep 15, 2016
8d2fca6
Ch14 tweaks
DagmaraSz Sep 15, 2016
4d22563
Added in loggers
DagmaraSz Sep 15, 2016
b29a017
Tweaks to match spec
DagmaraSz Sep 15, 2016
c87a711
Orange problems...
DagmaraSz Sep 15, 2016
8c56dcc
More orange tweaking
DagmaraSz Sep 15, 2016
7876db2
Oranges: take 1mln.
DagmaraSz Sep 15, 2016
cecccea
Oranges: take 1mln and 1.
DagmaraSz Sep 15, 2016
20761f5
Oranges: take 1mln and 2.
DagmaraSz Sep 15, 2016
06d064e
Oranges: take 1mln and 3.
DagmaraSz Sep 15, 2016
04404c6
Oranges: take 1mln and 4.
DagmaraSz Sep 15, 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
32 changes: 30 additions & 2 deletions ch09-writing-your-own-methods/ask.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
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?'
ask 'Do you like eating burritos?'
wets_bed = ask 'Do you wet the bed?'
ask 'Do you like eating chimichangas?'
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
52 changes: 50 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,51 @@
def old_roman_numeral num
# your code here
end

if num <= 0
return '>0 only please!'
end

#this will be our roman numeral string:
roman_numeral = ''

# deal with 1000s
thousands = num/1000
if thousands > 0
roman_numeral = 'M'*thousands
num = num - thousands*1000
end

#deal wih 100s
hundreds = num/100
if hundreds >= 5
roman_numeral = roman_numeral + 'D' + 'C'*(hundreds-5)
elsif hundreds > 0
roman_numeral = roman_numeral + 'C'*hundreds
end
num = num - hundreds*100

#deal wih 10s
tens = num/10
if tens >= 5
roman_numeral = roman_numeral + 'L' + 'X'*(tens-5)
elsif tens > 0
roman_numeral = roman_numeral + 'X'*tens
end
num = num - tens*10

#deal wih 1s
if num >= 5
roman_numeral = roman_numeral + 'V' + 'I'*(num-5)
elsif num > 0
roman_numeral = roman_numeral + 'I'*num
end

return roman_numeral

end

puts 'Translation:'
puts '3541 is ' + old_roman_numeral(3541)
puts '0 is '+ old_roman_numeral(0)
puts '-123 is ' + old_roman_numeral(-123)
puts '2077 is ' + old_roman_numeral(2077)
puts '2005 is ' + old_roman_numeral(2005)
62 changes: 60 additions & 2 deletions ch09-writing-your-own-methods/roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
def roman_numeral num
# your code here
end
if num <= 0
return '>0 only please!'
end

#this will be our roman numeral string:
roman_numeral = ''

# deal with 1000s
thousands = num/1000
if thousands > 0
roman_numeral = 'M'*thousands
num = num - thousands*1000
end

#deal wih 100s
hundreds = num/100
if hundreds == 9
roman_numeral = roman_numeral + 'CM'
elsif hundreds >= 5
roman_numeral = roman_numeral + 'D' + 'C'*(hundreds-5)
elsif hundreds == 4
roman_numeral = roman_numeral + 'CD'
elsif hundreds > 0
roman_numeral = roman_numeral + 'C'*hundreds
end
num = num - hundreds*100

#deal wih 10s
tens = num/10
if tens == 9
roman_numeral = roman_numeral + 'XC'
elsif tens >= 5
roman_numeral = roman_numeral + 'L' + 'X'*(tens-5)
elsif tens == 4
roman_numeral = roman_numeral + 'XL'
elsif tens > 0
roman_numeral = roman_numeral + 'X'*tens
end
num = num - tens*10

#deal wih 1s
if num == 9
roman_numeral = roman_numeral + 'IX'
elsif num >= 5
roman_numeral = roman_numeral + 'V' + 'I'*(num-5)
elsif num == 4
roman_numeral = roman_numeral + 'IV'
elsif num > 0
roman_numeral = roman_numeral + 'I'*num
end

return roman_numeral
end

puts 'Translation:'
puts '3541 is ' + roman_numeral(3541)
puts '0 is '+ roman_numeral(0)
puts '-123 is ' + roman_numeral(-123)
puts '2077 is ' + roman_numeral(2077)
puts '2005 is ' + roman_numeral(2005)
Binary file added ch10-nothing-new/aga.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 30 additions & 2 deletions ch10-nothing-new/dictionary_sort.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
def dictionary_sort arr
# your code here
end
recursive_sort arr, []
end

#the method that actually does sorting
def recursive_sort unsorted_array, sorted_array
j = 1

smallest_index = 0

until unsorted_array.length == 0

# find smallest in unsorted_array
while j < unsorted_array.length
smallest_index = j if unsorted_array[j].to_s.downcase < unsorted_array[smallest_index].to_s.downcase
j += 1
end

# move it from the unsorted array to the end of already_sorted
sorted_array << unsorted_array[smallest_index]
unsorted_array.delete_at(smallest_index)

# find next smallest with recursive call
recursive_sort unsorted_array, sorted_array
end

return sorted_array
end

puts dictionary_sort ["avada", "Kedavra", "black", "SirIUs", "harry"]
puts dictionary_sort ["A","feel", "can", "like", "can","singing"]
108 changes: 107 additions & 1 deletion ch10-nothing-new/english_number.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
def english_number number
# your code here

if number < 0
return 'Please enter a number that isn\'t negative.'
end

if number == 0
return 'zero'
end

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']
higher_powers = ['thousand','million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion',
'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion', 'quindecillion',
'sedecillion', 'septendecillion', 'octodecillion', 'novendecillion', 'vigintillion']

# "left" is how much of the number we still have left to write out.
# "write" is the part we are writing out right now.
left = number
write = 0

#deal with thousands up to vigintillions
#start from vigintillion and go down to find the lowest power when write is not 0
power = 63
i = 20

until power == 0
ten_power = 10**power
write = left/ten_power
left = left - write*ten_power
if write > 0
illions = english_number write
num_string = num_string + illions + ' ' + higher_powers[i]
if left > 0
# Add space between thousands and hundreds
num_string = num_string + ' '
end
end
power -= 3
i -= 1
end

#deal with hundreds
write = left/100 # How many hundreds left?
left = left - write*100 # Subtract off those hundreds.
if write > 0
# Now here's the recursion:
hundreds = english_number write
num_string = num_string + hundreds + ' hundred'
if left > 0
# So we don't write 'two hundredfifty-one'...
num_string = num_string + ' '
end
end

#deal with tens
write = left/10
left = left - write*10
if write > 0
#teenagers
if ((write == 1) and (left > 0))
num_string = num_string + teenagers[left-1]
# The "-1" is because teenagers[3] is 'fourteen', not 'thirteen'.
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
# Add space between tens and ones
num_string = num_string + '-'
end
end

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

# TA DA!
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(10000)
puts english_number(999999)
puts english_number(1100458)
puts english_number(1000000000000)
puts english_number(10**63 + 10**60 + 10**24 + 10*6 + 1215)

Binary file added ch10-nothing-new/jacqui.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading