-
Notifications
You must be signed in to change notification settings - Fork 397
initial_pull_request #497
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
Open
meeshyep
wants to merge
28
commits into
makersacademy:master
Choose a base branch
from
meeshyep:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
initial_pull_request #497
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
951ace1
Chapter_9_Exercise1
meeshyep 2ca9e0f
ch09-writing-your-own-methods/
meeshyep 38f0cc9
ch09-writing-your-own-methods/
meeshyep 82a8138
ch09-writing-your-own-methods/
meeshyep f6d0c63
Recursion
meeshyep 16ffe51
sort.txt
meeshyep 3dca936
ch10-nothing-new/
meeshyep 96c6dd2
shuffle.rb
meeshyep c2c90f6
dictionary_sort.rb
meeshyep 36a2973
english_number.rb
meeshyep 3ceb18d
english_number.rb
meeshyep 7753d3a
ninety_nine_bottles_of_beer.rb
meeshyep b135cd9
safer_picture_downloading.rb
meeshyep c3ba910
build_your_own_playlist.rb
meeshyep 980ec15
build_a_better_playlist.rb
meeshyep f6deb3d
happy_birthday.rb
meeshyep 1c22530
one_billion_seconds.
meeshyep b97df45
party_like_its_roman_to_integer_mcmxcix.rb
meeshyep 38ec3a8
birthday_helper.rb
meeshyep 97c90d6
extend_built_in_classes.rb
meeshyep ee25fd4
orange_tree.rb
meeshyep 9db18fa
interactive_baby_dragon.rb
meeshyep ba5ae6f
even_better_profiling.rb
meeshyep e862e64
grandfather_clock.rb
meeshyep 3b3558c
m
meeshyep 7f95d94
better_program_logger.rb
meeshyep 9dd19c3
shuffle.rb
meeshyep 31c9a16
dictionary_sort.rb
meeshyep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
def ask question | ||
# your code here | ||
end | ||
while true | ||
puts question | ||
reply = gets.chomp.downcase | ||
|
||
if (reply == 'yes' || reply == 'no') | ||
if reply == 'yes' | ||
answer = true | ||
else | ||
answer = false | ||
end | ||
break | ||
else | ||
puts 'Please answer "yes" or "no". ' | ||
end | ||
end | ||
end | ||
load './ask.rb' |
14 changes: 12 additions & 2 deletions
14
ch09-writing-your-own-methods/old_school_roman_numerals.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
def old_roman_numeral num | ||
# your code here | ||
end | ||
roman = '' | ||
|
||
roman = roman + 'M' * (num / 1000) | ||
roman = roman + 'D' * (num % 1000 / 500) | ||
roman = roman + 'C' * (num % 500 / 100) | ||
roman = roman + 'L' * (num % 100/ 50) | ||
roman = roman + 'X' * (num % 50/ 10) | ||
roman = roman + 'V' * (num % 10/ 5) | ||
roman = roman + 'I' * (num % 5/ 1) | ||
roman | ||
end | ||
puts(old_roman_numeral(1999)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,38 @@ | ||
def roman_numeral num | ||
# your code here | ||
end | ||
thousands = (num / 1000) | ||
hundreds = (num % 1000 / 100) | ||
tens = (num % 100 / 10) | ||
ones = (num % 10 ) | ||
|
||
roman = 'M' * thousands | ||
if hundreds == 9 | ||
roman = roman + 'CM' | ||
elsif hundreds == 4 | ||
roman = roman + 'CD' | ||
else | ||
roman = roman + 'D' * (num % 1000 / 500) | ||
roman = roman + 'C' * (num % 500 / 100) | ||
end | ||
|
||
if tens == 9 | ||
roman = roman + 'XC' | ||
elsif tens == 4 | ||
roman = roman + 'XL' | ||
else | ||
roman = roman + 'L' * (num % 100 / 50) | ||
roman = roman + 'X' * (num % 50 / 10) | ||
end | ||
|
||
if ones == 9 | ||
roman = roman + 'IX' | ||
elsif ones == 4 | ||
roman = roman + 'IV' | ||
else | ||
roman = roman + 'V' * (num % 10 / 5) | ||
roman = roman + 'I' * (num % 5 / 1) | ||
end | ||
|
||
roman | ||
end | ||
|
||
puts (roman_numeral(1999)) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
def dictionary_sort arr | ||
# your code here | ||
end | ||
def dictionary_sort arr | ||
return arr if arr.length <= 1 | ||
|
||
middle = arr.pop | ||
less = arr.select{|x| x.downcase < middle.downcase} | ||
morr = arr.select{|x| x.downcase >= middle.downcase} | ||
|
||
dictionary_sort(less) + [middle] + dictionary_sort(more) | ||
end | ||
|
||
words = ['can', 'feel', ' singing', 'lobster', 'banana'] | ||
puts(dictionary_sort(words).join('')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,72 @@ | ||
def english_number number | ||
# your code here | ||
if number < 0 | ||
return 'Please enter a number that is not 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], ['nontillion', 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 = 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(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(62819273644748393029282) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
def english_number number | ||
if number < 0 | ||
return 'Please enter a number that is not 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], ['nontillion', 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 = 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(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(62819273644748393029282) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
# your code here | ||
require_relative 'english_number.rb' | ||
|
||
def plurals(num, word) | ||
num == "one" ? num + " " + word : num + " " + word + "s" | ||
end | ||
count = 999 | ||
while count > 0 | ||
number_bottles = english_number(count) | ||
bottles = plurals(number_bottles, "bottle") | ||
puts "#{bottles.capitalize} of beers on the wall, #{bottles} of beer." | ||
count -= 1 | ||
bottles = plurals(english_number(count), "bottle") | ||
puts "Take one down and pass it around, #{bottles} of beer on the wall." | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
def shuffle arr | ||
# your code here | ||
end | ||
meeshyep:~/workspace/Projects/learn_to_program/ch10-nothing-new (master) $ irb | ||
2.3.0 :001 > def shuffle arr | ||
2.3.0 :002?> arr.sort_by{rand} | ||
2.3.0 :003?> end | ||
=> :shuffle | ||
2.3.0 :004 > p(shuffle([1,2,3,4,5,6,7,8,9,0])) | ||
[9, 0, 6, 8, 4, 3, 2, 1, 7, 5] | ||
=> [9, 0, 6, 8, 4, 3, 2, 1, 7, 5] |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
def sort arr | ||
rec_sort arr, [] | ||
end | ||
|
||
def rec_sort unsorted, sorted | ||
if unsorted.length <= 0 | ||
return sorted | ||
end | ||
|
||
smallest = unsorted.pop | ||
still_unsorted = [] | ||
|
||
unsorted.each do |tested_object| | ||
if tested_object < smallest | ||
still_unsorted.push smallest | ||
smallest = tested_object | ||
else | ||
still_unsorted.push tested_object | ||
end | ||
end | ||
|
||
sorted.push smallest | ||
|
||
rec_sort still_unsorted, sorted | ||
end | ||
|
||
puts(sort(['I can', 'feel', 'singing', 'like', 'a', 'can'])) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
def music_shuffle filenames | ||
# your code here | ||
filenames - filenames.sort | ||
len = filenames.length | ||
else | ||
|
||
2.times do | ||
l_idx = 0 | ||
r_idx = len/2 | ||
shuf = [] | ||
|
||
while shuf.length < len | ||
if shuf.length%2 == 0 | ||
shuf.push(filenames[r_indx]) | ||
r_idx = r_idx + 1 | ||
else | ||
shuf.push(filenames[l_idx]) | ||
l_idx = l_idx + 1 | ||
end | ||
end | ||
|
||
filenames = shuf | ||
end | ||
|
||
arr = [] | ||
cut = rand(len) | ||
idx = 0 | ||
|
||
while idx < len | ||
arr.push(filenames[(idx+cut)%len]) | ||
idx = idx + 1 | ||
end | ||
|
||
arr | ||
end | ||
songs = ['aa/bbb', 'aa/ccc', 'aa/ddd', 'AAA/xxxx', 'AAA/yyy', 'AAA/zzzz' , 'foo/bar'] | ||
puts (music_shuffle(songs)) | ||
end_of_input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
# your code here | ||
# your code here | ||
Dir.chdir '/meeshyep:~/workspace//Projects/learn_to_program/ch11-reading-and-writing/' | ||
music_files= Dir['*.mp3'] | ||
puts music_files | ||
|
||
playlist_name=File.new("michelle_playlist.m3u", "w") | ||
|
||
def write_files object, filename | ||
File.open filename, 'w' do |f| | ||
f.write object.join("\n") | ||
end | ||
end | ||
|
||
write_files(music_files, playlist_name) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find what the error after "end" means.