Skip to content

Instantly share code, notes, and snippets.

@Drenmi
Last active December 9, 2021 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drenmi/dd30a3e4fa845aa095693ea5f7c31c63 to your computer and use it in GitHub Desktop.
Save Drenmi/dd30a3e4fa845aa095693ea5f7c31c63 to your computer and use it in GitHub Desktop.

Set Checker

In the card game of Set, each card has four distinct attributes:

  • shape (diamond, oval, squiggle)
  • colour (green, red, purple)
  • fill (blank, lined, filled)
  • count (one, two, three)

A set is made from any three cards where the attributes are either all the same or all different.

In our application, a Set card is modelled by:

Card = Struct.new(:shape, :colour, :fill, :count)

(All attributes are passed as symbols.)

Your task is to implement the following function which takes three Card objects as input, and returns true if the three cards make a set, or false otherwise.

def set?(*cards)
  # Add your implementation here
end

Constraints:

  • All cards in a deck of Set are unique, so you don't need to care about looking for duplicates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment