From 7a0948efa6bf238373408bf0fe3b564f456a7bee Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 13:24:57 +0200 Subject: [PATCH 01/10] first commit exo 0 et 1 --- 00_hello/hello.rb | 8 +++++++- 01_temperature/temperature.rb | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/00_hello/hello.rb b/00_hello/hello.rb index 251797306..d51f4a31c 100644 --- a/00_hello/hello.rb +++ b/00_hello/hello.rb @@ -1 +1,7 @@ -#write your code here +def hello() + return "Hello!" +end + +def greet(name) + return "Hello, #{name}!" +end diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb index 251797306..57310fe36 100644 --- a/01_temperature/temperature.rb +++ b/01_temperature/temperature.rb @@ -1 +1,8 @@ #write your code here +def ftoc(a) + return ((a - 32)/1.8).round(2) +end + +def ctof(b) + return ((b * 1.8) + 32) +end From 3cd64e6f7554200edd492f609d43151934c20cdd Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 16:04:13 +0200 Subject: [PATCH 02/10] exos 2 et 3 --- 02_calculator/calculator.rb | 16 ++++++++++++- 02_calculator/calculator_spec.rb | 2 +- 03_simon_says/simon_says.rb | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 251797306..3db8b6d51 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -1 +1,15 @@ -#write your code here +def add(a,b) + return a + b +end + +def subtract(a,b) + return a - b +end + +def sum(a) + c = 0 + a.each do |b| + c += b + end + return c +end diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index fef7e9d00..f7017a930 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -82,7 +82,7 @@ it "multiplies two numbers" it "multiplies several numbers" - + end describe "#power" do diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb index 251797306..7797e0e21 100644 --- a/03_simon_says/simon_says.rb +++ b/03_simon_says/simon_says.rb @@ -1 +1,42 @@ #write your code here +def echo(a) + return a +end + +def shout(a) + return(a).upcase! +end + +def repeat(a, b = 0) + if b == 0 + return "#{a} #{a}" + else + c = [] + b.times do + c << a + end + return c.join(" ") + end +end + +def start_of_word(a, b) + return a[0..(b - 1)] +end + +def first_word(a) + return a.split(" ")[0] +end + +def titleize(a) + skip = ["and", "or", "the", "over"] + c = [] + a.split(" ").each do |b| + if skip.include? b + c << b + else + c << b.capitalize! + end + end + c << b.capitalize! + return c.join(" ") +end From 7455335101aed26837556d6eceb77c8e46f3b8b6 Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 16:10:12 +0200 Subject: [PATCH 03/10] exo 3 fini --- 03_simon_says/simon_says.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb index 7797e0e21..007a84004 100644 --- a/03_simon_says/simon_says.rb +++ b/03_simon_says/simon_says.rb @@ -37,6 +37,6 @@ def titleize(a) c << b.capitalize! end end - c << b.capitalize! + c[0] = a.split(" ")[0].capitalize! return c.join(" ") end From 018447d22e81d417966d8fdbb696061a54e9ddfa Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 17:44:43 +0200 Subject: [PATCH 04/10] spec 1 ok --- 04_pig_latin/pig_latin.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb index 251797306..048fec560 100644 --- a/04_pig_latin/pig_latin.rb +++ b/04_pig_latin/pig_latin.rb @@ -1 +1,23 @@ -#write your code here +def translate(a) + vow = ["a", "e", "i", "o", "u", "y"] + ay = "ay" + word = [] + + a.split(" ").each do |w| + + if vow.include? w[0] + return w + ay + + else + w = w.split(//) + word << w.rotate! until vow.include? w[0] + puts word + end +puts word.join("") + ay + end + +end + + +ah = "apple banana cherry" +puts translate(ah) From a6347d7e234104ca213af5c1403d1d4021246b17 Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 18:25:49 +0200 Subject: [PATCH 05/10] 2 consonnes OK --- 04_pig_latin/pig_latin.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb index 048fec560..2a6c3467d 100644 --- a/04_pig_latin/pig_latin.rb +++ b/04_pig_latin/pig_latin.rb @@ -1,23 +1,20 @@ def translate(a) vow = ["a", "e", "i", "o", "u", "y"] ay = "ay" - word = [] + phrase = [] a.split(" ").each do |w| if vow.include? w[0] return w + ay - else w = w.split(//) - word << w.rotate! until vow.include? w[0] - puts word + w.rotate! until vow.include? w[0] end -puts word.join("") + ay + return w.join("") + ay end end - -ah = "apple banana cherry" +ah = "testos jrye" puts translate(ah) From b0bb03762d67fa760ee0aa196dc1720eb9d560b6 Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 18:38:59 +0200 Subject: [PATCH 06/10] 3 consonnes OK --- 04_pig_latin/pig_latin.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb index 2a6c3467d..0a61efc7e 100644 --- a/04_pig_latin/pig_latin.rb +++ b/04_pig_latin/pig_latin.rb @@ -4,17 +4,19 @@ def translate(a) phrase = [] a.split(" ").each do |w| - + # print a.split if vow.include? w[0] - return w + ay + word = w + ay + # phrase << word else w = w.split(//) w.rotate! until vow.include? w[0] + word = w.join("") + ay end - return w.join("") + ay + phrase << word end - + return phrase.join(" ") end -ah = "testos jrye" -puts translate(ah) +# ah = "aghte oputfg" +# puts translate(ah) From 5751a8ebdea78e6667bc7c6e14246598b6184857 Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 22:01:15 +0200 Subject: [PATCH 07/10] =?UTF-8?q?exo=204=20fini,=20d=C3=A9but=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04_pig_latin/pig_latin.rb | 22 +++++++++++++++------- 05_book_titles/book.rb | 7 ++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb index 0a61efc7e..a847abcd3 100644 --- a/04_pig_latin/pig_latin.rb +++ b/04_pig_latin/pig_latin.rb @@ -1,22 +1,30 @@ def translate(a) + vow = ["a", "e", "i", "o", "u", "y"] ay = "ay" phrase = [] a.split(" ").each do |w| - # print a.split - if vow.include? w[0] + # -- cas "squ" -- + if w.index("squ") + w = w.split(//).rotate(3) + word = w.join("") + ay + # -- cas "qu" -- + elsif w.index("qu") + w = w.split(//).rotate(2) + word = w.join("") + ay + # -- voyelle -- + elsif vow.include? w[0] word = w + ay - # phrase << word + # -- consonne rotate jusqu'à voyelle -- else w = w.split(//) w.rotate! until vow.include? w[0] word = w.join("") + ay end + phrase << word - end + end + return phrase.join(" ") end - -# ah = "aghte oputfg" -# puts translate(ah) diff --git a/05_book_titles/book.rb b/05_book_titles/book.rb index 009f2643e..33938e416 100644 --- a/05_book_titles/book.rb +++ b/05_book_titles/book.rb @@ -1,3 +1,8 @@ class Book -# write your code here + attr_accessor :title + + def book(title) + @book = book.capitalize! + end + end From caa99458ae46aef809e59263a5be2524239fca64 Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 23:17:29 +0200 Subject: [PATCH 08/10] Relecture + debut exo 5 --- 01_temperature/temperature.rb | 1 - 02_calculator/calculator.rb | 4 ++-- 03_simon_says/simon_says.rb | 2 +- 05_book_titles/book.rb | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb index 57310fe36..1bee36fa6 100644 --- a/01_temperature/temperature.rb +++ b/01_temperature/temperature.rb @@ -1,4 +1,3 @@ -#write your code here def ftoc(a) return ((a - 32)/1.8).round(2) end diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 3db8b6d51..49bd6067c 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -7,9 +7,9 @@ def subtract(a,b) end def sum(a) - c = 0 + c = 0 a.each do |b| c += b - end + end return c end diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb index 007a84004..0ecc6a40e 100644 --- a/03_simon_says/simon_says.rb +++ b/03_simon_says/simon_says.rb @@ -38,5 +38,5 @@ def titleize(a) end end c[0] = a.split(" ")[0].capitalize! - return c.join(" ") + return c.join(" ") end diff --git a/05_book_titles/book.rb b/05_book_titles/book.rb index 33938e416..2e93da228 100644 --- a/05_book_titles/book.rb +++ b/05_book_titles/book.rb @@ -1,8 +1,8 @@ class Book attr_accessor :title - def book(title) - @book = book.capitalize! + def title=(new) + @title = new.capitalize! end end From 569d90d9d33c38c4413b1e27f1ba787429c5115d Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Mon, 9 Apr 2018 23:41:34 +0200 Subject: [PATCH 09/10] exo 5-8 --- 05_book_titles/book.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/05_book_titles/book.rb b/05_book_titles/book.rb index 2e93da228..727aa3d61 100644 --- a/05_book_titles/book.rb +++ b/05_book_titles/book.rb @@ -2,7 +2,19 @@ class Book attr_accessor :title def title=(new) - @title = new.capitalize! + c = [] + conjunctions = ["and", "but", "for", "nor", "or", "so", "yet"] + prepositions = ["over", "the","a", "an", "in", "of"] + new.split(" ").each do |b| + if conjunctions.include? b + c << b + elsif prepositions.include? b + c << b + else + c << b.capitalize! + end + @title = c.join(" ") + end end end From e83fe0edc2d67d63e751fec0115a35b4ede5422a Mon Sep 17 00:00:00 2001 From: Baptiste Rogeon Date: Tue, 10 Apr 2018 00:08:49 +0200 Subject: [PATCH 10/10] upcase on I - test is_a? Integer --- 05_book_titles/book.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/05_book_titles/book.rb b/05_book_titles/book.rb index 727aa3d61..f8d52711f 100644 --- a/05_book_titles/book.rb +++ b/05_book_titles/book.rb @@ -4,12 +4,21 @@ class Book def title=(new) c = [] conjunctions = ["and", "but", "for", "nor", "or", "so", "yet"] - prepositions = ["over", "the","a", "an", "in", "of"] + prepositions = ["over", "in", "of"] + articles = ["the", "a", "an"] + # new = new.to_s new.split(" ").each do |b| if conjunctions.include? b c << b elsif prepositions.include? b c << b + elsif articles.include? b + c << b + elsif b.length == 1 && b == "i" + c << b.upcase! + elsif b.is_a? Integer + # print b + c << b else c << b.capitalize! end @@ -18,3 +27,7 @@ def title=(new) end end + + +puts @book = Book.new +puts @book.title = "I Knew When I was 20"