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

Frances' Learn to Program commits #513

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6226ec1
Committing chapter 8 refresher
francesmx Sep 12, 2016
3e23448
Committing the improved ask method
francesmx Sep 13, 2016
0fcab9d
Adding chapter nine old school roman numerals
francesmx Sep 13, 2016
8d811b2
Re-adding old school roman numerals taking my own tests out
francesmx Sep 13, 2016
e6a4689
Adding the classic roman numerals and an updated old school roman num…
francesmx Sep 13, 2016
708afbf
Fixed roman numerals issue.
francesmx Sep 13, 2016
c6ec3ea
Adding sort.rb
francesmx Sep 14, 2016
8af79f4
Adding my awesome shuffle.rb program and hoping for the best.
francesmx Sep 14, 2016
88df535
Adding an awesome dictionary sort method.
francesmx Sep 14, 2016
15003c3
Adding english_number.rb woohoo
francesmx Sep 14, 2016
dd44275
Adding english_number.rb for the second time.
francesmx Sep 14, 2016
22ec22f
Adding english_number.rb for the third time.
francesmx Sep 14, 2016
8bf6b1a
Committing ninety_nine_bottles_of_beer.rb which I have totally nailed
francesmx Sep 15, 2016
ee67c0f
Adding safer picture downloading although I haven't really tested it!…
francesmx Sep 16, 2016
c81f971
Adding playlist file.
francesmx Sep 16, 2016
e8aa1e6
Build a better playlist
francesmx Sep 17, 2016
5a483e2
Added improved build a playlist
francesmx Sep 17, 2016
13074de
Slightly edited better playlist.
francesmx Sep 17, 2016
528c98d
Adding some of the chapter 12 exercises. Getting there woohoo
francesmx Sep 17, 2016
a772ad4
Adding that horrible roman to integer program. Hated it.
francesmx Sep 17, 2016
f7c8515
Adding birthday_helper.rb and birthdates.txt files
francesmx Sep 17, 2016
7907097
Adding extend built in classes.
francesmx Sep 17, 2016
fd87546
Added the roman method extension to the Integer class.
francesmx Sep 17, 2016
499dc38
Adding orange_tree.rb and hoping for the best
francesmx Sep 17, 2016
0e18857
Adding orange_tree.rb with a few edits.
francesmx Sep 17, 2016
2ab9ed8
Adding orange_tree.rb with a few more edits.
francesmx Sep 17, 2016
84308f0
Reckon I've nailed this very enjoyable orange_tree task! Fingers cros…
francesmx Sep 17, 2016
4f22f3c
Fixed minor error in orange tree program.
francesmx Sep 18, 2016
aadced9
More minor edits to orange_tree.rb - here's hoping this time.
francesmx Sep 18, 2016
641a9b0
Adding orange tree program for the final time after learning how to r…
francesmx Sep 18, 2016
b011587
Again committing this blasted orange_tree.rb
francesmx Sep 18, 2016
523dbfa
Again committing this blasted orange_tree.rb grrrrr
francesmx Sep 18, 2016
4631ffa
I really need this to pass now.
francesmx Sep 18, 2016
ecb493a
After all this, I find it doesn't work because I put puts in there. D…
francesmx Sep 18, 2016
e4c0422
This time it failed due to a lack of smiley! Hahaha
francesmx Sep 18, 2016
79a2ae4
Okay that time it failed for a legitimate error that I have now fixed…
francesmx Sep 18, 2016
042cbc7
Added a very fun interactive baby dragon. Hoping to pass
francesmx Sep 18, 2016
4d31971
Adding better profiling.
francesmx Sep 18, 2016
7f986cb
Changed profiling to be true in order to pass tests. Fingers crossed.
francesmx Sep 18, 2016
40c9241
Committing grandfather_clock.rb solution.
francesmx Sep 19, 2016
0e5b28f
Adding program logger.
francesmx Sep 19, 2016
f2a9731
Improved program logger.
francesmx Sep 19, 2016
67bdcb4
Adding revision to better program logger.
francesmx Sep 19, 2016
b379635
Surely final edits.
francesmx Sep 19, 2016
3a2af2c
Surely please this time...
francesmx Sep 19, 2016
593652f
Really hoping this is my last commit for the Chris Pine exercises. PL…
francesmx Sep 19, 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
24 changes: 24 additions & 0 deletions ch08-arrays.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Type as many words as we want (one word per line), continuing until we press Enter on an empty line
# Repeat the words back to us in alphabetical order.
# Test program thoroughly.

words = []
puts "Hello, why don't you type some lines? Enter one word per line. When you get fed up, press Enter on an empty line."

userInputEmpty = false

while userInputEmpty == false

word = gets.chomp

if word != ""
words.push word
puts "How about another word? Leave empty if you're done"

else
userInputEmpty = true
end
end

puts "And here is a lovely alphabetical list of your words!"
puts words.sort
40 changes: 38 additions & 2 deletions ch09-writing-your-own-methods/ask.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
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
break
else
puts 'Please answer "yes" or "no".'

end
end

answer
end

puts "Hello, and thank you for participating."
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 "Thanks for taking part. Actually it wasn't about mexican food; it was about bed wetting."
puts
puts "And your answer to that question was..."
puts wets_bed
49 changes: 47 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,48 @@
# Write a method that when passed an integer between 1 and 3000 (or so)
# returns a string containing the proper old-school Roman numeral.

# M = 1000
# D = 500
# C = 100
# L = 50
# X = 10
# V = 5
# I = 1

# Hint: use the integer division and modulus methods

# How many times does each of those roman numerals factor into numberRequested?

# Example: 1759

# 1 x 1000 = M
# 1 x 500 = D
# 2 x 100 = CC
# 1 x 50 = L
# 0 x 10 = no Xs
# 1 x 5 = V
# 4 x 1 = IIII

# MDCCLVIIII

# How many times does 1,000 go into it? Put that many Ms.
# How many times does 500 go into the remainder? Put that many Ds.
# How many times does 100 go into the remainder? Put that many Cs.
# How many times does 50 go into the remainder? Put that many Ls.
# How many times does 10 go into the remainder? Put that many Xs.
# How many times does 5 go into the remainder? Put that many Vs.
# How many times does 1 go into the remainder? Put that many Is.

def old_roman_numeral num
# your code here
end

numberMs = "M" * (num / 1000)
numberDs = "D" * ((num % 1000) / 500)
numberCs = "C" * ((num % 500) / 100)
numberLs = "L" * ((num % 100) / 50)
numberXs = "X" * ((num % 50) / 10)
numberVs = "V" * ((num % 10) / 5)
numberIs = "I" * ((num % 5) / 1)

return numberMs + numberDs + numberCs + numberLs + numberXs + numberVs + numberIs

end
55 changes: 53 additions & 2 deletions ch09-writing-your-own-methods/roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
# M = 1000
# D = 500
# C = 100
# L = 50
# X = 10
# V = 5
# I = 1

def roman_numeral num
# your code here
end

number1000s = (num / 1000)
number100s = (num % 1000) / 100
number10s = (num % 100) / 10
number1s = (num % 10) / 1

numberDs = (num % 1000) / 500
numberCs = (num % 500) / 100
numberLs = (num % 100) / 50
numberXs = (num % 50) / 10
numberVs = (num % 10) / 5
numberIs = (num % 5) / 1

result = "M" * number1000s

if number100s == 9
result = result + "CM"
elsif number100s == 4
result = result + "CD"
else
result = result + "D" * numberDs
result = result + "C" * numberCs
end

if number10s == 9
result = result + "XC"
elsif number10s == 4
result = result + "XL"
else
result = result + "L" * numberLs
result = result + "X" * numberXs
end

if number1s == 9
result = result + "IX"
elsif number1s == 4
result = result + "IV"
else
result = result + "V" * numberVs
result = result + "I" * numberIs
end

result

end
43 changes: 41 additions & 2 deletions ch10-nothing-new/dictionary_sort.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# Okay how do we solve this in English?
# For the purpose of comparison, we should just downcase everything
# But if it were capitalised to begin with, it ought to remain so

def dictionary_sort arr
# your code here
end
recursive_sort arr, []
end

def recursive_sort unsorted_array, sorted_array

# If the unsorted array has no items in it, return the sorted array
if unsorted_array.length <= 0
return sorted_array
end

# Remove the last word from the unsorted array and put it into the variable smallest
smallest = unsorted_array.pop

# Create a new array called still_unsorted to hold all the other words
still_unsorted = []

# For each word in the unsorted array, see if it's smaller than the 'smallest' word that you took earlier
# If it is, put the smallest word back into the array, and replace 'smallest' with this new word
# If word is not smaller than the smallest, then push this word into the still unsorted array

unsorted_array.each do | word |

if word.downcase < smallest.downcase
still_unsorted.push smallest
smallest = word
else
still_unsorted.push word
end
end

# Put the smallest word into the sorted array
sorted_array.push smallest

# Now call the same recursive sort method to sort out the still_unsorted words
recursive_sort still_unsorted, sorted_array

end
89 changes: 88 additions & 1 deletion ch10-nothing-new/english_number.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
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 = ""

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],
['sexdicillion', 51],
['septendecillion', 54],
['octodecillion', 57],
['novembdecillion', 60],
['vigintillion', 63],
['googol', 100]]

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
left = left - write*zil_base

if write > 0
prefix = english_number write
num_string = num_string + prefix + " " + zil_name
if left > 0
num_string = num_string + " "
end
end
end

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

if write > 0
if ((write == 1) and (left > 0))
num_string = num_string + teenagers[left-1]
left = 0
else
num_string = num_string + tens_place[write-1]
end

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

write = left
left = 0

if write > 0
num_string = num_string + ones_place[write-1]
end

num_string

end

# puts english_number 937234827364876238423423487686234
# puts english_number 234987234982398798423
# puts english_number 23432
puts english_number 99
puts english_number 234
puts english_number 109238745102938560129834709285360238475982374561034
# puts english_number 9898176572634765762999987987
Loading