Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Last active October 15, 2019 16:15
Show Gist options
  • Save hadrienblanc/34b6a289c996a9b6a5e48654aea93cbb to your computer and use it in GitHub Desktop.
Save hadrienblanc/34b6a289c996a9b6a5e48654aea93cbb to your computer and use it in GitHub Desktop.
#
# Tu joues une partie de cartes et durant la partie, tu peux soit gagner 1 point, soit gagner 2 points par manche.
# Le but étant d’arriver à 26 points.
# Quelles sont les différentes combinaisons de points possibles durant le jeu afin d’arriver à 26 points ?
# Exemple pour un total de 3 points, il y a 3 combinaisons : 1/1/1 – 2/1 – 1/2
#
possible_combinations = []
possible_play = [1, 2]
range_of_games_played = 13..26
range_of_games_played.each do |number_of_games_played|
possible_play.repeated_permutation(number_of_games_played).each do |scenario|
possible_combinations << scenario if scenario.reduce(:+) == 26
end
end
puts "we have #{possible_combinations.size} possible combinations in order to achieve 26 points."
# Hello, my name is Hadrien
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment