The Lucky Housemenm0 h32m Jionlisrce Hac
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 🎰code-golf🎰.
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
15 Answers
Zsh, 117 104 95 67 bytes
-13 by using a different criterion for differentiation, -9 by combining cases, -28 by changing the case statement to a nested arithmetic ternary
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 e;((a+=${#${@:#$e}}))
<<<$[a?(a-12?6-a/2:c>89):7+(c>22)]
Try it online!
Try it online!
Try it online!
Try it online!
Here's the magic:
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
Jelly, 23 bytes
Gotta be beatable...
ċⱮ`S×49_ịʋ“Ċ¬ȦṾ¡Ė¡‘+:ȷ2
Try it online! Or see a test-suite.
How?
ċⱮ`S×49_ịʋ“Ċ¬ȦṾ¡Ė¡‘+:ȷ2 - Link: list a, integer n e.g. [x,x,y,x], 99
Ɱ` - map across a with:
ċ - count occurrences in a [3,3,1,3]
S - sum (call this s) 10
“Ċ¬ȦṾ¡Ė¡‘ - code-page indices (call this X) [192,7,190,186,0,194,0]
ʋ - last 4 links as f(s, X):
49 - 49 49
× - multiply (s by 49) 490
ị - index (s) into (X) 190
_ - subtract 300
+ - add (n) 399
ȷ2 - 10^2 = 100 100
: - integer division 3
-
\\$\\begingroup\\$ You can replace
ȷ2with³by assuming the program the function is in doesn't take command-line arguments, although that's not what I think you mean by "beatable". :P \\$\\endgroup\\$ – Erik the Outgolfer 7 hours ago
Python 3, 126 111 108 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!
-
2\\$\\begingroup\\$ 80 bytes with python 3.8: tio.run/… \\$\\endgroup\\$ – Embodiment of Ignorance 14 hours ago
-
1\\$\\begingroup\\$ @EmbodimentofIgnorance You removed so many bytes that you might as well write your own answer 😀 \\$\\endgroup\\$ – Dat 14 hours ago
Python 2, 96 91 bytes
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!
-
\\$\\begingroup\\$ Ah. I missed that. Thanks. \\$\\endgroup\\$ – Hiatsu 17 hours ago
Python 3.8 (pre-release), 78 bytes
lambda c,a:(ord("Ĭ̉Èd\\n"[len(x:=[*map(a.count,{*a})])*(max(x)!=3)])+c)//100
Dat's answer, but golfed more.
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.
-
\\$\\begingroup\\$ 62 bytes in Python 3? \\$\\endgroup\\$ – Arnauld 9 hours ago
-
\\$\\begingroup\\$ or 61 bytes with a single mod. \\$\\endgroup\\$ – Arnauld 7 hours ago
-
\\$\\begingroup\\$ (Ah... Didn't notice that it's actually what Embodiment of Ignorance is doing.) \\$\\endgroup\\$ – Arnauld 6 hours ago
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!
C# (Visual C# Interactive Compiler), 123 106 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!
Stax, 23 bytes
¿^∩û:¶á☺ⁿ£z⌐└≤♂EM¥t(,5╓
Run and debug it
This program uses any arbitrary set of 5 integers for icons.
Procedure:
- Add up the number of occurrences of each element.
- Divide by 2 and then mod 7.
- The result is a number from 1..5. Use this to look up the coin prize in a fixed array.
- Add to the initial coin count.
- 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.
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 characters (I suggest abcde). The second line of input is the current coin count.
Bash, 76 75 bytes
read c
for i;{ for j;{ ((a+=i!=j));};}
echo $[a?(a-12?6-a/2:c>89):7+(c>22)]
Bash port of my Zsh answer.
Try it online!
Try it online!
C (gcc), 92 86 bytes
-1 by x+=(..!=..) -5 by returning via assignment
f(c,a)int*a;{int i=16,x=0;for(;i--;)x+=a[i/4]!=a[i%4];c=x?(x-12?6-x/2: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.
Try it online!
Try it online!
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