first commit

This commit is contained in:
julien committed 2026-10-13 18:54:55 +02:00
commit f6abf65e91
10 files changed
+346

No files matched your search

+24
View File
@@ -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)