add some exercises

This commit is contained in:
julien committed 2026-10-13 20:33:50 +02:00
1 parent f6abf65e91
commit d79c543c72
13 files changed
+232

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