From e7180f8a630942f813e9b5be9eb6ffec32d85cd1 Mon Sep 17 00:00:00 2001 From: Richard Pryce Date: Wed, 5 Aug 2020 14:13:14 +0100 Subject: [PATCH 01/13] 1 passed --- session1/3-challenge/1_arithmetic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session1/3-challenge/1_arithmetic.rb b/session1/3-challenge/1_arithmetic.rb index 049ece773..7f4a3ddd2 100644 --- a/session1/3-challenge/1_arithmetic.rb +++ b/session1/3-challenge/1_arithmetic.rb @@ -9,5 +9,5 @@ # arithmetic1(-6) # => -50 def arithmetic1(n) - + n * 5 - 20 end From d0a379e5e3ed7ed87a6b03e05ffca226f53607f6 Mon Sep 17 00:00:00 2001 From: Richard Pryce Date: Wed, 5 Aug 2020 14:17:37 +0100 Subject: [PATCH 02/13] 2 passed --- session1/3-challenge/2_arithmetic.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/session1/3-challenge/2_arithmetic.rb b/session1/3-challenge/2_arithmetic.rb index 21445b427..eff1269a0 100644 --- a/session1/3-challenge/2_arithmetic.rb +++ b/session1/3-challenge/2_arithmetic.rb @@ -9,4 +9,5 @@ # arithmetic2(-6, -7) # => -3.5 def arithmetic2(a, b) + a > b ? b / 2.0 : a / 2.0 end From 83101f98e8bd2cec234ee9dbfbaf32fb6469153c Mon Sep 17 00:00:00 2001 From: Richard Pryce Date: Wed, 5 Aug 2020 14:22:04 +0100 Subject: [PATCH 03/13] 3 passed --- session1/3-challenge/3_simple_logic.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/session1/3-challenge/3_simple_logic.rb b/session1/3-challenge/3_simple_logic.rb index 29f8c5037..67e5196af 100644 --- a/session1/3-challenge/3_simple_logic.rb +++ b/session1/3-challenge/3_simple_logic.rb @@ -8,4 +8,6 @@ # ten_twenty(6) # => 10 def ten_twenty(n) +n.odd? ? 20 : 10 + end From 14d81ba386da9fede397e3d737672084b1d6aaeb Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Wed, 5 Aug 2020 15:31:56 +0100 Subject: [PATCH 04/13] 1 added --- session1/3-challenge/1_arithmetic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session1/3-challenge/1_arithmetic.rb b/session1/3-challenge/1_arithmetic.rb index 049ece773..7c98d6d06 100644 --- a/session1/3-challenge/1_arithmetic.rb +++ b/session1/3-challenge/1_arithmetic.rb @@ -9,5 +9,5 @@ # arithmetic1(-6) # => -50 def arithmetic1(n) - + n-20*5 end From 36871d3ea1ef1a707ea55f1c96a53193b83c7623 Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Wed, 5 Aug 2020 22:48:34 +0100 Subject: [PATCH 05/13] 6 --- session1/3-challenge/6_string.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/session1/3-challenge/6_string.rb b/session1/3-challenge/6_string.rb index 4dc3a4e83..ab48b0ae7 100644 --- a/session1/3-challenge/6_string.rb +++ b/session1/3-challenge/6_string.rb @@ -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 \ No newline at end of file +new_string << string[x] +end + +new_string +end From 2d90e98b0b5f6f628b50e4bb4da7918ac568fdb6 Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sat, 15 Aug 2020 12:21:45 +0100 Subject: [PATCH 06/13] 2:1 --- session2/3-challenge/1_input_output.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/session2/3-challenge/1_input_output.rb b/session2/3-challenge/1_input_output.rb index 99f723341..5538eac06 100644 --- a/session2/3-challenge/1_input_output.rb +++ b/session2/3-challenge/1_input_output.rb @@ -8,6 +8,11 @@ # "11\n7\n18\n" to standard output. def sum_difference_product - # your code goes here - -end \ No newline at end of file + # 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 From 90992661dfb9b1129a2b303cdb6ed8db9eafe6ad Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sat, 15 Aug 2020 12:31:34 +0100 Subject: [PATCH 07/13] 2:2 --- session2/3-challenge/2_input_output_control.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/session2/3-challenge/2_input_output_control.rb b/session2/3-challenge/2_input_output_control.rb index 31ce263ee..8679ceb66 100644 --- a/session2/3-challenge/2_input_output_control.rb +++ b/session2/3-challenge/2_input_output_control.rb @@ -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 @@ -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__ \ No newline at end of file +hi_hi_goodbye if $0 == __FILE__ From 5c6de7ae0799fa505dbfe62a1b7a96fc34ff6e5f Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sat, 15 Aug 2020 12:48:44 +0100 Subject: [PATCH 08/13] 2:3 --- session2/3-challenge/3_array.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/session2/3-challenge/3_array.rb b/session2/3-challenge/3_array.rb index 4dea8459c..d36da3195 100644 --- a/session2/3-challenge/3_array.rb +++ b/session2/3-challenge/3_array.rb @@ -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 From 21d1e1c0af0d5ac878bd4bef7eb1ee18485b3740 Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sat, 15 Aug 2020 12:56:12 +0100 Subject: [PATCH 09/13] 2:4 --- session2/3-challenge/4_array.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/session2/3-challenge/4_array.rb b/session2/3-challenge/4_array.rb index 85602ab21..3ffeb0949 100644 --- a/session2/3-challenge/4_array.rb +++ b/session2/3-challenge/4_array.rb @@ -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]) From cc22cc20af5190dc7a0e42bbfd586ef1cb84cd06 Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sat, 15 Aug 2020 13:07:28 +0100 Subject: [PATCH 10/13] 2:5 --- session2/3-challenge/5_array.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/session2/3-challenge/5_array.rb b/session2/3-challenge/5_array.rb index 3f1125b04..47f27f661 100644 --- a/session2/3-challenge/5_array.rb +++ b/session2/3-challenge/5_array.rb @@ -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]) From ce19860928aa71a0163b39c5e9efde47e839e953 Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sat, 15 Aug 2020 13:41:52 +0100 Subject: [PATCH 11/13] 2:6 --- session2/3-challenge/6_array.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/session2/3-challenge/6_array.rb b/session2/3-challenge/6_array.rb index 90ae4534c..773539029 100644 --- a/session2/3-challenge/6_array.rb +++ b/session2/3-challenge/6_array.rb @@ -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"]) From 94602aa9eff03e7958d176c7b6622e2a692d7c9e Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Sun, 16 Aug 2020 17:01:11 +0100 Subject: [PATCH 12/13] 9 --- session2/3-challenge/9_input_output_logic_string.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/session2/3-challenge/9_input_output_logic_string.rb b/session2/3-challenge/9_input_output_logic_string.rb index 626119b35..f2baf2860 100644 --- a/session2/3-challenge/9_input_output_logic_string.rb +++ b/session2/3-challenge/9_input_output_logic_string.rb @@ -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 From a60e05a4da79970c1526e1f1416905e09a9b294d Mon Sep 17 00:00:00 2001 From: Prycey77 Date: Thu, 27 Aug 2020 10:37:52 +0100 Subject: [PATCH 13/13] 12_classes.rb passed --- session2/3-challenge/12_classes.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/session2/3-challenge/12_classes.rb b/session2/3-challenge/12_classes.rb index 7bc1f194a..78a2c6bdc 100644 --- a/session2/3-challenge/12_classes.rb +++ b/session2/3-challenge/12_classes.rb @@ -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 \ No newline at end of file