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

projet semaine2 sur rspec #1

Open
wants to merge 2 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: 3 additions & 3 deletions lib/00_hello.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def hello

return "Hello!"
end

def greet(name)

def greet(nom)
return "Hello, #{nom}!"
end
9 changes: 9 additions & 0 deletions lib/01_temperature.rb
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions lib/02_calculator.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions lib/03_basics.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions lib/04_simon_says.rb
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions lib/05_timer.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/06_pig_latin.rb
Original file line number Diff line number Diff line change
@@ -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