#!/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)