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

+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env ruby
class Card
attr_reader :value, :suit
def initialize(value, suit)
@value = value
@suit = suit
end
end
def has_suit?(hand, suit)
hand.any? { |card| card.suit == suit }
end
def valid_follow_card?(hand, lead_card, follow_card)
if follow_card.suit == lead_card.suit
true
elsif has_suit?(hand, lead_card.suit)
false
else
true
end
end
hand = [
Card.new("9", "hearts"),
Card.new("jack", "clubs"),
Card.new("7", "spades")
]
lead_card = Card.new("king", "hearts")
puts valid_follow_card?(hand, lead_card, hand[0]) # true
puts valid_follow_card?(hand, lead_card, hand[1]) # false