~mrlee/www.kamelasa.dev

2a904814de5a7209fc3ce9c0d400b0bb40acbf7e — Lee Meichin a month ago 1e25f07
Make order sensible
1 files changed, 5 insertions(+), 5 deletions(-)

M posts/ruby-sorcery.poly.pm
M posts/ruby-sorcery.poly.pm => posts/ruby-sorcery.poly.pm +5 -5
@@ 110,22 110,22 @@ This particular solution depends on the hand being ordered, but that's fine, a l
◊codeblock['ruby]{
  def royal_flush?(hand)
    case hand
    in [[1, c, s], ['K', ^c, ^s], ['Q', ^c, ^s], ['J', ^c, ^s], [10, ^c, ^s]]
    in [[1, c, s], [10, ^c, ^s], ['J', ^c, ^s], ['Q', ^c, ^s], ['K', ^c, ^s]]
      true
    else false
    end
  end

  # alternatively, if golfing in Ruby 3:
  # def royal_flush?(hand) = !!(hand in [[1, c, s], ['K', ^c, ^s], ['Q', ^c, ^s], ['J', ^c, ^s], [10, ^c, ^s]] rescue false)
  # def royal_flush?(hand) = !!(hand in [[1, c, s], [10, ^c, ^s], ['J', ^c, ^s], ['Q', ^c, ^s], ['K', ^c, ^s]] rescue false)


  my_hand = PokerHand.new(cards: [
    PlayingCard.new(value: 1, colour: :black, suit: :hearts),
    PlayingCard.new(value: 'K', colour: :black, suit: :hearts),
    PlayingCard.new(value: 'Q', colour: :black, suit: :hearts),
    PlayingCard.new(value: 'J', colour: :black, suit: :hearts),
    PlayingCard.new(value: 10, colour: :black, suit: :hearts),
    PlayingCard.new(value: 'J', colour: :black, suit: :hearts),
    PlayingCard.new(value: 'Q', colour: :black, suit: :hearts),
    PlayingCard.new(value: 'K', colour: :black, suit: :hearts),
  ])

  royal_flush?(my_hand)