-5
\$\begingroup\$

Mama Say Mama Sa Mama Coosa

I'm sure all of you have heard of Michael Jackson and some of you have listened to MJ's song "Wanna be starting something". The line "Mama Say Mama Sa Mama Coosa" is repeated throughout the song.

Specification

In this line, the word "Mama"occurs three times, "Say", "Sa", "Coosa" occurs once. The task is the following: Given the input number of occurrences of the words "Mama", "Say", "Sa", "Coosa", output the number of times MJ can sing "Mama Say Mama Sa Mama Coosa", like in a complete sentence.

Input

Input is a single line with four positive integers denoting the number of times he says the words "Mama", "Say", "Sa","Coosa" respectively .

Output

Output the number of times MJ can sing "Mama Say Mama Sa Mama Coosa"

Shortest code wins.

Testcases

Testcase 1
Input -->  3 1 1 1
Output-->  1


Testcase 2
Input -->  6 1 1 1
Output-->  1

Testcase 3
Input -->  1000 3 2 3
Output-->  2

Testcase 4
Input -->  7 3 4 3
Output-->  2
\$\endgroup\$
  • \$\begingroup\$ I am a bit confused by the specification. It would be nice to include exactly what is being calculated. \$\endgroup\$ – Ad Hoc Garf Hunter Feb 12 '17 at 16:16
  • \$\begingroup\$ Any constraints about the number? Like are they necessary all strictly positive? \$\endgroup\$ – Dada Feb 12 '17 at 16:17
  • 15
    \$\begingroup\$ Just a note. 1 minute in the sandbox isn't enough time for any feedback. \$\endgroup\$ – fəˈnɛtɪk Feb 12 '17 at 16:20
  • 1
    \$\begingroup\$ So, you want the minimum of four numbers where the first is divided by three first? \$\endgroup\$ – John Dvorak Feb 12 '17 at 16:22
  • 4
    \$\begingroup\$ There are already answers so don't delete the question. Next time you should wait for feedback in the sandbox before posting \$\endgroup\$ – fəˈnɛtɪk Feb 12 '17 at 16:23

12 Answers 12

7
\$\begingroup\$

Jelly, 5 bytes

Ḣ:3«Ṃ

Try it online!

How it works

Ḣ:3«Ṃ  Main link. Argument: [a, b, c, d]

Ḣ      Head; pop and yield a.
 :3    Perform integer division by 3,
    Ṃ  Yield the minimum of [b, c, d].
   «   Take the minimum of a and the result to the right.
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Giving you a +1 for :3 \$\endgroup\$ – Okx Feb 12 '17 at 19:46
  • \$\begingroup\$ @Okx Another 5 byte solution, :1¦3Ṃ, and one can bastardise that one into the 6 byte :-3¦3Ṃ \$\endgroup\$ – Jonathan Allan Feb 13 '17 at 9:41
7
\$\begingroup\$

Python 2, 23 bytes

lambda a,*x:min(a/3,*x)

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ What does the asterisk before the x do? \$\endgroup\$ – user41805 Feb 12 '17 at 16:21
  • \$\begingroup\$ Create a function with a variable number of arguments. The first argument becomes a, all remaining ones are stored in the tuple x. \$\endgroup\$ – Dennis Feb 12 '17 at 16:22
  • 1
    \$\begingroup\$ The second time the *x is used it unpacks an array (x) into arguments for min. \$\endgroup\$ – Ad Hoc Garf Hunter Feb 12 '17 at 18:00
3
\$\begingroup\$

MATL, 9 8 bytes

1 byte saved thanks to @Luis

I7Bh/kX<

Try it at MATL Online

Explanation

        % Implicitly grab input as an array
I       % Push the literal 3 to the stack
7B      % Push 7 and convert to binary ([1, 1, 1]) and push it to the stack
h       % Horizontally concatenate the two to create the array [3 1 1 1]
/       % Perform element-wise division
k       % Round all values towards minus infinity
X<      % Compute the minimum of the resulting array
        % Implicitly display the result
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Perl 6, 19 bytes

{min $^a div 3,|@_}

Try it online!

How it works

{                 }  # A lambda.
     $^a             # First argument.
         div 3       # Integer division by 3.
                @_   # All regaining arguments as a list.
        ,      |     # Slipped into the outer list.
 min                 # Smallest number in the list.

The $^a and @_ are in-place parameter declarations for the surrounding block lambda. One is a positional parameter, and the other to a slurpy parameter that takes all remaining positional arguments.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

MATLAB / Octave, 26 bytes

@(a)min(fix(a./[3 1 1 1]))

Creates an anonymous function named ans which you can then pass the input array as: ans([3 1 1 1])

Online Demo

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Cubix, 24 bytes

O;@sI3,>I?;^>..^.-!..;;?

Try it here

    O ;
    @ s
I 3 , > I ? ; ^
> . . ^ . - ! .
    . ;
    ; ?

I Read number from the input
3, Push 3 onto the stack and integer divide
> Redirect to the right
I? Read number from input and test
if 0 (end of input), ; remove from stack. ^ redirect to top face, O@ Output TOS and quit
if positive, - subtract from TOS
? Test. For 0 and positive ; remove TOS, for negative ;s remove TOS and swap top items on the stack. This keeps the lowest number at the top.
Follow arrows back to the 2nd I and repeat until done.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Mathematica, 18 bytes

⌊#/3⌋~Min~##2&

Pure function taking four integer arguments and returning an integer. Computes the floor of the first argument divided by 3, then finds the minimum of that number and the remaining arguments ##2.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Batch, 71 bytes

@set/am=%1/3
@for %%n in (%*)do @set/a"n=%%n-m,m-=(n>>31)*n
@echo %m%

Unrolling the loop would have been 7 bytes longer.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), 30 bytes

a=>Math.min(a[0]/3,...a)|0

Usage

f=a=>Math.min(a[0]/3,...a)|0
f([2,1,1,1])

Output

0

Explanation

This function takes an array as argument, and then feeds all its elements to Math.min as well as the first element devided by three. Since a[0]/3 is smaller than a[0] (because a[0] is guaranteed to be positive), we don't have to remove it from the main array. Math.min returns the minimum value, which is then floored and returned.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You will be given 4 numbers as input and not 3 \$\endgroup\$ – user41805 Feb 12 '17 at 18:21
  • \$\begingroup\$ Oops, cost me 2B to fix \$\endgroup\$ – Luke Feb 12 '17 at 18:23
  • 1
    \$\begingroup\$ If you take the arguments as a single array parameter then you can save 4 bytes. \$\endgroup\$ – Neil Feb 12 '17 at 19:33
1
\$\begingroup\$

C#, 62 bytes

Golfed

int i(int a,int b,int c,int d){return new[]{a/3,b,c,d}.Min();}

Pretty self-explanatory I think.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

PowerShell, 44 bytes

$a,$b=$args;[int]($a/3),$b|measure -mi|% Mi*

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

R, 26 bytes

As an unnamed function that takes a vector of numbers as the parameter.

function(x)min(x,x[1]%/%3)

Return the min of the parameter and the first item integer divided by 3. So for an input of 7,8,9,10, it will return the min of 7,8,9,10,2. This was shorter than dividing the complete vector by c(3,1,1,1)

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.