# The Lucky House

There's a minigame in Super Mario 3D World known as the Lucky House. It consists of a slot machine with 4 blocks.

Each block may be one of 5 different icons (Flower, Leaf, Bell, Cherry or Boomerang) and the goal of the player is to get as many identical icons as possible (see a video).

The player is rewarded with coins, which in turn may be converted into extra lives. Your task is to compute the number of extra lives won.

Depending on the number of icons that match, the amount of coins rewarded are as follows:

• No matches - 10 coins
• One pair - 100 coins
• Two pairs - 200 coins
• Three-of-a-kind - 300 coins
• Four-of-a-kind - 777 coins

You win one extra life (1UP) every 100 coins. Therefore, you're guaranteed to win exactly 1UP with one pair, 2UP with two pairs and 3UP with 3-of-a-kind. However, the number of lives won with no matches or 4-of-a-kind depends on your initial coin stock.

Source: Super Mario Wiki

## Input

You're given the initial coin stock $$\0 \le c < 100\$$ and a list of four values $$\[v_1,v_2,v_3,v_4]\$$ representing the final icons on the slot machine.

## Output

The number of extra lives won: $$\0\$$, $$\1\$$, $$\2\$$, $$\3\$$, $$\7\$$ or $$\8\$$.

## Rules

• You may take the icons in any reasonable format: e.g. as a list, as a string or as 4 distinct parameters.
• Each icon may be represented by either a single-digit integer or a single character. Please specify the set of icons used in your answer. (But you don't have to explain how they're mapped to Flower, Leaf, Bell, etc., because it doesn't matter at all.)
• You are not allowed to remap the output values.
• This is 🎰🎰.

## Test cases

In the following examples, we use a list of integers in $$\[1..5]\$$ to represent the icons.

coins  icons      output   explanation
-------------------------------------------------------------------------
0    [1,4,2,5]    0      no matches  ->  0 +  10 =  10 coins -> nothing
95    [3,1,2,4]    1      no matches  -> 95 +  10 = 105 coins -> 1UP
25    [2,3,4,3]    1      one pair    -> 25 + 100 = 125 coins -> 1UP
25    [4,5,5,4]    2      two pairs   -> 25 + 200 = 225 coins -> 2UP
0    [2,5,2,2]    3      3-of-a-kind ->  0 + 300 = 300 coins -> 3UP
22    [1,1,1,1]    7      4-of-a-kind -> 22 + 777 = 799 coins -> 7UP
23    [3,3,3,3]    8      4-of-a-kind -> 23 + 777 = 800 coins -> 8UP
99    [3,3,3,3]    8      4-of-a-kind -> 99 + 777 = 876 coins -> 8UP

• Are we allowed to input the coin count as a float from 0 to 0.99? I'd guess not, but asking just in case. – Grimy Aug 20 at 16:25
• @Grimy No, only an integer (or a string representing this integer). Sorry for the late answer. – Arnauld Aug 20 at 19:05

# x86-16 Assembly, 5641 39 bytes

Binary:

00000000: b103 33ed ac8b fe51 f2ae 7503 45eb f983  ..3....Q..u.E...
00000010: fd03 7504 80c2 4d43 03dd 59e2 e592 7502  ..u...MC..Y...u.
00000020: 040a 3c64 7201 43                        ..<dr.C


Unassembled:

B1 03           MOV  CL, 3              ; set up loop counter for 3 digits
DIGIT_LOOP:
33 ED           XOR  BP, BP             ; clear digit matches counter in BP
AC              LODSB                   ; load next digit char into AL
8B FE           MOV  DI, SI             ; start searching at next char
51              PUSH CX                 ; save outer digit loop counter
MATCH_LOOP:
F2/ AE          REPNZ SCASB             ; search until digit in AL is found
75 03           JNZ  CHECK_FOUR         ; is end of search?
45              INC  BP                 ; if not, a match was found, increment count
EB F9           JMP  MATCH_LOOP         ; continue looping
CHECK_FOUR:
83 FD 03        CMP  BP, 3              ; is four of a kind?
75 04           JNE  SCORE_DIGIT        ; if not, add number of matches to 1UP's
80 C2 4D        ADD  DL, 77             ; add 77 to coin count
43              INC  BX                 ; +1 1UP extra for four-of-a-kind
SCORE_DIGIT:
03 DD           ADD  BX, BP             ; Add number of matches to total, set ZF if 0
59              POP  CX                 ; restore outer digit loop position
E2 E5           LOOP DIGIT_LOOP         ; keep looping
92              XCHG DX, AX             ; coin count to AX for shorter compare
75 02           JNZ  FINAL_SCORE        ; if 1UPs > 0, no consolation prize
04 0A           ADD  AL, 10             ; award 10 coins
FINAL_SCORE:
3C 64           CMP  AL, 100            ; is coin score over 100?
72 01           JB   DONE               ; if not, no extra 1UP
43              INC  BX                 ; otherwise, increment 1UP
DONE:


Input starting coin count in DX, SI pointing to start of "icon" bytes (which can be '1'-'5', or any byte value). Output the number of 1UP's in BX.

Explanation:

The input of four bytes is iterated and compared to the remaining bytes to the right, counting the number of matches. The scores for each type of match are awarded and add up to the total. Since a four-of-a-kind is also three-of-a-kind and also a one-pair, the value of each score type can be decomposed as follows:

• 3 matches = 4 1UP's + 77 coins
• 2 matches = 2 1UP's
• 1 match = 1 1UP

Examples:

[2, 2, 2, 2] (four-of-a-kind) = 7 1UP's + 77 coins

2 [2, 2, 2] = 3 matches = 4 1UP's + 77 coins
2 [2, 2] = 2 matches = 2 1UP's
2 [2] = 1 match   = 1 1UP


[2, 5, 2, 2] (three-of-a-kind) = 3 1UP's

2 [5, 2, 2] = 2 matches = 2 1UP's
5 [2, 2] = 0 matches
2 [2] = 1 match   = 1 1UP


[4, 5, 5, 4] (two pair) = 2 1UP's

4 [5, 5, 4] = 1 match   = 1 1UP
5 [5, 4] = 1 match   = 1 1UP
5 [4] = 0 matches


[2, 3, 4, 3] (one pair) = 1 1UP

2 [3, 4, 3] = 0 matches
3 [4, 3] = 1 match   = 1 1UP
4 [3] = 0 matches


If number of earned 1UP's is 0 at the end, 10 coins are awarded. If total coins are greater than 100, an additional 1UP is awarded.

Here is a test program for PC DOS that includes extra routines to handle the integer value I/O:

# Jelly,  23 22 20  19 bytes

-1 thanks to Erik the Outgolfer (use ³ in place of ȷ2) also used in newer version twice
-1 thanks to Grimy (subtract one before summing instead of subtracting four afterwards)

Maybe beatable?

ċⱮ’SṚḌH×³«777»⁵+:³


A dyadic Link accepting a list and an integer which yields an integer.

Try it online! Or see a test-suite.

### How?

ċⱮ’SṚḌH×³«777»⁵+:³ - Link: list a, integer n   e.g. [x,x,x,x], 22
Ɱ                 - map across a with:
ċ                   -   count occurrences in a       [4,4,4,4]
’                - decrement                      [3,3,3,3]
S               - sum (call this s)              12
Ṛ              - reverse (implicit toDigits)    [2,1]
Ḍ             - un-decimal                     21
H            - halve                          10.5
³          - 100                           100
×           - multiply                     1050
777      - 777                           777
«         - minimum                       777
⁵    - 10                             10
»     - maximum                       777  (handles 0 -> 10)
³ - 100                           100
:  - integer division                7


How the hand evaluation works for each type of hand:

           Hand:    no-pair     pair        2-pair      trips       4-of-a-kind
(sorted) counts:    [1,1,1,1]   [1,1,2,2]   [2,2,2,2]   [1,3,3,3]   [4,4,4,4]
decrement:    [0,0,0,0]   [0,0,1,1]   [1,1,1,1]   [0,2,2,2]   [3,3,3,3]
sum:    0           2           4           6           12
reversed:    [0]         [2]         [4]         [6]         [2,1]
un-decimal:    0           2           4           6           21
halved:    0           1           2           3           10.5
times 100:    0           100         200         300         1050
min(x, 777):    0           100         200         300         777
max(x, 10):    10          100         200         300         777


Alternative 20: ĠẈị“¡ıKĖ‘S×4+E{»⁵+:³

# Zsh, 117 ... 60 bytes

-13 by using a different criterion for differentiation, -9 by combining cases, -28 by changing the case statement to a nested arithmetic ternary, -4 thanks to @JonathanAllan, -1 by optimizing the ternaries, -2 because I accidentally used echo when adding Jonathan's optimization.

Takes coin count on stdin, and block inputs as arguments. Arguments can be numbers, characters, or even strings: ./foo.zsh flower leaf flower boomerang

read c
for i;for j;((a+=i<j))
<<<$[!a?7+(c>22):a-6?6-a:c>89]  Try it online: 117 104 95 67 63 62 60 Here's the magic from the 67 byte answer: read coins for block # for each element (( a+=${#${@:#$block}} ))
#          ${@:#$block}      remove all elements which don't match
#       ${# } count the remaining elements # (( a+= )) add that number to the total <<<$[a?(a-12?6-a/2:coins>89):7+(coins>22)]
#    a?                     :7+(coins>22)  4*0 (all elements match all elements)
#      (a-12?     :coins>89)               4*3 (all elements match exactly one)
#      (a-12?6-a/2         )               3*1 + 1*3 ->  6, 6 -  6/2 -> 3
#                                          2*2 + 2*2 ->  8, 6 -  8/2 -> 2
#                                          2*3 + 2*2 -> 10, 6 - 10/2 -> 1


# C# (Visual C# Interactive Compiler), 123106 90 bytes

a=>b=>(a+("Ĭ̉Èd\n"[(b=b.GroupBy(x=>x,(o,p)=>p.Count())).Count()*(b.Max()==3?0:1)]))/100


A port of my python answer, which is derived from @Dat's answer.

Try it online!

# Python 2, 63 bytes

lambda x,l:int([3,1,7.77,2,.1][sum(map(l.count,l))%14%5]+x/1e2)


Try it online!

I had the same idea as GammaFunction to use sum(map(l.count,l)) as a "fingerprint". But, instead of using an arithmetic formula on the result, I use a lookup table, first squishing the value to 0 through 4 using a mod chain %14%5. Dividing all the point values by 100 saved a few bytes.

• 62 bytes in Python 3? – Arnauld Aug 17 at 8:57
• or 61 bytes with a single mod. – Arnauld Aug 17 at 10:55
• (Ah... Didn't notice that it's actually what Embodiment of Ignorance is doing.) – Arnauld Aug 17 at 11:21

# Python 3, 68 bytes

def f(c,a):x=sum(map(a.count,a))//2;return[c//90,x-2,7+(c>22)][x//3]


Try it online!

A Python port of my C port of my Bash port of my Zsh answer, re-golfed with help from the "Tips for golfing in Python" page. Last port, I swear... I'm running out of languages I'm comfortable golfing in. I was curious how this strategy compared to the other Python answers. Again, there's probably some way to beat this.

This one turned out surprisingly good, so I added a table below summarizing what's happening so others can port or improve this.

Type          Example  map(a.count,a)  sum(__)   x=__//2  x//3   array lookup
----------------------------------------------------------------------------
none         [1,2,3,4]    [1,1,1,1]        4       2       0      c//90
pair         [1,1,2,3]    [2,2,1,1]        6       3       1      x-2 -> 1
two pair     [1,3,1,3]    [2,2,2,2]        8       4       1      x-2 -> 2
3-of-a-kind  [1,3,1,1]    [3,1,3,3]       10       5       1      x-2 -> 3
4-of-a-kind  [3,3,3,3]    [4,4,4,4]       16       8       2      7+(c>22)


## Python 3.8 (pre-release), 63 bytes

Praise the := walrus!

lambda c,a:[2+c//90,x:=sum(map(a.count,a))//2,9+(c>22)][x//3]-2


Try it online!

# Perl 6, 48 44 bytes

{*/100+((0,0,1,3,7.77)[.Bag{*}].sum||.1)+|0}


Try it online!

Curried function f(icons)(coins).

# Python 2, 9691 89 bytes

-2 bytes thanks to @Kevin Cruijssen

lambda x,a,b,c,d:(x+(100*sum((a==b,a==c,a==d,b==c,b==d,c==d))or 10)+177*(a==b==c==d))/100


Try it online!

• Ah. I missed that. Thanks. – Hiatsu Aug 17 at 0:56
• You can remove one pair of parenthesis around (100*sum((a==b,a==c,a==d,b==c,b==d,c==d)) for -2 bytes. – Kevin Cruijssen Aug 19 at 11:15

# PHP, 153 127 bytes

@640KB made some really clever changes to shorten it further:

function($c,$s){for(;++$x<6;$n+=$m>3?777:($m>2?300:($m>1)*100))for($m=!$y=-1;++$y<5;$m+=$s[$y]==$x);return($c+($n?:10))/100|0;}


Try it online!

• Hi @XMark, welcome to CGCC! Nice submission! I golfed it a bit more and got you -26 bytes 127 bytes, TIO. Keep 'em coming! – 640KB Aug 19 at 16:58

# Python 3, 126111108 103 bytes

def f(c,a):x=sorted([a.count(i)for i in set(a)]);return([300,777,200,100,10][len(x)*(x[-1]!=3)]+c)//100


Try it online!

• 80 bytes with python 3.8: tio.run/… – Embodiment of Ignorance Aug 17 at 3:03
• @EmbodimentofIgnorance You removed so many bytes that you might as well write your own answer 😀 – Dat Aug 17 at 3:04

# Python 3.8 (pre-release), 78 bytes

lambda c,a:(ord("Ĭ̉Èd\n"[len(x:=[*map(a.count,{*a})])*(max(x)!=3)])+c)//100


Try it online!

# Perl 5-pF, 46 bytes

map$q+=$$_++,@F;_=0|<>/100+(q>5?7.77:q||.1)  Try it online! First of input is the spin result, using any 5 unique ASCII letters, except q (I suggest abcde). The second line of input is the current coin count. ## How? -F # CLI option splits the input into individual characters in @F map q+= # q holds the result of the calculation here # possible values are 0,1,2,3,6$$_ # This interprets$_ as a variable reference, thus if $_ is 'a', this variable is$a
++     # increment after adding it to $q ,@F; # iterate over the elements of @F$_=0|     # force the result to be an integer
<>/100 # divide the current coin count by 100
+($q>5?7.77 # if$q is over 5, then there must have been 4 of a kind
:$q||.1) # otherwise, use$q, unless it is 0, then use .1
-p        # CLI option implicitly outputs $_  All of the numbers involved are divided by 100, so the program is counting the number of lives (including partial ones) currently earned. The trick to this solution is in the map. If the possible entries are abcde, then each of $a, $b, $c, $d, and $e hold the count of the number of times this character had previously been seen. That gets added to a running total ($q) each time a character is seen. The running total is bumped up if there is a four of a kind (effectively a 177 coin bonus). • Can you include explanation of how this works, please? – msh210 Aug 17 at 21:26 • @msh210 I've tried to add one as best I can. Please feel free to ask questions about it. – Xcali Aug 21 at 3:31 # JavaScript (Node.js), 64 bytes c=>a=>[,7.77,a.sort()[1]-a[2]?2:3,1,.1][new Set(a).size]+c*.01|0  Try it online! I figured there had to be at least one JavaScript answer to an Arnauld challenge! The concept here is mainly to use the number of distinct elements as a lookup key. • 1 unique => 4 of a kind • 2 unique => 2 pair or 3 of a kind • 3 unique => 1 pair • 4 unique => no matches In order to distinguish between 2 pair and 3 of a kind, the input array is sorted and the middle 2 elements are compared. # PHP, 89 84 bytes foreach(count_chars($argv[2])as$a)$b+=[2=>1,3,7.77][$a];echo$argv[1]/100+($b?:.1)|0;  Try it online! Input from command line, output to STDOUT: $ php lucky.php 99 3333
8

$php lucky.php 0 2522 3$ php lucky.php 0 abaa
3


# Stax, 23 bytes

¿^∩û:¶á☺ⁿ£z⌐└≤♂EM¥t(,5╓


Run and debug it

This program uses any arbitrary set of 5 integers for icons.

### Procedure:

1. Add up the number of occurrences of each element.
2. Divide by 2 and then mod 7.
3. The result is a number from 1..5. Use this to look up the coin prize in a fixed array.
4. Add to the initial coin count.
5. Divide by 100.

Here's the output from an experimental stack state visualizer I've been working on for the next release of stax. This is an unpacked version of the same code with the stack state added to comments.

c               input:[2, 3, 4, 3] 25 main:[2, 3, 4, 3]
{[#m            input:[2, 3, 4, 3] 25 main:[1, 2, 1, 2]
|+              input:[2, 3, 4, 3] 25 main:6
h7%             input:[2, 3, 4, 3] 25 main:3
":QctI*12A"!    input:[2, 3, 4, 3] 25 main:[300, 777, 10, 100, 200] 3
@               input:[2, 3, 4, 3] 25 main:100
a+              main:125 [2, 3, 4, 3]
AJ/             main:1 [2, 3, 4, 3]


Run this one

# Retina 0.8.2, 72 bytes

O\D
(\D)\1{3}
777¶
(\D)\1\1
300¶
(\D)\1
100¶
\D{4}
10¶
\d+\D*
$* 1{100}  Try it online! Link includes test cases. Takes input as 4 printable ASCII non-digits followed by the initial number of coins in digits. Explanation: O\D  Sort the non-digits so that identical symbols are grouped together. (\D)\1{3} 777¶  Four-of-a-kind scores 777. (\D)\1\1 300¶  Three-of-a-kind scores 300. (\D)\1 100¶  Each pair scores 100, so two pairs will score 200. \D{4} 10¶  If there were no matches then you still win! \d+\D*$*


Convert the values to unary and take the sum.

1{100}


Integer divide the sum by 100 and convert back to decimal.

# Retina, 56 bytes

(\D)\1{3}
777¶
w(\D).*\1
100¶
\D{4}
10¶
\d+\D*
*
_{100}


Try it online! Link includes test cases. Takes input as 4 printable ASCII non-digits followed by the initial number of coins in digits. Explanation:

(\D)\1{3}
777¶


Four-of-a-kind scores 777.

w(\D).*\1
100¶


Each pair scores 100. The w takes all pairs into consideration, so that they can be interleaved, plus three-of-a-kind can be decomposed into three pairs, thus automagically scoring 300.

\D{4}
10¶


If there were no matches then you still win!

\d+\D*
*


Convert the values to unary and take the sum.

_{100}


Integer divide the sum by 100 and convert back to decimal.

# APL+WIN, 42 bytes

Prompts for icons followed by coin stock.

  ⌊(.01×⎕)+.1⌈+/1 3 7.77×+⌿(+⌿⎕∘.=⍳5)∘.=1↓⍳4


Try it online! Courtesy of Dyalog Classic

# Bash, 76 75 71 70 bytes

-4 thanks to @JonathanAllan, -1 by rearranging the ternary.

read c
for i;{ for j;{ ((a+=i<j));};}
echo $[!a?7+(c>22):a-6?6-a:c>89]  Bash port of my Zsh answer. Try it online! Try it online! Try it online! Try it online! • Save 4 using less-than in place of not-equal here too. – Jonathan Allan Aug 17 at 21:32 • @JonathanAllan This even saves 4 on my Zsh answer, thanks. – GammaFunction Aug 17 at 22:16 # C (gcc), 92 84 82 81 79 78 bytes -1 by x+=(..!=..) -5 by returning via assignment, -4 thanks to Jonathan Allan by replacing != with <, which saves bytes elsewhere, -1 by rearranging the ternary. From @ceilingcat: -2 by declaring i and x outside the function, -1 by setting x=i and decrementing x instead. i,x;f(c,a)int*a;{for(i=x=16;i--;)x-=a[i/4]>=a[i%4];c=x?x-6?6-x:c>89:7+(c>22);}  Another port of my Zsh answer. I'm unfamiliar with C golfing, there's probably another trick somewhere in here to reduce it further. 92 84 82 81 79 Try it online! • Save 4 using less than in place of not equal: x+=a[i/4]<a[i%4];c=x?(x-6?6-x:c>89):7+(c>22); – Jonathan Allan Aug 17 at 21:31 # 05AB1E, 2019 18 bytes D¢<OR;т*777T)Åm+т÷  Port of @JonathanAllan's Jelly answer, so make sure to upvote him!! -2 bytes thanks to @Grimy. Takes the list of icons as first input (being [1,2,3,4,5]), and the amount of coins as second input. Try it online or verify all test cases. (The test suite uses T‚à+ instead of TMI+, which is an equal bytes alternative.) Explanation: D # Duplicate the first (implicit) input-list ¢ # Count the amount of occurrences in itself < # Decrease each count by 1 O # Sum these R # Reverse it ; # Halve it т* # Multiply by 100 777 # Push 777 T # Push 10 ) # Wrap all three values into a list Åm # Get the median of these three values + # Add the second (implicit) input to it т÷ # And integer-divide it by 100 # (after which the result is output implicitly)  • @Grimy Ah, of course. Thanks! I suggested the same golf in the Jelly answer (crediting you of course). :) – Kevin Cruijssen Aug 19 at 13:19 • Also, 777‚ßTMI can be 777T)Åm. – Grimy Aug 19 at 13:20 • Cheaty 17 (takes the coin count as a float, which i'm pretty sure is not allowed) – Grimy Aug 20 at 15:17 • @Grimy So 0.90 is 90 coins in that case? Since the coin input is guaranteed to be in the range [0,99], you could ask OP whether he'd allow it or not. – Kevin Cruijssen Aug 20 at 15:22 • Yup, 0.90 means 90 coins. I asked the OP about it. In any case, here's another non-cheaty 18. – Grimy Aug 20 at 16:27 # Scala, 88 bytes (c,v)=>(Seq(777,300,200,100,0,10)((v.groupBy(x=>x).map(_._2.size+1).product-5)/2)+c)/100  Try it online! # Charcoal, 30 bytes ≔⊘ΣＥη№ηιηＩ⌊⁺∕θ¹⁰⁰∨⁻η∕²∨›⁸η⁹∕¹χ  Try it online! Link is to verbose version of code. Takes input as the number of coins and an array of any Python comparable values as icons. Explanation: ≔⊘ΣＥη№ηιη  Shamelessly steal @GammaFunction's trick of computing half the sum of counts. ⁻η∕²∨›⁸η⁹  Subtract 2 from the sum, thus resulting in the values 0, 1, 2, 3 appropriately, but for 4-of-a-kind, divide the 2 by 9 first, resulting in 7.777.... ∨...∕¹χ  But if the result is 0, then there were no matches, so replace it with 0.1 instead. (Using a literal doesn't help me here because I would need a separator.) Ｉ⌊⁺∕θ¹⁰⁰...  Divide the initial coins by 100 and add on the winnings, then floor the result and cast to string for implicit output. # Pyth, 32 bytes AQ-@[+K2/G90J/sm/HdH2+9>G22)/J3K  Try it online! Inspired by GammaFunction's solution. Takes input as [coins, [icons]]. AQ # Q is the input. Set G := Q[0], H := Q[1] [ ) # Construct a list from the following entries: +K2/G90 # [0] (K:=2) + G/90 (/ is integer division) J # [1] J:= s # reduce on + ( m H # map entries of H as d on ( /Hd # number of occurences of d in H ) ) / 2 # / 2 +9>G22 # [2] 9 + (G > 22) @ /J3 # Take element at position J/3 - K # Subtract K (=2)  # PowerShell, 94 bytes param($n,$l)$r=@{2=100;3=300;4=777}[($l|group|% c*t)]|?{$_;$n+=$_}
+(($n+10*!$r)-replace'..$')  Try it online! Unrolled: param($nowCoins,$values)$groupCounts=$values|group|% count$rewardedCoins=@{2=100;3=300;4=777}[$groupCounts]|?{$_                          # output matched only
$nowCoins+=$_               # and accumulate
}
$nowCoins+=10*!$rewardedCoins   # add 10 coins if no rewarded conis
+($nowCoins-replace'..$')       # truncate last two digits


# PowerShell, 114 107 bytes

-7 bytes thanks to mazzy

param($n,$l)((((0,.1,1)[+($x=($l|group|% c*t|sort))[2]],2,3)[$x[1]-1],7.77)[$x[0]-eq4]+".$n")-replace'\..*'  Try it online! A big ol' PowerShell-flavored ternary operation built upon grouping and sorting the counts of the input list. The sort is needed because we leverage the fact that the grouped list gets shorter the more repeats there are. In fact, here's all the possible values: (1,1,1,1) (1,1,2) (2,2) (1,3) (4)  Truncating to an int is still expensive. Unrolled: param($n,$l)$x=$l|group|% c*t|sort ((( #Start building a list... (0,.1,1)[+$x[2]],     #where spot 0 holds dummy data or handles no match and 1 pair
2,3)[$x[1]-1], #Overwrite the dummy data with 2-pair or 3-o-k 7.77)[$x[0]-eq4]      #OR ignore all that and use spot 1 because it's a 4-o-k
+".\$n"                #Use that value and add CoinCnt via int-to-string-to-decimal
)-replace'\..*'          #Snip off the decimal part

• is an empty string allowed instead 0? Try it online! – mazzy Aug 20 at 8:08
• another variant Try it online! – mazzy Aug 20 at 8:20

# Wolfram Language (Mathematica), 54 bytes

⌊{,.1,1,2,3,,,7.77}[[Total[Counts@#2^2]/2]]+.01#⌋&


Try it online!

# R, 102, 91, 81 bytes

f=function(b,v,s=table(v))(477*any(s>3)+b+10*all(s<2))%/%100+sum(s==2)+3*any(s>2)


Managed to drop 11 bytes (and fix a bug) thanks to @Giuseppe. Managed a further 10 inspired by by @Giuseppe's /10 idea.

Ungolfed

f=function(b,v){
s = table(v)          #included in fn inputs
a = b+10*all(s<2)     #covers all different case
a = a+477*any(s>3)    #Covers 4 of a kind
d = sum(s==2)+3*any(s>2) #covers 1 and 2 pair, 3 of a kind.
a%/%100+d         #sum appropriate values
}


Try it online!

• This doesn't seem to pass the last test case – Giuseppe Aug 19 at 21:25
• but if you can figure out why that is, you can remove the as.factor() and the f= to get it to 88 bytes. – Giuseppe Aug 19 at 21:26
• Ah -- good catch, I seem to have done my math wrong. And top tip on table -- i'm not as familiar with it as I ought to be -- I started with summary(as.factor(v)). I prefer to leave the f=. I don't feel like the code is complete without it, but I realize thats a style choice. – user5957401 Aug 20 at 15:29
• If you say so. This is 87 bytes, including the f=; feel free to put a TIO link into you answer :-) – Giuseppe Aug 20 at 15:49
• I like the split out. As I was toying with it, I figured out that sum(s==2) helps a lot. But it required re-writing everything else, and the /10 no longer saved space (I don't think) – user5957401 Aug 21 at 20:43

# 8051 Assembly (compiles to 158 bytes)

This is a VEEEEEEEEEERRY naive approch, this is yet untested and ungolfed but im pretty confident that works. Things to consider are:

1) the 8051 is an accumulator machine ie. it needs mov instructions that other architectures may not need at all.

2) the 8051 is an 8bit machine therefor there has to be done some trickery for the numbers >255 which makes for more code and is therefor a disadvantage of the platform over the others.

CSEG AT 0000H

coinStackOnes equ 0xf3
coinStackTens equ 0xf4
coinStackHundreds equ 0xf5 ; leave one byte as guard so that if that gets corrupted it doesnt really matter

values1 equ 0xf7
values2 equ 0xf8
values3 equ 0xf9
values4 equ 0xfa

numOfFlowers equ 0xfb
numOfLeaf equ 0xfc
numOfBell equ 0xfd
numOfCherry equ 0xfe
numOfBoomerang equ 0xff

flower equ 1
leaf equ 2
bell equ 3
cherry equ 4
boomerang equ 5

mov r1, #4
mov r0, numOfFlowers
clearNumOfRegs: mov @r0, #0d
inc r0
djnz r1, clearNumOfRegs
;if you reach this all numOfXXXX registers are zeroed

mov r0, #values1
mov r1, #flower

mov a, #6 ; innercounter
mov b, #5 ; outercounter
checkfornextpossibleitem:   mov r2, a; backup countervar
mov a, @r0 ; store given value in a
xrl a, @r1 ; xor a with item
jnz nextItem ; if value!=item -> nextitem
mov a, #numOfFlowers ;if you end up here a=0 (ie value == item) --> generate addr for numOfReg <-- load a with addr for numOfFlowers
xch a, r1 ; change the item with the addr as r1 is indirect register
inc @r1 ; increment numOfRegister
xch a, r1; r1 = item
;next item
nextItem:   inc r1 ; increment item
mov a, r2 ; restore counter
dec a; decrement counter
cjne a, #0, checkfornextpossibleitem
;if you reach this you have successfully tested one value against all items and therefor the next value must be tested
mov a, #6; reset the innercounter
dec b; decrement the outercounter
inc r0; increment the register that points to the value-under-test
xch a,b; cjne works with a but not with b therefor exchange them
cjne a, #0, here ; do the comparison; if you dont jump here you have tested all values
jmp howManyPairsDoIHave; if you didnt jump above you have the now the number of flowers and so on
here:   xch a,b ; and change back
jmp checkfornextpossibleitem ; check the next value
howManyPairsDoIHave:    mov r0,#0; store numOfPairsHere initialize with zeros
mov r1, numOfFlowers;
mov b, #6; use as counter to know when you went through all numOfRegisters
analyseNumOfRegister:   mov a, @r1 ; load the numOfregister for some math
xrl a, #2; a will contain zero if numOfXXX = 2
jnz numOfXXXWasNot2; if you do not jump here you have 2 XXX therefor
inc r0; increment the number of pairs
jmp nextNumOfRegister; continiue with the next one
numOfXXXWasNot2:    mov a, @r1; restore the number of XXX and try the next magic value
xrl a, #3; will contain zero if you have a three of a kind
jnz no3XXX; if you dont jump here however you have a three of a kind
no3XXX:     mov a, @r1; restore number of XXX
xrl a, #4; a will contain zero if 4 of a kind
jnz nextNumOfRegister; if you numOfXXX!=4 you can only continiue trying to find something in the next numof register
jz add777Coins; if you didnt jump above how ever you will have to add the 777 coins as you detected a 4 of a kind
nextNumOfRegister:  inc r0; move pointer to the next numofregister
djnz b, analyseNumOfRegister; if you havent already analysed all numofregisters then continue
; if you have however you end up here so you will have to take a look at the numOfPairs
cjne r0, #1, tryIf2Pairs; test if you have 1 pair if not try if you have 2
jmp add100Coins; if you have 1 pair however add the 100 coins
tryIf2Pairs:    cjne r0, #2, youMustHave0Pairs; test if you have 2 pairs if not you can be sure to have 0 of them
inc coinStackTens
mov a, coinStackTens
cjne a, #10d, howManyHearts ; if your tens digit isnt outta range continue with the calculation of the number of hearts
inc coinStackHundreds; if it is outta range do correct that
mov coinStackTens, #0
jmp howManyHearts;
add100Coins:    inc coinStackHundreds; here the digit can not possibly have an invalid value...
jmp howManyHearts
mov coinStackHundreds, a
jmp howManyHearts ; also here no invalid values possible
mov coinStackHundreds, a
jmp howManyHearts ; same again
mov r2, #3
mov r1, a
mov a, @r0
mov b, a; b contains the possibly invalid version of the ones digit
da a; if you have an invalid value its lower nibble gets corrected this way
anl a, 0x0f; and the higher one gets corrected this way
xch a,b; a and b must be swapped in order to make subb work ie b contains now the corrected value and a has the maybe faulty value
subb a,b; returns zero if all the corrections had no effect therefor the next digit can be increased by 7
jz nextDigit
inc r1
inc @r1
nextDigit:  inc r0
`