Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ea98acc
ask.rb reworked
glynester Sep 12, 2016
11effba
ask.rb commented out ext 'puts'
glynester Sep 12, 2016
efbf80c
old_school_roman_numerals.rb
glynester Sep 12, 2016
a81949c
roman_numerals.rb modern method
glynester Sep 12, 2016
5ff8f67
shuffle.rb
glynester Sep 12, 2016
31b2c13
sort.rb
glynester Sep 12, 2016
7dbe6e7
dictionary_sort.rb
glynester Sep 12, 2016
faa6145
english_number.rb
glynester Sep 12, 2016
cc98454
ninety_nine_bottles_of_beer.rb set to run 5 (five:) times
glynester Sep 12, 2016
5fc9975
ninety_nine_bottles_of_beer.rb Capitalised the first word. Added some…
glynester Sep 12, 2016
4bfd8b3
safer_picture_downloading.rb Couldn't get code to run. Included code …
glynester Sep 12, 2016
0eb9cc5
build_your_own_playlist.rb Not working. Ref = 'https://github.com/mak…
glynester Sep 12, 2016
d7d1941
playlist commit 14-09-2016
glynester Sep 14, 2016
2ba0ff3
Test
glynester Sep 22, 2016
cde027a
Happy birthday to you!
glynester Sep 22, 2016
bcafe2c
1 billions secs old.
glynester Sep 22, 2016
361bbc4
Amended to include (optional) entry of hours, mins and secs.
glynester Sep 22, 2016
f30a38b
Roman numerals to decimal conversion prog.
glynester Sep 22, 2016
3e18d28
1st draft of happy_birthday.rb.
glynester Sep 22, 2016
5f4ced6
birthday_helper.rb calculates next birthday and age on next birthday.
glynester Sep 22, 2016
31dd4ba
Amended array class to include shuffle method.
glynester Sep 22, 2016
d46cfce
Amended integer class to include factorial method.
glynester Sep 22, 2016
11bb47c
Added the 'roman' method to the Integer class.
glynester Sep 23, 2016
ea2261b
Profiling can be turned on and off now.
glynester Sep 23, 2016
4be6c7e
When called, clock 'dongs' according to the number of hours in the cu…
glynester Sep 23, 2016
9f28c66
Prog logger.
glynester Sep 23, 2016
a4187d9
'better_program_logger.rb' with double spacing for each sub level rea…
glynester Sep 23, 2016
9633bab
Interim orange tree. Does all but can't sponteously die yet!
glynester Sep 23, 2016
3712fe1
orange tree. Now the tree can sponteously die after the age of 20.
glynester Sep 23, 2016
1007d86
dragon prog enhanced to include user interface.
glynester Sep 23, 2016
d178d10
Tidied up the program.
glynester Sep 23, 2016
471865d
Amended to append "(duplicate)" onto a file that would be overwritten…
glynester Sep 23, 2016
0af680c
Playlist now works on my local machine.
glynester Sep 24, 2016
c22099a
Interim dev on shuffle method. It works but need to make it more rand…
glynester Sep 24, 2016
b6649a5
Shuffle method completed.
glynester Sep 24, 2016
1d0bdfb
test commit to see if this appears on http://hub.makersacademy.com/st…
glynester Sep 26, 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
36 changes: 34 additions & 2 deletions ch09-writing-your-own-methods/ask.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
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 #answer = true
else
return false #answer = false
end
break
else
puts 'Please answer "yes" or "no".'
end
end
answer # This is what we return (true or false).
end

=begin
puts 'Hello, and thank you for...'
puts
ask 'Do you like eating tacos?' # Ignore this return value
ask 'Do you like eating burritos?' # And this one
wets_bed = ask 'Do you wet the bed?' # Save this return value
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
=end
17 changes: 14 additions & 3 deletions ch09-writing-your-own-methods/old_school_roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
def old_roman_numeral num
# your code here
end
def old_roman_numeral num
# I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000
m = (num / 1000) #Integer division so produces 0 if no 1,000's.
d = ((num % 1000) / 500)
c = ((num % 500) / 100)
l = ((num % 100) / 50)
x = ((num % 50) / 10)
v = ((num % 10) / 5)
i = (num % 5)
"M"*m + "D"*d + "C"*c + "L"*l + "X"*x + "V"*v + "I"*i
end

#puts old_roman_numeral 3000
#puts old_roman_numeral 879
51 changes: 49 additions & 2 deletions ch09-writing-your-own-methods/roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
=begin
I placed before V or X indicates one less, so four is IV (one less than five) and nine is IX (one less than ten)
X placed before L or C indicates ten less, so forty is XL (ten less than fifty) and ninety is XC (ten less than
a hundred)
C placed before D or M indicates a hundred less, so four hundred is CD (a hundred less than five hundred) and
nine hundred is CM (a hundred less than a thousand)[5]
For example, MCMIV is one thousand nine hundred and four, 1904 (M is a thousand, CM is nine hundred and IV is four).
=end

def roman_numeral num
# your code here
end
# I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000
retstr = ""
m = (num / 1000) #Integer division so produces 0 if no 1,000's.
d = ((num % 1000) / 500)
c = ((num % 500) / 100)
l = ((num % 100) / 50)
x = ((num % 50) / 10)
v = ((num % 10) / 5)
i = (num % 5)

hunds = ((num % 1000) / 100)
tens = ((num % 100) / 10)
units = (num % 10)

retstr += "M"*m
if hunds == 9
retstr += "CM" #900 Special case
elsif hunds == 4 #400 Special case
retstr += "CD"
else
retstr += + "D"*d + "C"*c #Use default build of Roman Num for hundreds using C's and D's.
end
if tens == 9
retstr += "XC" #90 Special case
elsif tens == 4
retstr += "XL" #40 Special case
else
retstr += "L"*l + "X"*x #Use default build of Roman Num for tens using L's and X's.
end
if units == 9
retstr += "IX" #9 Special case
elsif units == 4
retstr += "IV" #4 Special case
else
retstr += "V"*v + "I"*i #Use default build of Roman Num for ones using V's and I's.
end
retstr
end

#puts roman_numeral 1954
25 changes: 23 additions & 2 deletions ch10-nothing-new/dictionary_sort.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
#I did a dictionary sort for the sort.rb exercise so this code is the same!
def dictionary_sort arr
# your code here
end
return arr if arr.count <= 1
still_unsorted = arr
already_sorted = []
for count in 0...arr.length
smallest = still_unsorted[0].downcase
key = ""
for counter in 0...still_unsorted.length
if still_unsorted[counter].downcase <= smallest
smallest = still_unsorted[counter].downcase
smallest_orig_case = still_unsorted[counter]
key = counter
end
end
already_sorted.push smallest_orig_case
still_unsorted.delete_at(key.to_i)
end
already_sorted
end

#print dictionary_sort ["Glenn", "Is", "writing", "a", "sort", "method", "did", "You", "Know"]

#print dictionary_sort ["singing","A","feel","can", "like","can"]
209 changes: 208 additions & 1 deletion ch10-nothing-new/english_number.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,210 @@
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']

# "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
#NEW CODE START3
write = left/1000000000 # How many billions left?

left = left - write*1000000000 # Subtract off those billions.

if write > 0

# Now here's the recursion:

billions = english_number write

num_string = num_string + billions + ' billion'

if left > 0

# So we don't write 'one billionseventy million'...

num_string = num_string + ' '

end

end

#NEW CODE END3


#NEW CODE START2
write = left/1000000 # How many millions left?

left = left - write*1000000 # Subtract off those millions.

if write > 0

# Now here's the recursion:

millions = english_number write

num_string = num_string + millions + ' million'

if left > 0

# So we don't write 'one millionseventy thousand'...

num_string = num_string + ' '

end

end

#NEW CODE END2

#NEW CODE START1
write = left/1000 # How many thousands left?

left = left - write*1000 # Subtract off those thousands.

if write > 0

# Now here's the recursion:

thousands = english_number write

num_string = num_string + thousands + ' thousand'

if left > 0

# So we don't write 'nine thousandnine hundred'...

num_string = num_string + ' '

end

end

#NEW CODE END1
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

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

print english_number( 0); print " "; print 0; puts
print english_number( 9); print " "; print 9; puts
print english_number( 10); print " "; print 10; puts
print english_number( 11); print " "; print 11; puts
print english_number( 17); print " "; print 17; puts
print english_number( 32); print " "; print 32; puts
print english_number( 88); print " "; print 88; puts
print english_number( 99); print " "; print 99; puts
print english_number(100); print " "; print 100; puts
print english_number(101); print " "; print 101; puts
print english_number(234); print " "; print 234; puts
print english_number(3211); print " "; print 3211; puts
print english_number(999999); print " "; print 999999; puts
print english_number(1000000000000); print " "; print 1000000000000; puts

print english_number(10001); print " "; print 10001; puts
print english_number(1070301); print " "; print 1070301; puts
Loading