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

1 passed #395

Open
wants to merge 14 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
6 changes: 5 additions & 1 deletion session1/3-challenge/1_arithmetic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
# arithmetic1(-6) # => -50

def arithmetic1(n)

<<<<<<< HEAD
n-20*5
=======
n * 5 - 20
>>>>>>> 83101f98e8bd2cec234ee9dbfbaf32fb6469153c
end
1 change: 1 addition & 0 deletions session1/3-challenge/2_arithmetic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
# arithmetic2(-6, -7) # => -3.5

def arithmetic2(a, b)
a > b ? b / 2.0 : a / 2.0
end
2 changes: 2 additions & 0 deletions session1/3-challenge/3_simple_logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
# ten_twenty(6) # => 10

def ten_twenty(n)
n.odd? ? 20 : 10

end
5 changes: 3 additions & 2 deletions session1/3-challenge/5_string.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Given a string, replace every instance of sad to happy
#
#
# add_more_ruby("The clowns were sad.") # => "The clowns were happy."
# add_more_ruby("The sad dad said sad stuff.") # => "The happy dad said happy stuff."
# add_more_ruby("Sad times are ahead!") # => "Happy times are ahead!"

def add_more_ruby(string)
end
string.gsub(/[sS]ad/, {'sad' =>'happy', 'Sad'=>'Happy'})
end
10 changes: 9 additions & 1 deletion session1/3-challenge/6_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
#

def odds_and_evens(string, return_odds)
new_string = ""
string.length.times do |x|
next if return_odds == true && x.even?
next if return_odds == false && x.odd?

end
new_string << string[x]
end

new_string
end
26 changes: 26 additions & 0 deletions session2/3-challenge/12_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,34 @@
# f.to_f # => 0.5

class Fraction

attr_accessor :numerator, :denominator

def initialize numerator, denominator
@numerator = numerator
@denominator = denominator

end

def gcd(a,b)
return a if b == 0
gcd(b, a%b)
end

def to_s
"#{@numerator}/#{@denominator}"
end

def to_f
@numerator / denominator.to_f
end

def lowest
div = gcd(@denominator, @numerator)
Fraction.new(@numerator/div, @denominator/div)
end
end

f = Fraction.new(20,60)
puts f.numerator
puts f.lowest.to_s
11 changes: 8 additions & 3 deletions session2/3-challenge/1_input_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# "11\n7\n18\n" to standard output.

def sum_difference_product
# your code goes here

end
# num = gets.chomp
numbers = gets.chomp.split(" ")
puts numbers[0].to_i + numbers[1].to_i
puts numbers[0].to_i - numbers[1].to_i
puts numbers[0].to_i * numbers[1].to_i


end
15 changes: 12 additions & 3 deletions session2/3-challenge/2_input_output_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
# and when you think it is correct, you can test it with $ rake 2:2

def hi_hi_goodbye
# your code here

puts "Enter a number"
while true
number = gets.chomp
break if number == "bye"
number.to_i.times do
print "hi "
end
puts ""
# number.to_i.times print "hi "
end
puts "goodbye"
end


Expand All @@ -29,4 +38,4 @@ def hi_hi_goodbye
# This will just invoke the method if you run this program directly
# This way you can try it out by running "$ ruby 2_input_output_control.rb"
# but it will still work for our tests
hi_hi_goodbye if $0 == __FILE__
hi_hi_goodbye if $0 == __FILE__
14 changes: 13 additions & 1 deletion session2/3-challenge/3_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

class String
def every_other_char
str = ""
split_string = self.split("")
count = 1
split_string.each do |letter|
if count % 2 == 1
str += letter
end
count += 1
end

str
end

end

puts "sdfsdfsdf".every_other_char
11 changes: 10 additions & 1 deletion session2/3-challenge/4_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@

# This time you will have to define the method, it's called: get_squares

def get_squares(num_arr)
return_arr = []
num_arr.each do |number|
if num_arr.include?(number * number)
return_arr << number
end
end
return_arr.sort
end


# puts get_squares([9,3,81])
7 changes: 7 additions & 0 deletions session2/3-challenge/5_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@
#
# mod_three [0,1,2,3,4,5,6,7] # => [1, 2, 1, 2, 1]

def mod_three(num_arr)
new = []
num_arr.map {|number| new << number % 3 if number % 3 > 0}
new
end

puts mod_three([3,4,5,6,7,8,9])
10 changes: 10 additions & 0 deletions session2/3-challenge/6_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@
# prime_chars? ['a', 'bcd'] # => false
# prime_chars? ['a', 'b', 'cd'] # => false

def prime_chars?(num_arr)
require 'prime'
total = 0
num_arr.each do |x|
total += x.length
end
Prime.prime?(total)
end

# puts prime_chars?(["s"])
10 changes: 9 additions & 1 deletion session2/3-challenge/9_input_output_logic_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
# USER: BYE

def deaf_grandma

while true
input = gets.chomp
break if input == "BYE"
if input == input.upcase && input != ""
puts "NO, NOT SINCE 1938!"
else
puts "HUH?! SPEAK UP, SONNY!"
end
end
end


Expand Down