Irish Snap: Variant Rules

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

EdgyNerd

Posted 2019-08-22T12:31:31.013

Reputation: 1 106

2Can we take the cards seperately? Or take input as top, [middle, bottom]? – Jo King – 2019-08-22T12:52:12.947

sure, 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 for false and any other integer for true or, even, any negative integer for false or any positive integer for true? – Shaggy – 2019-08-22T23:11:16.800

Yeah, 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

Answers

4

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

Jo King

Posted 2019-08-22T12:31:31.013

Reputation: 38 234

Too bad whitespace is required before <, this was the perfect chance to have a heart smiley. – Grimmy – 2019-08-22T13:18:57.543

4

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.

Arfie

Posted 2019-08-22T12:31:31.013

Reputation: 1 230

3

05AB1E, 7 6 bytes

α12%ß!

Try it online!

Takes inputs as [middle, bottom], top.

α        # absolute difference
 12%     # mod 12
    ß    # minimum
     !   # factorial

Only 1 is truthy in 05AB1E. 0! and 1! are both 1, while no other number has a factorial of 1.

Grimmy

Posted 2019-08-22T12:31:31.013

Reputation: 12 521

2

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 5 The numbers 3 and 5 in binary are 0 1 1 and 1 0 1 which 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?

Jonah

Posted 2019-08-22T12:31:31.013

Reputation: 8 729

2

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!

Arnauld

Posted 2019-08-22T12:31:31.013

Reputation: 111 334

%144 could be %72 – Grimmy – 2019-08-22T13:08:09.813

@Grimy Thanks! FWIW, %13 would also work. – Arnauld – 2019-08-22T13:34:26.013

2

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

Neil

Posted 2019-08-22T12:31:31.013

Reputation: 95 035

1

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

ar4093

Posted 2019-08-22T12:31:31.013

Reputation: 531

1

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

Xcali

Posted 2019-08-22T12:31:31.013

Reputation: 7 671

1

Jelly, 6 bytes

ạ%12ṠƑ

Try it online!

Erik the Outgolfer

Posted 2019-08-22T12:31:31.013

Reputation: 38 134

1

C (gcc), 47 43 bytes

f(b,m,t){return(1<<t-m|1<<t-b)&0x80101003;}

Try it online!

G. Sliepen

Posted 2019-08-22T12:31:31.013

Reputation: 580

1

Japt, 7 bytes

d_aV <2

Try it

Embodiment of Ignorance

Posted 2019-08-22T12:31:31.013

Reputation: 7 014

1

T-SQL 2008, 40 bytes

PRINT 1/-~abs((@-@2)%12/2*((@-@3)%12/2))

Try it online

t-clausen.dk

Posted 2019-08-22T12:31:31.013

Reputation: 2 874

1

Jelly, 6 bytes

I%12ỊẸ

Try it online!

A monadic link taking the list of [middle, top, bottom] as its argument and returning 1 for snap and 0 for no snap.

Nick Kennedy

Posted 2019-08-22T12:31:31.013

Reputation: 11 829

0

[R], 23 bytes

takes input as a=c(bottom,top,middle):

any(abs(diff(a))%%12<2)

Zahiro Mor

Posted 2019-08-22T12:31:31.013

Reputation: 371