Irish Snap: Variant Rules
code-golf decision-problemcards
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 work ,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 11 being jack, 12 being queen and 13 being king. The last number in the array will be the number at the top of the stack of cards.
Rules
The 4 different criteria for if cards make an Irish snap are a snap:
- 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 -> 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