How to resolve the algorithm Set, the card game step by step in the J programming language
How to resolve the algorithm Set, the card game step by step in the J programming language
Table of Contents
Problem Statement
The card game, Set, is played with a pack of 81 cards, each of which depicts either one, two, or three diamonds, ovals, or squiggles. The symbols are coloured red, green, or purple, and the shading is either solid, striped, or open. No two cards are identical. In the game a number of cards are layed out face up and the players try to identify "sets" within the cards. A set is three cards where either the symbols on the cards are all the same or they are all different, the number of symbols on the cards are all the same or all different, the colours are all the same or all different, and the shadings are all the same or all different. For example, this is a set: because each card depicts a different symbol, the number of symbols on each card is different, the colours are all the same, and the shadings are all different. This is not a set: because two of the cards are green and one is purple, so the colours are neither all the same nor all different.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Set, the card game step by step in the J programming language
Source code in the j programming language
deck=: >,{;:each'one two three';'red green purple';'solid striped open';'diamond oval squiggle'
deal=: (?#) { ]
sets=: {{ >;sets0\y }}
sets0=: {{ <;({:y) sets1\}:y }}
sets1=: {{ <~.;({:y) sets2 m\}:y }}
sets2=: {{ <(m,:n)<@,"2 1 y#~m isset n"1 y }}
isset=: {{ 1=#~.(m=n),(m=y),:n=y }}
disp=: <@(;:inv)"1
four=: 4 deal deck
eight=: 8 deal deck
twelve=: 12 deal deck
>disp four
one purple striped oval
one purple striped diamond
three green solid oval
two red solid oval
>disp eight
three green striped diamond
two green open squiggle
three purple striped squiggle
one purple solid squiggle
two green solid oval
three purple solid squiggle
two red solid oval
three purple solid diamond
>disp twelve
two red solid squiggle
three purple open squiggle
two purple open oval
one purple open oval
one green solid oval
three green striped oval
one green open oval
three green open squiggle
one red open squiggle
one purple striped squiggle
two purple striped diamond
two red open diamond
disp sets four
┌┐
││
└┘
disp sets eight
┌┐
││
└┘
disp sets twelve
┌─────────────────────────┬───────────────────────────┬──────────────────────────┐
│three green open squiggle│one purple striped squiggle│two red solid squiggle │
├─────────────────────────┼───────────────────────────┼──────────────────────────┤
│one green open oval │two red open diamond │three purple open squiggle│
├─────────────────────────┼───────────────────────────┼──────────────────────────┤
│three green open squiggle│two red open diamond │one purple open oval │
└─────────────────────────┴───────────────────────────┴──────────────────────────┘
You may also check:How to resolve the algorithm Substring step by step in the Sed programming language
You may also check:How to resolve the algorithm Return multiple values step by step in the Pike programming language
You may also check:How to resolve the algorithm Show the epoch step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Comments step by step in the COBOL programming language
You may also check:How to resolve the algorithm File extension is in extensions list step by step in the Mathematica / Wolfram Language programming language