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

Whatapalaver solutions #521

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions ch09-writing-your-own-methods/ask.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
def ask question
# your code here
end
while true
puts question
reply = gets.chomp.downcase
return true if reply == 'yes'
return false if reply == 'no'
puts 'Answer yes or no'
end
end
14 changes: 12 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,13 @@
def old_roman_numeral num
# your code here
end

roman_array = []
roman_array << 'M' * (num / 1000)
roman_array << 'D' * (num % 1000 / 500)
roman_array << 'C' * (num % 500 / 100)
roman_array << 'L' * (num % 100 / 50)
roman_array << 'X' * (num % 50 / 10)
roman_array << 'V' * (num % 10 / 5)
roman_array << 'I' * (num % 5 / 1)
return roman_array.join

end
27 changes: 25 additions & 2 deletions ch09-writing-your-own-methods/roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
def roman_numeral num
# your code here
end
values = [
[1000, 'M'],
[900, 'CM'],
[500, 'D'],
[400, 'CD'],
[100, 'C'],
[50, 'L'],
[40, 'XL'],
[10, 'X'],
[9, 'IX'],
[5, 'V'],
[4, 'IV'],
[1, 'I']
]
new_roman_array = ""

values.each do |number, roman|
while num >= number
new_roman_array << roman
num -= number
end
end

new_roman_array
end