W Super Mario 3D World jest minigra znana jako Lucky House . Składa się z automatu z 4 blokami.
Każdy blok może być jedną z 5 różnych ikon (Kwiat, Liść, Dzwon, Wiśnia lub Bumerang), a celem gracza jest uzyskanie jak największej liczby identycznych ikon ( zobacz wideo ).
Gracz jest nagradzany monetami, które z kolei mogą zostać zamienione na dodatkowe życia. Twoim zadaniem jest obliczenie liczby wygranych dodatkowych żyć.
W zależności od liczby pasujących ikon ilość nagradzanych monet jest następująca:
- Bez zapałek - 10 monet
- Jedna para - 100 monet
- Dwie pary - 200 monet
- Trójka - 300 monet
- Cztery w swoim rodzaju - 777 monet
Wygrywasz jedno dodatkowe życie (1UP) na 100 monet . Dlatego masz gwarancję wygrania dokładnie 1UP za jedną parę , 2UP za dwie pary i 3UP za jedyne w swoim rodzaju . Jednak liczba wygranych żetonów bez meczów lub 4-w swoim rodzaju zależy od początkowego stanu monet.
Źródło: Super Mario Wiki
Wkład
Otrzymujesz początkowe zapasy monet oraz listę czterech wartości reprezentujących końcowe ikony na automacie.
Wydajność
Liczba wygranych dodatkowych żyć: , , , , lub .
Zasady
- Możesz wziąć ikony w dowolnym rozsądnym formacie: np. Jako lista, jako ciąg znaków lub jako 4 różne parametry.
- Każda ikona może być reprezentowana przez jednocyfrową liczbę całkowitą lub pojedynczy znak . Podaj zestaw ikon używanych w odpowiedzi. (Ale nie musisz wyjaśniać, w jaki sposób są mapowane na Kwiat, Liść, Dzwon itp., Ponieważ to nie ma żadnego znaczenia).
- Nie wolno ponownie mapować wartości wyjściowych.
- To jest 🎰 code-golf 🎰.
Przypadki testowe
W poniższych przykładach używamy listy liczb całkowitych w do przedstawienia ikon.
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
źródło
Odpowiedzi:
x86-16 Assembly,
564139 bytesBinary:
Unassembled:
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 inBX
.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:
Examples:
[2, 2, 2, 2]
(four-of-a-kind) = 7 1UP's + 77 coins[2, 5, 2, 2]
(three-of-a-kind) = 3 1UP's[4, 5, 5, 4]
(two pair) = 2 1UP's[2, 3, 4, 3]
(one pair) = 1 1UPIf 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:
Download and test LUCKY.COM for DOS.
źródło
Jelly,
23 22 2019 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?
A dyadic Link accepting a list and an integer which yields an integer.
Try it online! Or see a test-suite.
How?
How the hand evaluation works for each type of hand:
Alternative 20:
ĠẈị“¡ıKĖ‘S×4+E{»⁵+:³
źródło
ȷ2
with³
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ċⱮ`’SṚḌH׳«777»⁵+:³
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 usedecho
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
Try it online:
117 104 95 67 63 6260Here's the magic from the 67 byte answer:
źródło
C# (Visual C# Interactive Compiler),
12310690 bytesA port of my python answer, which is derived from @Dat's answer.
Try it online!
źródło
Python 2, 63 bytes
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.źródło
Python 3, 68 bytes
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.
Python 3.8 (pre-release), 63 bytes
Praise the
:=
walrus!Try it online!
źródło
Perl 6,
4844 bytesTry it online!
Curried function
f(icons)(coins)
.źródło
Python 2,
969189 bytes-2 bytes thanks to @Kevin Cruijssen
Try it online!
źródło
(100*sum((a==b,a==c,a==d,b==c,b==d,c==d))
for -2 bytes.PHP,
153127 bytes@640KB made some really clever changes to shorten it further:
Try it online!
źródło
Python 3,
126111108103 bytesTry it online!
źródło
Python 3.8 (pre-release), 78 bytes
Dat's answer, but golfed more.
Try it online!
źródło
Perl 5
-pF
, 46 bytesTry it online!
First of input is the spin result, using any 5 unique ASCII letters, except
q
(I suggestabcde
). The second line of input is the current coin count.How?
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 areabcde
, 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).źródło
JavaScript (Node.js), 64 bytes
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.
In order to distinguish between 2 pair and 3 of a kind, the input array is sorted and the middle 2 elements are compared.
źródło
PHP,
8984 bytesTry it online!
Input from command line, output to
STDOUT
:źródło
Stax, 23 bytes
Run and debug it
This program uses any arbitrary set of 5 integers for icons.
Procedure:
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.
Run this one
źródło
Retina 0.8.2, 72 bytes
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:
Sort the non-digits so that identical symbols are grouped together.
Four-of-a-kind scores 777.
Three-of-a-kind scores 300.
Each pair scores 100, so two pairs will score 200.
If there were no matches then you still win!
Convert the values to unary and take the sum.
Integer divide the sum by 100 and convert back to decimal.
źródło
Retina, 56 bytes
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:
Four-of-a-kind scores 777.
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.If there were no matches then you still win!
Convert the values to unary and take the sum.
Integer divide the sum by 100 and convert back to decimal.
źródło
APL+WIN, 42 bytes
Prompts for icons followed by coin stock.
Try it online! Courtesy of Dyalog Classic
źródło
Bash,
76 75 7170 bytes-4 thanks to @JonathanAllan, -1 by rearranging the ternary.
Bash port of my Zsh answer.
Try it online! Try it online! Try it online!Try it online!źródło
C (gcc),
92 84 82 81 7978 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
andx
outside the function, -1 by settingx=i
and decrementingx
instead.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 79Try it online!źródło
x+=a[i/4]<a[i%4];c=x?(x-6?6-x:c>89):7+(c>22);
05AB1E,
201918 bytesPort 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 ofTMI+
, which is an equal bytes alternative.)Explanation:
źródło
777‚ßTMI
can be777T)Åm
.0.90
is90
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.Scala, 88 bytes
Try it online!
źródło
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 values0, 1, 2, 3
appropriately, but for 4-of-a-kind, divide the2
by9
first, resulting in7.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.
źródło
Pyth, 32 bytes
Try it online!
Inspired by GammaFunction's solution. Takes input as
[coins, [icons]]
.źródło
PowerShell, 94 bytes
Try it online!
Unrolled:
źródło
PowerShell,
114107 bytes-7 bytes thanks to mazzy
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:
Truncating to an int is still expensive.
Unrolled:
źródło
0
? Try it online!Wolfram Language (Mathematica), 54 bytes
Try it online!
źródło
R,
102,91, 81 bytesManaged to drop 11 bytes (and fix a bug) thanks to @Giuseppe. Managed a further 10 inspired by by @Giuseppe's /10 idea.
Ungolfed
Try it online!
źródło
as.factor()
and thef=
to get it to 88 bytes.table
-- i'm not as familiar with it as I ought to be -- I started withsummary(as.factor(v))
. I prefer to leave thef=
. I don't feel like the code is complete without it, but I realize thats a style choice.f=
; feel free to put a TIO link into you answer :-)sum(s==2)
helps a lot. But it required re-writing everything else, and the /10 no longer saved space (I don't think)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.
źródło