13
1
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
2Can we take the cards seperately? Or take input as
top, [middle, bottom]
? – Jo King – 2019-08-22T12:52:12.947sure, you can do both. changed the question to reflect that – EdgyNerd – 2019-08-22T12:54:18.203
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? – Jo King – 2019-08-22T13:11:10.447
Yeah, you can invert the output. Also, added that test case – EdgyNerd – 2019-08-22T13:14:27.370
Must the output values be consistent or could we, for example, output
0
forfalse
and any other integer fortrue
or, even, any negative integer forfalse
or any positive integer fortrue
? – Shaggy – 2019-08-22T23:11:16.800Yeah, output doesn't have to be consistent. I'm pretty sure there's a couple of answers using that already – EdgyNerd – 2019-08-23T08:38:21.813