Scoring Briscola

JavaScript (ES6), 42 bytes

Takes the two ranks in currying syntax (a)(b). Returns 1 for more than, -1 for less than or 0 for equal.

a=>b=>Math.sign((s="05040000123")[a]-s[b])

Try it online!


Using a formula, 48 bytes

This is definitely longer than using a lookup table but also a bit more interesting.

Same I/O format.

a=>b=>Math.sign((g=n=>(1<<n&1802)*6%13)(a)-g(b))

Try it online!

How?

Because many cards have a value of \$0\$, we first want to mask them out. Given a card rank \$n\$, we compute:

$$p=2^n\text{ and }(2^1+2^3+2^8+2^9+2^{10})$$ $$p=2^n\text{ and }1802$$

  n (card)   | 2**n | AND 1802
-------------+------+----------
  1 (Ace)    |    2 |      2
  2          |    4 |      0
  3 (Three)  |    8 |      8
  4          |   16 |      0
  5          |   32 |      0
  6          |   64 |      0
  7          |  128 |      0
  8 (Jack)   |  256 |    256
  9 (Knight) |  512 |    512
 10 (King)   | 1024 |   1024

We now want to transform the remaining non-zero values in such a way that they can be sorted in the correct order. We use:

$$q=6p \bmod 13$$

    p (card)   |   6p | MOD 13
---------------+------+--------
    2 (Ace)    |   12 |   12
    8 (Three)  |   48 |    9
  256 (Jack)   | 1536 |    2     --> Ace > Three > King > Knight > Jack
  512 (Knight) | 3072 |    4
 1024 (King)   | 6144 |    8

MATL, 12 bytes

[DEXIl]&mdZS

Input is an array of two numbers. Output is -1, 0 and 1 respectively for more than, equal to or less than.

Try it online!

Explanation

Consider input [1 4] as an example.

[DEXIl]    % Push [8 9 10 3 1]
           % STACK: [8 9 10 3 1] 
&m         % Implicit input. Index (1-based) of membership, 0 if not member
           % STACK: [5 0]
d          % Consecutive difference
           % STACK: -5
ZS         % Sign. Implicit display
           % STACK: -1

Japt, 25 21 16 bytes

  • 1 => more than
  • -1 => less than
  • 0 => equal

£"78920"bXÉÃr- g

Try it online!