diff --git a/lib/00_hello.rb b/lib/00_hello.rb index a5fd1d52..f42db47f 100644 --- a/lib/00_hello.rb +++ b/lib/00_hello.rb @@ -1,7 +1,7 @@ def hello - + return "Hello!" end -def greet(name) - +def greet(nom) + return "Hello, #{nom}!" end diff --git a/lib/01_temperature.rb b/lib/01_temperature.rb new file mode 100644 index 00000000..e95206e7 --- /dev/null +++ b/lib/01_temperature.rb @@ -0,0 +1,9 @@ +def ftoc(t) + a = ((t - 32) * (5.0 / 9)) + return a.to_f +end + +def ctof(tt) + b = (tt * (9.0 / 5) + 32) + return b.to_f +end \ No newline at end of file diff --git a/lib/02_calculator.rb b/lib/02_calculator.rb new file mode 100644 index 00000000..f77bda4b --- /dev/null +++ b/lib/02_calculator.rb @@ -0,0 +1,38 @@ +def add(n1, n2) + a = n1 + n2 + return a.to_f +end + +def subtract(n3, n4) + b = n3 - n4 + return b.to_f +end + +def sum(l) + tab = Array.new(l) + somme = 0 + for i in 0..tab.length-1 do + somme = somme + tab[i] + end + return somme.to_f +end + +def multiply(n5, n6) + c = n5 * n6 + return c.to_f +end + +def power(n7, n8) + d = n7 ** n8 + return d.to_f +end + +def factorial(n9) + fact = 1 + i = 1 + while i<=n9 + fact = fact * i + i +=1 + end + return fact +end diff --git a/lib/03_basics.rb b/lib/03_basics.rb new file mode 100644 index 00000000..3a4e69f4 --- /dev/null +++ b/lib/03_basics.rb @@ -0,0 +1,30 @@ +def who_is_bigger(a, b, c) + if a == nil || b == nil || c == nil + return "nil detected" + end + if a > b && a > c + return "a is bigger" + end + if b > a && b > c + return "b is bigger" + end + if c > a && c > b + return "c is bigger" + end +end + +def reverse_upcase_noLTA(phrase) + return phrase.reverse.upcase.delete('LTA') +end + +def array_42(l1) + return l1.include?(42) +end + +def magic_array(l2) + b = l2.flatten! + b = l2.sort! + b = b.collect{|i| i*2} + b = b.delete_if{|i| i%3==0} + b = b.uniq +end \ No newline at end of file diff --git a/lib/04_simon_says.rb b/lib/04_simon_says.rb new file mode 100644 index 00000000..914e28c8 --- /dev/null +++ b/lib/04_simon_says.rb @@ -0,0 +1,22 @@ +def simon_says + def echo(greet) + return greet + end + def shout(maj) + return maj.upcase + end + def repeat(mot1, n1) + n1.times do |i| + return mot1 + end + end + def start_of_word(mot2, n2) + return mot2.slice(0..n2-1) + end + def first_word(mot3, n3) + return mot3.scan(/\w+/)[0] + end + def titleize(mot2) + + end +end \ No newline at end of file diff --git a/lib/05_timer.rb b/lib/05_timer.rb new file mode 100644 index 00000000..a7bb8824 --- /dev/null +++ b/lib/05_timer.rb @@ -0,0 +1,59 @@ +def time_string(s) + min = 0 + h = 0 + if s < 60 + if s < 10 + return "0#{h}:0#{min}:0#{s}" + else + return "0#{h}:0#{min}:#{s}" + end + else + while s >= 60 + s -= 60 + min += 1 + end + if min < 60 + if min < 10 && s < 10 + return "0#{h}:0#{min}:0#{s}" + end + if min >= 10 && s < 10 + return "0#{h}:#{min}:0#{s}" + end + if min < 10 && s >= 10 + return "0#{h}:0#{min}:#{s}" + end + if min >= 10 && s >= 10 + return "0#{h}:#{min}:#{s}" + end + else + while min >= 60 + min -= 60 + h += 1 + end + if h < 10 && min < 10 && s < 10 + return "0#{h}:0#{min}:0#{s}" + end + if h < 10 && min < 10 && s >= 10 + return "0#{h}:0#{min}:#{s}" + end + if h < 10 && min >= 10 && s < 10 + return "0#{h}:#{min}:0#{s}" + end + if h < 10 && min >= 10 && s >= 10 + return "0#{h}:#{min}:#{s}" + end + if h >= 10 && min < 10 && s < 10 + return "#{h}:0#{min}:0#{s}" + end + if h >= 10 && min < 10 && s >= 10 + return "#{h}:0#{min}:#{s}" + end + if h >= 10 && min >= 10 && s < 10 + return "#{h}:#{min}:0#{s}" + end + if h >= 10 && min >= 10 && s >= 10 + return "#{h}:#{min}:#{s}" + end + end + end +end \ No newline at end of file diff --git a/lib/06_pig_latin.rb b/lib/06_pig_latin.rb new file mode 100644 index 00000000..63fbb0d1 --- /dev/null +++ b/lib/06_pig_latin.rb @@ -0,0 +1,12 @@ +def translate(mot) + k = mot[0] + if k=="a" || k=="e" || k=="o" || k=="i" || k=="u" || k== "y" + return mot+"ay" + else + return mot.reverse+"ay" + end + aa = mot.slice(0..1) + if aa=="ch" + return mot.reverse(2..mot.length-1)+mot(0..1) + end +end \ No newline at end of file