add some exercises
This commit is contained in:
1 parent
f6abf65e91
commit
d79c543c72
13 files changed
+232
No files matched your search
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# Règles :
|
||||
# - le mot choisi doit être présent dans le tableau ;
|
||||
# - s'il existe un mot de 5 lettres ou plus, le choix doit faire au moins 5 lettres ;
|
||||
# - sinon, s'il existe un mot commençant par "a", le choix doit commencer par "a" ;
|
||||
# - sinon, n'importe quel mot présent dans le tableau est accepté.
|
||||
|
||||
def valid_word?(words, chosen_word)
|
||||
return false unless words.include?(chosen_word)
|
||||
|
||||
if words.any? { |word| word.length >= 5 }
|
||||
chosen_word.length >= 5
|
||||
elsif words.any? { |word| word.start_with?("a") }
|
||||
chosen_word.start_with?("a")
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
words = ["chat", "arbre", "chien", "rat"]
|
||||
chosen_word = "rat"
|
||||
|
||||
puts valid_word?(words, chosen_word)
|
||||
Reference in new issue
Block a user