Gioco d'azzardo Mid-Autumn Festival


11

Domani è il festival di metà autunno e, nello spirito di quella vacanza, presenterò un gioco d'azzardo a cui noi (persone di Xiamen ) giochiamo durante le vacanze!

Regole

Il gioco si gioca con sei dadi a 6 facce. Diverse combinazioni di numeri hanno ranghi diversi, con un'enfasi speciale su quattro e uno. Il tuo compito è quello di scrivere un programma / funzione che classifichi la mano, dato un tiro di 6 dadi. Ecco i gradi (ho modificato / semplificato un po 'le regole):

ranghi

Immagino che solo i cinesi possano fare questa sfida! Bene, ecco alcune spiegazioni in inglese.

  • 0: 4 quattro e 2.
  • 1: 6 a quattro zampe.
  • 2: 6 quelli.
  • 3: 6 di qualsiasi tipo tranne quelli a quattro e uno.
  • 4: 5 a quattro zampe.
  • 5: 5 di qualsiasi tipo tranne che per i quattro.
  • 6: 4 a quattro zampe.
  • 7: dritto. (1-6)
  • 8: 3 a quattro zampe.
  • 9: 4 di qualsiasi tipo tranne 4.
  • 10: 2 a quattro zampe.
  • 11: 1 quattro.
  • 12: niente.

Ingresso

6 numeri, una matrice di 6 numeri o una stringa di 6 numeri che rappresentano i valori dei 6 tiri di dado da 1 a 6

Produzione

Il tuo programma / funzione può restituire / produrre qualsiasi cosa per indicare il rango, purché ogni rango sia indicato da un output e viceversa. Ex. Usando i numeri 0-12, 1-13, ecc.

Esempi (utilizzo di 0-12 come output)

[1,1,1,1,1,1]->2
[1,4,4,4,1,4]->0
[3,6,5,1,4,2]->7
[1,2,3,5,6,6]->12
[3,6,3,3,3,3]->5
[4,5,5,5,5,5]->5

Questo è code-golf, quindi vince il conteggio dei byte più breve!


(Avrei messo questo nella sandbox, ma volevo che i tempi fossero corretti. Ho cercato di essere il più accurato possibile, per favore fatemi sapere se ci sono dei chiarimenti necessari.)
— Quintec

@Shaggy Quindi l'OP dice che invece
— produce

@Shaggy Come ho affermato nella domanda, l'output non deve necessariamente corrispondere al numero di etichetta. Il numero saltato e le lacune casuali nell'immagine servono a semplificare un po 'le regole - non ci sono davvero regole definite per questa tradizione, questa è solo la mia interpretazione.
— Quintec,

Non dovrebbe essere [1,2,3,5,6,6]->13??
— J.Doe,

@ J.Doe Gli esempi / casi di test utilizzano gli indici come risultato anziché i valori. A differenza dei valori, 10non viene ignorato.
— Kevin Cruijssen,

Risposte:


2

Carbone , 55 byte

≡⌈Eθ№θι⁶I⁻²⌕14§θχ⁵I⁻⁵⁼⁵№θ4⁴⎇⁼№θ4⁴§60⁼№θ1²9¹7I⁻¹²⌊⊘X²№θ4

Provalo online! Il collegamento è alla versione dettagliata del codice. Non salta 10. Spiegazione:

≡⌈Eθ№θι

Calcola la frequenza più alta di qualsiasi cifra.

⁶I⁻²⌕14§θχ

Se esiste un 6 di un tipo, sottrarre la posizione della cifra nella stringa 14da 2. Ciò si traduce in 1 per 6 4 s, 2 per 6 1 s e 3 per 6 di qualsiasi altra cosa.

⁵I⁻⁵⁼⁵№θ4

Se c'è un 5 di un tipo, il risultato è 5 a meno che non ci siano 5 4s, nel qual caso viene sottratto 1.

⁴⎇⁼№θ4⁴§60⁼№θ1²9

Se c'è un 4 di un tipo, allora se ci sono 4 4, il risultato è 6 a meno che non ci siano 2 1 nel qual caso il risultato è 0, altrimenti il ​​risultato è 9.

¹7

Se tutte le cifre sono diverse, il risultato è 7.

I⁻¹²⌊⊘X²№θ4

Altrimenti il ​​risultato è 12 - (4 >> (3 - # di 4s)).


Sembra essere la migliore pratica di accettare la risposta più breve, quindi è quello che farò :) Purtroppo non molte persone hanno visto e votato la tua risposta ...
— Quintec

@Quintec Non è un problema; le persone dovrebbero valutare le risposte in base all'ingegnosità dell'algoritmo o ad altri fattori che le fanno apprezzare la risposta.
— Neil,

10

JavaScript (ES6), 88 byte

a=>a.map(o=n=>[x=o[n]=-~o[n],6,,,21,9,8^o[1]][a=x<a?a:x])[5]|[,1,4,5,o[1]&2|8,2,4][o[4]]

Provalo online! oppure prova tutti i possibili tiri!

Emette un numero intero secondo il seguente mapping:

 Rank | Output       Rank | Output
------+--------     ------+--------
   0  |  31            7  |   7
   1  |  12            8  |   5
   2  |  14            9  |  21
   3  |   8           10  |   4
   4  |  11           11  |   1
   5  |   9           12  |   0
   6  |  29

Come?

Metodo

L'output viene calcolato eseguendo un OR bit a bit tra:

  • F
  • M

eccezioni:

  • F=44B4un'
  • M=66B6un'

tavolo

FM sono evidenziate in grassetto e blu nella tabella seguente.

F01234un'4B56MO014581024166767141466200145810243001458102442121212121293123215999131391111136un'889121381010126B141415141514141414

M≥3M≤3MF=3

Esempio

M=1F=1

6 O 1=7

77

Commentate

a =>                   // a[] = input array, reused as an integer to keep track of the
  a.map(               //       maximum number of occurrences of the same dice (M)
    o =                // o = object used to count the number of occurrences of each dice
    n =>               // for each dice n in a[]:
    [                  //   this is the lookup array for M-bitmasks:
      x =              //     x = o[n] = number of occurrences of the current dice
        o[n] = -~o[n], //     increment o[n] (we can't have M = 0, so this slot is not used)
      6,               //     M = 1 -> bitmask = 6
      ,                //     M = 2 -> bitmask = 0
      ,                //     M = 3 -> bitmask = 0
      21,              //     M = 4 -> bitmask = 21
      9,               //     M = 5 -> bitmask = 9
      8 ^ o[1]         //     M = 6 -> bitmask = 14 for six 1's, or 8 otherwise
    ][a =              //   take the entry corresponding to M (stored in a)
        x < a ? a : x] //   update a to max(a, x)
  )[5]                 // end of map(); keep the last value
  |                    // do a bitwise OR with the second bitmask
  [                    // this is the lookup array for F-bitmasks:
    ,                  //   F = 0 -> bitmask = 0
    1,                 //   F = 1 -> bitmask = 1
    4,                 //   F = 2 -> bitmask = 4
    5,                 //   F = 3 -> bitmask = 5
    o[1] & 2 | 8,      //   F = 4 -> bitmask = 10 if we also have two 1's, 8 otherwise
    2,                 //   F = 5 -> bitmask = 2
    4                  //   F = 6 -> bitmask = 4
  ][o[4]]              // take the entry corresponding to F (the number of 4's)

5

R , 100 byte

Codifica il punteggio come un insieme di condizionali indicizzati. Più semplice del mio primo approccio a regex.

Modifica - corretto bug e ora classifica tutti i tiri.

function(d,s=sum(d<2))min(2[s>5],c(11,10,8,6-6*!s-2,4,1)[sum(d==4)],c(7,12,12,9,5,3)[max(table(d))])

Provalo online!



2

Python 2 ,  148  119 byte

-27 byte grazie a ovs (1. uso di .countconsentire l' utilizzo di map; 2. rimozione di ridondanti 0in slice; 3. utilizzo di un inanziché di un max; 4. abbreviato (F==4)*O==2in F==4>O==2[da golf a F>3>O>1])

C=map(input().count,range(1,7))
O,F=C[::3]
print[F>3>O>1,F>5,O>5,6in C,F>4,5in C,F>3,all(C),F>2,4in C,F>1,F,1].index(1)

Provalo online!


@ovs oh heh .count> _ <bello
— Jonathan Allan,

Un ultimo suggerimento: poiché dè necessario solo uno, questo è più breve come programma completo .
— Ovs,


@ovs - grazie per tutto il tuo golf. Ne ho salvati altri due per l'avvio.
— Jonathan Allan,

Devi amare il concatenamento condizionale del pitone! Inoltre, la specifica ora non salta il numero 10
— Quintec,

1

Pyth, 60 byte

eS[@[ZhZ2 4*6hq2hJuXtHG1Qm0Q8hT)@J3*5hSJ*Tq6hJ*<3KeSJ@j937TK

Mappe al grado inverso, 0-12. Provalo online qui o verifica tutti i casi di test contemporaneamente qui .

La mappatura completa utilizzata è la seguente:

12: 4 fours and 2 ones.
11: 6 fours.
10: 6 ones.
 9: 6 of any kind except fours and ones.
 8: 5 fours.
 7: 5 of any kind except for fours.
 6: 4 fours.
 5: Straight. (1-6)
 4: 3 fours.
 3: 4 of any kind except 4.
 2: 2 fours.
 1: 1 four.
 0: Nothing.

Funziona mappando i valori dei dadi sulle frequenze, quindi calcolando il valore di diverse regole e prendendo il massimo dell'insieme.

Implicit: Q=eval(input()), Z=0, T=10

JuXtHG1Qm0Q   Input mapping
 u     Q      Reduce each element of the input, as H, ...
        m0Q   ...with initial value, G, as an array of 6 zeroes (map each roll to 0)
   tH           Decrement the dice roll
  X  G1         Add 1 to the frequency at that point
J             Store the result in J

@[ZhZ2 4*6hq2hJuXtHG1Qm0Q8hT)@J3   Rule 1 - Values for sets including 4
  Z                               *0
   hZ                             *1 (increment 0)
     2                            *2
       4                          *4
              JuXtHG1Qm0Q          Input mapping (as above)
             h                     First value of the above - i.e. number of 1's
           q2                      1 if the above is equal to 2, 0 otherwise
        *6h                       *Increment and multiply by 6
                                   Maps to 12 if there are 2 1's, 6 otherwise
                         8        *8
                          hT      *11 (increment 10)
 [                          )      Wrap the 7 starred results in an array
                             @J3   Get the 4th value of the input mapping - i.e. number of 4's
@                                  Get the value at that position in the array

*5hSJ   Rule 2 - Straight
  hSJ   Smallest frequency in input mapping (first, sort, J)
        For a straight, smallest value will be 1, 0 otherwise
*5      Multiply by 5

*Tq6hJ   Rule 3 - 6 1's
    hJ   Frequency of 1's (first value from input mapping)
  q6     1 if the above == 6, 0 otherwise
*T       Multiply by 10

*<3KeSJ@j937TK   Rule 4 - 4,5,6 of a kind, other than 4's
   KeSJ          Get the max frequency from input mapping, store in K
        j937T    [9,3,7]
       @     K   Get the element at K'th position in the above (modular indexing)
 <3K             1 if 3<K, 0 otherwise
*                Multiply the previous 2 results

eS[   Wrapping it all up!
  [   Wrap all the above rules in an array
eS    Take the max value of the above, implicit print

1

Retina , 137 126 byte

4
A
O`.
^11A+
0
1+$
2
^A+
1
(.)\1{5}
3
^.A+
4
.?(.)\1{4}.?
5
^..A+
6
12356A
7
.+AAA$
8
.*(.)\1{3}.*
9
.+AA$
10
.+A$
11
.{6}
12

-11 byte grazie a @Neil .

L'output è 0-indicizzato ( 0..12).

Provalo online o verifica tutti i casi di test .

Spiegazione:

Sostituisci ogni 4 con una 'A':

4
A

Ordina tutte le cifre di input (le A saranno sul retro):

O`.

Ogni altre due righe sostituisce l'input con l'output previsto:

Regex         Replacement  Explanation

^11A+         0            starts with "11", followed by any amount of A's
1+$           2            ends with any amount of 1s
^A+           1            starts with any amount of A's
(.)\1{5}      3            six of the same characters
^.A+          4            starts with any character, followed by any amount of A's
.?(.)\1{4}.?  5            five of the same characters,
                           with optionally a leading or trailing character
^..A+         6            starts with any two characters, followed by any amount of A's
12356A        7            literal "12356A" match
.+AAA$        8            any amount of leading characters, ending with three A's
.*(.)\1{3}.*  9            four of the same characters,
                           with optionally any amount of leading/trailing chars
.+AA$         10           any amount of leading characters, ending with two A's
.+A$          11           any amount of leading characters, ending with a A
.{6}          12           any six characters

1
Molto intelligente, ma penso che tu possa fare un ulteriore passo avanti e sostituirlo 4con qualcosa al di fuori dell'intervallo 1-6per farlo ordinare automaticamente a un'estremità (non sono sicuro che faccia la differenza a quale ordinamento).
— Neil,

@Neil Ah, anche questo è intelligente! Grazie.
— Kevin Cruijssen,

1

05AB1E , 57 55 byte

4¢4@U.M¢©5-Di14¹нk2αë>Di5X-ë>i9X3*-¹1¢2Ê*ë®i7ë¹4¢o;ï12α

La risposta di Port of @Neil Charcoal , perché il mio approccio iniziale era già a 60 byte e non avevo ancora finito. Tuttavia, la mia risposta attuale può probabilmente essere giocata ancora a golf.

Inserire come un elenco di cifre.

Provalo online o verifica tutti i casi di test .

Spiegazione:

4¢              # Count the amount of 4s in the (implicit) input-list
  4@            # Check if it's larger than or equal to 4
                # (results in 1 for truthy; 0 for falsey)
    U           # Pop and store that result in variable `X`
.M              # Push the most frequent number in the (implicit) input-list
  ¢             # Pop and push the count of that number in the (implicit) input-list
   ©            # Store it in the register (without popping)
5-Di            # If the maximum count - 5 is exactly 1 (so the maximum count is 6):
    14          #  Push 14
      ¹н        #  Push the first digit of the input-list
        k       #  Get its index in 14, resulting in -1, 0, or 1
         2α     #  Take the absolute difference with 2
                #  (This covers cases 1, 2, and 3)
ë>Di            # Else-if the maximum count - 5 + 1 is exactly 1 (so the maximum count is 5):
    5           #  Push 5
     X-         #  And subtract variable `X`
                #  (This covers cases 4 and 5)
ë>i             # Else-if the maximum count - 5 + 2 is exactly 1 (so the maximum count is 4):
   9            #  Push 9
    X3*         #  Multiply variable `X` by 3
       -        #  And subtract it from the 9
        ¹1¢     #  Count the amount of 1s in the input-list
           2Ê   #  Check if it's NOT equal to 2 (1 if truthy; 0 if falsey)
             *  #  Multiply it with the 9 or 6
                #  (This covers cases 0, 6, and 9)
ë®i             # Else-if the maximum count is 1:
   7            #  Push a 7
                #  (This covers case 7)
ë               # Else (maximum count is 2 or 3):
 ¹4¢            #  Count the amount of 4s in the input-list
    o           #  Take 2 to the power this count
     ;ï         #  Halve and floor it
       12α      #  And take the absolute difference with 12
                #  (This covers cases 8, 10, 11, and 12)
                # (Output the top of the stack implicitly as result)

0

Rubino , 100 byte

->a{%w(^2.*4$ 6$ ^6 6 5$ 5 4$ ^1*$ 3$ 4 2$ 1$ .).index{|b|/#{b}/=~([1,*a,4].map{|c|a.count(c)}*'')}}

Provalo online!

Come funziona:

Contare le occorrenze di ogni numero nell'array, anteporre il numero di 1 e aggiungere il numero di 4.

Successivamente, prova ad abbinare diversi schemi regex.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.