Irish Snap: Variant RulesName the poker handCounting icons for Innovation splaysEvaluate a Skat-HandClock (card game)Simulate a 'battle' in the playing card game 'Oorlog'Help me cheat at CheatPlay Best Card in EuchreExecute a Superb Shuffle™Was it a Superb Shuffle™️Is this a straight flush?
Mathematical uses of string theory
Did the British navy fail to take into account the ballistics correction due to Coriolis force during WW1 Falkland Islands battle?
Why don't electrons take the shorter path in coils?
Is it safe to remove the bottom chords of a series of garage roof trusses?
What are some interesting features that are common cross-linguistically but don't exist in English?
Sun setting in East!
Why do all fields in a QFT transform like *irreducible* representations of some group?
C++20 constexpr std::copy optimizations for run-time
What to say to a student who has failed?
Defense against attacks using dictionaries
What magic extends life or grants immortality?
Was Switzerland really impossible to invade during WW2?
Middle Mouse turns on Perspective
Can realistic planetary invasion have any meaningful strategy?
How can I watch the 17th (or last, if less) line in files of a folder?
Avoiding racist tropes in fantasy
Sleeping solo in a double sleeping bag
Deck Size Problems in Deckbuilding
Dealing with an extrovert co-worker
Rule based coloured background for labeling in QGIS
Would this system work to purify water?
Accent on í misaligned in bibliography / citation
Cross-referencing enumerate item
If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?
Irish Snap: Variant Rules
Name the poker handCounting icons for Innovation splaysEvaluate a Skat-HandClock (card game)Simulate a 'battle' in the playing card game 'Oorlog'Help me cheat at CheatPlay Best Card in EuchreExecute a Superb Shuffle™Was it a Superb Shuffle™️Is this a straight flush?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Introduction
Recently, me and a couple of my friends decided to play some cards, and one of them suggested the game 'Irish Snap', which was the inspiration for this challenge. However, I later learnt that the game has a lot of different rules that you can play with, some of which are listed here. The rules that are in this challenge aren't currently listed on that page, hence the name, 'Variant Rules'
The Challenge
Given an array of 3 cards, output a truthy or falsey value depending on if they make a valid snap in a game of Irish snap.
Input
The input will be an array of 3 numbers, ranging from 1-13 inclusive, with 1 representing an ace, 11 representing a jack, 12 representing a queen and 13 representing a king. The input can be in any order of top, middle, bottom.
Rules
The 4 different criteria for if cards make an Irish snap are:
- The top and middle cards are the same
- The top and middle cards have a difference of one
- The top and bottom cards are the same
- The top and bottom cards have a difference of one
If any of these criteria are met, you must output a truthy value. As well as this, for the two criteria that require the cards to have a difference of one, it 'wraps around', meaning that an ace and a king are considered to have a difference of one, and vice versa.
Test Cases
Input (Bottom, Middle, Top) -> Output
1 13 7 -> False
1 4 13 -> True
9 3 6 -> False
8 9 7 -> True
2 6 5 -> True
12 5 11 -> True
10 4 8 -> False
12 13 7 -> False
9 7 10 -> True
7 3 1 -> False
4 2 3 -> True
code-golf decision-problem cards
$endgroup$
add a comment |
$begingroup$
Introduction
Recently, me and a couple of my friends decided to play some cards, and one of them suggested the game 'Irish Snap', which was the inspiration for this challenge. However, I later learnt that the game has a lot of different rules that you can play with, some of which are listed here. The rules that are in this challenge aren't currently listed on that page, hence the name, 'Variant Rules'
The Challenge
Given an array of 3 cards, output a truthy or falsey value depending on if they make a valid snap in a game of Irish snap.
Input
The input will be an array of 3 numbers, ranging from 1-13 inclusive, with 1 representing an ace, 11 representing a jack, 12 representing a queen and 13 representing a king. The input can be in any order of top, middle, bottom.
Rules
The 4 different criteria for if cards make an Irish snap are:
- The top and middle cards are the same
- The top and middle cards have a difference of one
- The top and bottom cards are the same
- The top and bottom cards have a difference of one
If any of these criteria are met, you must output a truthy value. As well as this, for the two criteria that require the cards to have a difference of one, it 'wraps around', meaning that an ace and a king are considered to have a difference of one, and vice versa.
Test Cases
Input (Bottom, Middle, Top) -> Output
1 13 7 -> False
1 4 13 -> True
9 3 6 -> False
8 9 7 -> True
2 6 5 -> True
12 5 11 -> True
10 4 8 -> False
12 13 7 -> False
9 7 10 -> True
7 3 1 -> False
4 2 3 -> True
code-golf decision-problem cards
$endgroup$
1
$begingroup$
Can we take the cards seperately? Or take input astop, [middle, bottom]?
$endgroup$
– Jo King
8 hours ago
$begingroup$
sure, you can do both. changed the question to reflect that
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
Can we invert the output, i.e return False for valid snaps and vice versa? How about a test case where both middle and bottom are valid?
$endgroup$
– Jo King
8 hours ago
$begingroup$
Yeah, you can invert the output. Also, added that test case
$endgroup$
– EdgyNerd
8 hours ago
add a comment |
$begingroup$
Introduction
Recently, me and a couple of my friends decided to play some cards, and one of them suggested the game 'Irish Snap', which was the inspiration for this challenge. However, I later learnt that the game has a lot of different rules that you can play with, some of which are listed here. The rules that are in this challenge aren't currently listed on that page, hence the name, 'Variant Rules'
The Challenge
Given an array of 3 cards, output a truthy or falsey value depending on if they make a valid snap in a game of Irish snap.
Input
The input will be an array of 3 numbers, ranging from 1-13 inclusive, with 1 representing an ace, 11 representing a jack, 12 representing a queen and 13 representing a king. The input can be in any order of top, middle, bottom.
Rules
The 4 different criteria for if cards make an Irish snap are:
- The top and middle cards are the same
- The top and middle cards have a difference of one
- The top and bottom cards are the same
- The top and bottom cards have a difference of one
If any of these criteria are met, you must output a truthy value. As well as this, for the two criteria that require the cards to have a difference of one, it 'wraps around', meaning that an ace and a king are considered to have a difference of one, and vice versa.
Test Cases
Input (Bottom, Middle, Top) -> Output
1 13 7 -> False
1 4 13 -> True
9 3 6 -> False
8 9 7 -> True
2 6 5 -> True
12 5 11 -> True
10 4 8 -> False
12 13 7 -> False
9 7 10 -> True
7 3 1 -> False
4 2 3 -> True
code-golf decision-problem cards
$endgroup$
Introduction
Recently, me and a couple of my friends decided to play some cards, and one of them suggested the game 'Irish Snap', which was the inspiration for this challenge. However, I later learnt that the game has a lot of different rules that you can play with, some of which are listed here. The rules that are in this challenge aren't currently listed on that page, hence the name, 'Variant Rules'
The Challenge
Given an array of 3 cards, output a truthy or falsey value depending on if they make a valid snap in a game of Irish snap.
Input
The input will be an array of 3 numbers, ranging from 1-13 inclusive, with 1 representing an ace, 11 representing a jack, 12 representing a queen and 13 representing a king. The input can be in any order of top, middle, bottom.
Rules
The 4 different criteria for if cards make an Irish snap are:
- The top and middle cards are the same
- The top and middle cards have a difference of one
- The top and bottom cards are the same
- The top and bottom cards have a difference of one
If any of these criteria are met, you must output a truthy value. As well as this, for the two criteria that require the cards to have a difference of one, it 'wraps around', meaning that an ace and a king are considered to have a difference of one, and vice versa.
Test Cases
Input (Bottom, Middle, Top) -> Output
1 13 7 -> False
1 4 13 -> True
9 3 6 -> False
8 9 7 -> True
2 6 5 -> True
12 5 11 -> True
10 4 8 -> False
12 13 7 -> False
9 7 10 -> True
7 3 1 -> False
4 2 3 -> True
code-golf decision-problem cards
code-golf decision-problem cards
edited 8 hours ago
EdgyNerd
asked 9 hours ago
EdgyNerdEdgyNerd
6161 silver badge8 bronze badges
6161 silver badge8 bronze badges
1
$begingroup$
Can we take the cards seperately? Or take input astop, [middle, bottom]?
$endgroup$
– Jo King
8 hours ago
$begingroup$
sure, you can do both. changed the question to reflect that
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
Can we invert the output, i.e return False for valid snaps and vice versa? How about a test case where both middle and bottom are valid?
$endgroup$
– Jo King
8 hours ago
$begingroup$
Yeah, you can invert the output. Also, added that test case
$endgroup$
– EdgyNerd
8 hours ago
add a comment |
1
$begingroup$
Can we take the cards seperately? Or take input astop, [middle, bottom]?
$endgroup$
– Jo King
8 hours ago
$begingroup$
sure, you can do both. changed the question to reflect that
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
Can we invert the output, i.e return False for valid snaps and vice versa? How about a test case where both middle and bottom are valid?
$endgroup$
– Jo King
8 hours ago
$begingroup$
Yeah, you can invert the output. Also, added that test case
$endgroup$
– EdgyNerd
8 hours ago
1
1
$begingroup$
Can we take the cards seperately? Or take input as
top, [middle, bottom]?$endgroup$
– Jo King
8 hours ago
$begingroup$
Can we take the cards seperately? Or take input as
top, [middle, bottom]?$endgroup$
– Jo King
8 hours ago
$begingroup$
sure, you can do both. changed the question to reflect that
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
sure, you can do both. changed the question to reflect that
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
Can we invert the output, i.e return False for valid snaps and vice versa? How about a test case where both middle and bottom are valid?
$endgroup$
– Jo King
8 hours ago
$begingroup$
Can we invert the output, i.e return False for valid snaps and vice versa? How about a test case where both middle and bottom are valid?
$endgroup$
– Jo King
8 hours ago
$begingroup$
Yeah, you can invert the output. Also, added that test case
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
Yeah, you can invert the output. Also, added that test case
$endgroup$
– EdgyNerd
8 hours ago
add a comment |
10 Answers
10
active
oldest
votes
$begingroup$
Python 3, 38 bytes
lambda x,y,z:x-y,x-z&0,1,12,-1,-12
Try it online!
Returns a non-empty set (truthy) if valid, empty set (falsey) if not. Takes input in order top-middle-bottom, but can be rearranged for same code size.
$endgroup$
add a comment |
$begingroup$
05AB1E, 7 bytes
α12%ß2‹
Try it online!
Takes inputs as [middle, bottom], top.
α # absolute difference
12% # mod 12
ß # minimum
2‹ # less than 2?
$endgroup$
add a comment |
$begingroup$
Perl 6, 16 bytes
3>(*-(*|*)+1)%13
Try it online!
Anonymous whatever lambda that takes input as top, middle, bottom and returns a Junction that evaluates to True or False
$endgroup$
$begingroup$
Too bad whitespace is required before<, this was the perfect chance to have a heart smiley.
$endgroup$
– Grimy
8 hours ago
add a comment |
$begingroup$
J, 12 bytes
1 e.2>12||@-
Try it online!
Taking bottom middle as left arg, top as right arg.
original answer taking input as one list
J, 24 bytes
1 e.2>#:@3 5(12||@-/)@#]
Try it online!
#:@3 5The numbers 3 and 5 in binary are0 1 1and1 0 1which are the masks for the middle/top and bottom/top cards respectively(12||@-/)@#We filter the input with those masks, take the abs value of the
resulting differences, then the remainder when divided by 12 (for the ace-king case)1 e.2>are either of the resulting numbers less than 2, ie, 0 or 1?
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 29 bytes
Takes input as ([bottom, middle])(top).
The output is inverted.
a=>c=>a.every(n=>(n-c)/2%6|0)
Try it online!
JavaScript (ES6), 37 30 bytes
Saved 1 byte thanks to @Grimy
Takes input as ([bottom, middle])(top).
a=>c=>a.some(n=>(n-=c)*n%72<2)
Try it online!
$endgroup$
$begingroup$
%144could be%72
$endgroup$
– Grimy
8 hours ago
$begingroup$
@Grimy Thanks! FWIW,%13would also work.
$endgroup$
– Arnauld
8 hours ago
add a comment |
$begingroup$
Perl 5 -ap, 31 bytes
$t=<>}improve this answer
$endgroup$
Perl 5 -ap, 31 bytes
$t=<>{$|=abs($t-$_)%12<2for@F
Try it online!
Input:
bottom middle
top
Actually, the order of the middle and bottom doesn't matter.
Output:
0 for false; 1 for true
answered 5 hours ago
XcaliXcali
6,6841 gold badge7 silver badges23 bronze badges
6,6841 gold badge7 silver badges23 bronze badges
add a comment |
add a comment |
$begingroup$
Pyth, 12 11 bytes
Takes input as [bottom, top, middle] or [middle, top, bottom] (both work).
Outputs [] (Falsy in Pyth) if there's no valid snap, a non-empty array otherwise.
f>2%.aT12.+
Try it online!
If a consistent truthy/falsy value is required, add .A in front for +2 bytes. Then output will be True or False.
Explanation
f # Filter on lambda T:
>2 # 2 >
.aT # abs(T)
% 12 # % 12
.+ # the list of deltas (difference between consecutive elements)
.A (if required)# Any truthy values in the above list?
Edit: -1 with a different approach
$endgroup$
add a comment |
$begingroup$
Pyth, 12 11 bytes
Takes input as [bottom, top, middle] or [middle, top, bottom] (both work).
Outputs [] (Falsy in Pyth) if there's no valid snap, a non-empty array otherwise.
f>2%.aT12.+
Try it online!
If a consistent truthy/falsy value is required, add .A in front for +2 bytes. Then output will be True or False.
Explanation
f # Filter on lambda T:
>2 # 2 >
.aT # abs(T)
% 12 # % 12
.+ # the list of deltas (difference between consecutive elements)
.A (if required)# Any truthy values in the above list?
Edit: -1 with a different approach
$endgroup$
add a comment |
$begingroup$
Pyth, 12 11 bytes
Takes input as [bottom, top, middle] or [middle, top, bottom] (both work).
Outputs [] (Falsy in Pyth) if there's no valid snap, a non-empty array otherwise.
f>2%.aT12.+
Try it online!
If a consistent truthy/falsy value is required, add .A in front for +2 bytes. Then output will be True or False.
Explanation
f # Filter on lambda T:
>2 # 2 >
.aT # abs(T)
% 12 # % 12
.+ # the list of deltas (difference between consecutive elements)
.A (if required)# Any truthy values in the above list?
Edit: -1 with a different approach
$endgroup$
Pyth, 12 11 bytes
Takes input as [bottom, top, middle] or [middle, top, bottom] (both work).
Outputs [] (Falsy in Pyth) if there's no valid snap, a non-empty array otherwise.
f>2%.aT12.+
Try it online!
If a consistent truthy/falsy value is required, add .A in front for +2 bytes. Then output will be True or False.
Explanation
f # Filter on lambda T:
>2 # 2 >
.aT # abs(T)
% 12 # % 12
.+ # the list of deltas (difference between consecutive elements)
.A (if required)# Any truthy values in the above list?
Edit: -1 with a different approach
edited 5 hours ago
answered 5 hours ago
ar4093ar4093
1714 bronze badges
1714 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 6 bytes
ạ%12ṠƑ
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 6 bytes
ạ%12ṠƑ
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 6 bytes
ạ%12ṠƑ
Try it online!
$endgroup$
Jelly, 6 bytes
ạ%12ṠƑ
Try it online!
answered 4 hours ago
Erik the OutgolferErik the Outgolfer
35.8k4 gold badges30 silver badges111 bronze badges
35.8k4 gold badges30 silver badges111 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 12 bytes
›²⌊﹪↔⁻E²NN¹²
Try it online! Port of @Grimy's answer. Takes input as three separate values bottom, middle, top, and outputs using Charcoal's default Boolean format of - for true, nothing for false. Explanation:
² Literal 2
› Is greater than
⌊ Minimum of
↔ Absolute value of (vectorised)
E²N First two numeric inputs as a list ([bottom, middle])
⁻ Minus (vectorised)
N Third input (top)
﹪ Modulo (vectorised)
¹² Literal 12
$endgroup$
add a comment |
$begingroup$
Charcoal, 12 bytes
›²⌊﹪↔⁻E²NN¹²
Try it online! Port of @Grimy's answer. Takes input as three separate values bottom, middle, top, and outputs using Charcoal's default Boolean format of - for true, nothing for false. Explanation:
² Literal 2
› Is greater than
⌊ Minimum of
↔ Absolute value of (vectorised)
E²N First two numeric inputs as a list ([bottom, middle])
⁻ Minus (vectorised)
N Third input (top)
﹪ Modulo (vectorised)
¹² Literal 12
$endgroup$
add a comment |
$begingroup$
Charcoal, 12 bytes
›²⌊﹪↔⁻E²NN¹²
Try it online! Port of @Grimy's answer. Takes input as three separate values bottom, middle, top, and outputs using Charcoal's default Boolean format of - for true, nothing for false. Explanation:
² Literal 2
› Is greater than
⌊ Minimum of
↔ Absolute value of (vectorised)
E²N First two numeric inputs as a list ([bottom, middle])
⁻ Minus (vectorised)
N Third input (top)
﹪ Modulo (vectorised)
¹² Literal 12
$endgroup$
Charcoal, 12 bytes
›²⌊﹪↔⁻E²NN¹²
Try it online! Port of @Grimy's answer. Takes input as three separate values bottom, middle, top, and outputs using Charcoal's default Boolean format of - for true, nothing for false. Explanation:
² Literal 2
› Is greater than
⌊ Minimum of
↔ Absolute value of (vectorised)
E²N First two numeric inputs as a list ([bottom, middle])
⁻ Minus (vectorised)
N Third input (top)
﹪ Modulo (vectorised)
¹² Literal 12
answered 1 hour ago
NeilNeil
87.8k8 gold badges46 silver badges185 bronze badges
87.8k8 gold badges46 silver badges185 bronze badges
add a comment |
add a comment |
$begingroup$
C (gcc), 47 43 bytes
f(b,m,t)1<<t-b)&0x80101003;
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 47 43 bytes
f(b,m,t)1<<t-b)&0x80101003;
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 47 43 bytes
f(b,m,t)1<<t-b)&0x80101003;
Try it online!
$endgroup$
C (gcc), 47 43 bytes
f(b,m,t)1<<t-b)&0x80101003;
Try it online!
edited 3 hours ago
answered 3 hours ago
G. SliepenG. Sliepen
4302 silver badges5 bronze badges
4302 silver badges5 bronze badges
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f190599%2firish-snap-variant-rules%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
Can we take the cards seperately? Or take input as
top, [middle, bottom]?$endgroup$
– Jo King
8 hours ago
$begingroup$
sure, you can do both. changed the question to reflect that
$endgroup$
– EdgyNerd
8 hours ago
$begingroup$
Can we invert the output, i.e return False for valid snaps and vice versa? How about a test case where both middle and bottom are valid?
$endgroup$
– Jo King
8 hours ago
$begingroup$
Yeah, you can invert the output. Also, added that test case
$endgroup$
– EdgyNerd
8 hours ago