# What is the standard scratch?

In golf, the standard scratch of a course is calculated using this formula:

(3*num_of_3_par_holes + 4*num_of_4_par_holes + 5*num_of_5_par_holes) - difficulty_rating


Your task is to calculate the standard scratch of a golf course, given these 4 inputs.

You should take input in any standard form in the format

[num_of_3_pars, num_of_4_pars, num_of_5_pars], difficulty rating


but if it saves bytes, you many take input in a different way.

You should output the final result by any accepted method on meta, such as returning from a function.

Shortest code wins because this is !

• Will all inputs be integers and at least 1? (Also, will the output always be positive?) – Doorknob Jul 5 '17 at 15:20
• Can we take inputs reversed? – totallyhuman Jul 5 '17 at 15:20
• As trivial as this is, a few test cases would be nice. – Dennis Jul 5 '17 at 16:20
• Interesting, a code golf about golf. – sergiol Jul 6 '17 at 0:07

# Scratch, 145 bytes

-2 thanks to boboquack
-??? because writing it in Oto is shorter than English

(Because Scratch is the standard scratch.)

Here's a sample run:

.

# Jelly, 6 bytes

JḊ~æ.N


Try it online!

### How it works

JḊ~æ.N  Main link. Argument: [a, b, c, d]

J       Indices; yield [1, 2, 3, 4].
Ḋ      Dequeue; yield [2, 3, 4].
~     Bitwise NOT; yield [-3, -4, -5].
N  Negate; yield [-a, -b, -c, -d].
æ.   Dot product; yield
(-3)(-a) + (-4)(-b) + (-5)(-c) + (-d) = 3a + 4b + 5c - d.


# Java (OpenJDK 8), 24 bytes

(a,b,c,d)->a*3+b*4+c*5-d


Try it online!

• Yeah, shorter than Python \o/ – Olivier Grégoire Jul 5 '17 at 15:09

(a#b)c d=3*a+4*b+5*c-d


Try it online! Usage: (3#2)5 7 yields 35.

This not so nice input format is one byte shorter than the straight forward solution:

f a b c d=3*a+4*b+5*c-d


Point-free and nice input format: (23 bytes)

(-).sum.zipWith(*)[3..]


Try it online! Bind to f and call with f [3,2,5] 7.

# Mathematica, 13 14 bytes

{3,4,5,-1}.#&


Thanks to @GregMartin. Take input as a length-4 list.

• Thanks to "but if it saves bytes, you many take input in a different way", I think you should take input as a length-4 list and shorten the second solution to {3,4,5,-1}.#& (13 bytes). – Greg Martin Jul 5 '17 at 17:19
• You are right.. – Keyu Gan Jul 5 '17 at 17:22

# Python 3, 28 bytes

lambda a,b,c,d:3*a+4*b+5*c-d


Try it online!

# Javascript,24 bytes

(a,b,c,d)=>3*a+4*b+5*c-d


# Perl6, 16 characters

3* *+4* *+5* *-*


(Yepp, that is a sub.)

Sample run:

> say 3* *+4* *+5* *-*
{ ... }

> say (3* *+4* *+5* *-*)(4, 3, 2, 1)
33


Try it online!

# Julia 0.5, 15 bytes

!v=v⋅[3:5;-1]


Try it online!

• Is ⋅ three bytes, or am I miscounting? Would .* be an improvement? edit: Never mind—missed the summing part. – Julian Wolf Jul 5 '17 at 17:29
• Yes, three bytes. .* only performs element-wise multiplication; it doesn't take the sum of the products. – Dennis Jul 5 '17 at 17:30

# C#, 24 bytes

(a,b,c,d)=>a*3+b*4+c*5-d


# x86-64 Machine Code, 14 bytes

8D 3C 7F 8D 14 92 8D 04 B7 01 D0 29 C8 C3


A function following the System V AMD64 calling convention (ubiquitous on Gnu/Linux systems) that takes four integer parameters:

• EDI = num_of_3_par_holes
• ESI = num_of_4_par_holes
• EDX = num_of_5_par_holes
• ECX = difficulty_rating

It returns a single value, the standard scratch, in the EAX register.

Ungolfed assembly mnemonics:

; int ComputeStandardScratch(int num_of_3_par_holes,
;                            int num_of_4_par_holes,
;                            int num_of_5_par_holes,
;                            int difficulty_rating);
lea   edi, [rdi+rdi*2]    ; EDI = num_of_3_par_holes * 3
lea   edx, [rdx+rdx*4]    ; EDX = num_of_5_par_holes * 5
lea   eax, [rdi+rsi*4]    ; EAX = EDI + (num_of_4_par_holes * 4)
add   eax, edx            ; EAX += EDX
sub   eax, ecx            ; EAX -= difficulty_rating
ret                       ; return, leaving result in EAX


Just a simple translation of the formula. What's interesting is that this is essentially the same code that you would write when optimizing for speed, too. This really shows the power of the x86's LEA instruction, which is designed to load an effective address, but can do addition and scaling (multiplication by low powers of 2) in a single instruction, making it a powerful multi-purpose arithmetic workhorse.

# Jelly, 10 7 bytes

3r5×⁸S_


Try it online!

-3 bytes thanks to Erik The Outgolfer!

## How it works!

3r5×⁸S_  Main link: a, the pars as a list and b, the difficulty rating

S   The sum of
3r5        [3, 4, 5]
×       each element times
⁸      the left argument (a)
_  Subtract the right argument (b)

• Standard way to make lists is omitting [] but you can use 3r5×⁸S_ to golf this more (3r5 -> [3, 4, 5], ⁸ = left argument to differentiate it from the S, × is commutative). – Erik the Outgolfer Jul 5 '17 at 15:29

# Octave, 14 bytes

@(a)[3:5 -1]*a


Try it online!

About twice as long as the MATL answer. I initially literally ported this to MATL, but it turned out iY* is longer than just *s. Note that the input a, containing the holes in order and then the difficulty, should be a column vector.

• As question says you can take the input in any format if it saves bytes, this works for 14: @(a)[3:5 -1]*a. Input is a column vector of [3 holes; 4 holes; 5holes; difficulty] – Tom Carpenter Jul 7 '17 at 7:32
• @TomCarpenter Oh, I thought the list + number part was compulsory. It's a bit oddly phrased: "You should... but you may". I guess I'll amend my answer then. – Sanchises Jul 7 '17 at 9:01

## Julia, 21 bytes

f(a,b,c,d)=3a+4b+5c-d


Try it online!

# Neim, 7 bytes

'π𝐂𝕋𝐬S𝕊


Explanation:

'π         Push 345
The character ' pushes the next character's index in the codepage plus 100.
The characters ", + and * do that same thing except add a different number.
This means that in Neim, all 3 digit numbers can be expressed with 2 characters.
This commit was pushed 8 days before the answer was posted.
𝐂        Get the characters
𝕋       Vectorised multiply with the input
𝐬       Sum the resulting list
S𝕊    Subtract the input


Alternative program: 3𝐈ᛖ𝕋𝐬S𝕊

Instead of pushing 345 and then getting the characters, creates the array [1 2 3] using 3𝐈, then adds 2 to each element with ᛖ.

Try it online!

• This commit was pushed 8 days before the answer was posted. well, you don't actually need this. – Erik the Outgolfer Jul 5 '17 at 15:59
• @EriktheOutgolfer Sure I don't. But I also don't need the explanation. Would you like me to remove that? – Okx Jul 5 '17 at 16:01
• Basically you don't have to worry about non-competing since meta consensus changed. – Erik the Outgolfer Jul 5 '17 at 16:02
• @EriktheOutgolfer I do worry about non-competing because the meta consensus is subjective and unclear. But in this case, there's no reason to complain about it being there. You're using up more time than you otherwise would you didn't post that comment. – Okx Jul 5 '17 at 16:06
• For some reason, most Neim chars in inline code blocks look like ? boxes. – CalculatorFeline Jul 5 '17 at 17:02

# C (gcc), 30 bytes

e;f(a,b,c,d){e=3*a+4*b+5*c-d;}


Try it online!

• No need for an extra variable. Just assign to a. – Dennis Jul 6 '17 at 19:39

# Swift 3, 25 19 bytes

I realised you do not need the var f=, because you can call it like a Python lambda:

{$0*3+$1*4+$2*5-$3}


Test it online!

Usage: {$0*3+$1*4+$2*5-$3}(a,b,c,d), where a,b,c,d are the parameters.

# brainfuck, 39 bytes

,[->+++<],[->++++<],[->+++++<],[->-<]>.


Try it online!

Takes input and prints output as ASCII characters; for example, the value 99 would be represented as c.

### Explanation:

,                                       Take the first input in Cell 0
[      ]                               While the data being pointed to (Cell 0) is nonzero
->+++<                                Decrement Cell 0 and add 3 to Cell 1
Now 4 times the first input is in Cell 1
,                              Take the second input in Cell 0
[->++++<]                     Add 4 times the second input to Cell 1
,[->+++++<]          Take the third input in Cell 0 and add five times its value to Cell 1
,         Take the fourth input in Cell 0
[    ]   While the data being pointed to (Cell 0) is nonzero
->-<    Decrement Cells 0 and 1
>. Print the value in Cell 1


# Gallina, 38 bytes

Definition f a b c d := 3*a+4*b+5*c-d.


# dc, 14 characters

?3*?4*+?5*+?-p


The numbers need to be passed on separate lines.

Sample run:

bash-4.4\$ dc -e '?3*?4*+?5*+?-p' <<< '4
> 3
> 2
> 1'
33


Try it online!

# Brachylog, 18 16 bytes

∧5⟦₁↺b;?z×ᵐġ₃+ᵐ-


Try it online!

-2 thanks to Fatalize.

• ∧5⟦₁↺b;?z×ᵐġ₃+ᵐ- is 2 less bytes – Fatalize Jul 6 '17 at 7:34
• @Fatalize It would've been 3 less bytes if there wasn't a bug with leading integer and input. – Erik the Outgolfer Jul 6 '17 at 13:22

# ,,,, 12 bytes

↻5×↻4×↻3×↻-#


## Explanation

Take input 4, 3, 2, 1 for example.

↻5×↻4×↻3×↻-#

implicit input                  [4, 3, 2, 1]
↻             rotate the stack clockwise      [1, 4, 3, 2]
5            push 5                          [1, 4, 3, 2, 5]
×           pop 2 and 5 and push 2 * 5      [1, 4, 3, 10]
↻          rotate the stack clockwise      [10, 1, 4, 3]
4         push 4                          [10, 1, 4, 3, 4]
×        pop 3 and 4 and push 3 * 4      [10, 1, 4, 12]
↻       rotate the stack clockwise      [12, 10, 1, 4]
3      push 3                          [12, 10, 1, 4, 3]
×     pop 4 and 3 and push 4 * 3      [12, 10, 1, 12]
↻    rotate the stack clockwise      [12, 12, 10, 1]
-   pop 10 and 1 and push 10 - 1    [12, 12, 9]
#  pop 12, 12, 9 and push the sum  [33]
implicit output


# Cubix, 36 bytes

w;r5*U4I;I3*r;UW;;r;<\r/;r-I/+p+O@;w


Try it online!

      w ; r
5 * U
4 I ;
I 3 * r ; U W ; ; r ; <
\ r / ; r - I / + p + O
@ ; w . . . . . . . . .
. . .
. . .
. . .


Watch It Run

A fairly linear program that winds back around onto itself a few times. Basic steps:

• I3*r;U; get the first input, multiply by 3 and clean up stack
• I4*/r\ get next input and multiply by 4. Rotate result down.
• Iw5*Ur;w<;r;;W get next input, multiply by 5 and clean up the stack
• I-r;w; get last input, subtract from par 5 result and clean up stack
• /+p+O\@ add to par 4 result, bring par3 result to top add, output and halt

# HP-15C (RPN), 14 bytes

Instruction hex codes:

41 C4 F5 FC C5 F4 FC FA C5 F3 FC FA 31 FB


001 {       44  1 } STO 1
002 {          33 } R⬇
003 {           5 } 5
004 {          20 } ×
005 {          34 } x↔y
006 {           4 } 4
007 {          20 } ×
008 {          40 } +
009 {          34 } x↔y
010 {           3 } 3
011 {          20 } ×
012 {          40 } +
013 {       45  1 } RCL 1
014 {          30 } −


The four numbers are loaded into the stack in order before running the program.

• Nice first answer. Welcome to PPCG! – musicman523 Jul 7 '17 at 5:13

# Excel VBA, 20 Bytes

Anonymous VBE immediate window function that takes input from the range [A3:A6] of which [A3:A5] represent the number of 3,4 and 5 par holes, respectively and [A6] represents the difficulty. Outputs to the VBE immediate window

?[3*A3+4*A4+5*A5-A6]


The above is a condensed version of the call

Debug.Print Application.Evaluate("=3*A3+4*A4+5*A5-A6")


Where "=3*A3+4*A4+5*A5-A6" is given to be the formula of an anonymous cell, as indicated by the [...] wrapper, and ? is the deprecated version of the Print  call with an implicit Debug. by context

### More fun Version, 34 Bytes

Anonymous VBE immediate window function with same I/O conditions as above.

?[SUMPRODUCT(A3:A5,ROW(A3:A5))-A6]


The above is a condensed version of the call

Debug.Print Application.Evaluate("=SUMPRODUCT(A3:A5,ROW(A3:A5))")


Where "=SUMPRODUCT(A3:A5,ROW(A3:A5))" is given to be the formula of an anonymous cell, as indicated by the [...] wrapper, and ? is the deprecated version of the Print  call with an implicit Debug. by context. In this version, the range of [A3:A5] and the row numbers of that range (ROWS(A3:A5)) are passed as arrays

### Excel Version, 18 bytes

Of course, the versions above lend themselves thusly to excel versions of

=3*A3+4*A4+5*A5-A6


and

=SUMPRODUCT(A3:A5,ROW(A3:A5))-A6


# R, 25 23 bytes

cat(c(3:5,-1)%*%scan())


Try it online!

• sum(scan()*3:5)-scan() is slightly smaller – MickyT Jul 6 '17 at 19:08
• thank you. I usually don't try scan when there are multiple inputs like this, but whaddya know! – Giuseppe Jul 6 '17 at 19:13

# Befunge, 15 bytes

&3*&4*+&5*+&-.@


Try it online!

# Japt, 12 bytes

*3+V*4+W*5-X


Test it

# Braingolf, 14 bytes

3*>4*>5*>>++,-


Try it online!

# 05AB1E, 7 bytes

3LÌ*O²-


Try it online!

• You can replace 3L with ā as the first input will be a list of length 3 anyway. – kalsowerus Jul 6 '17 at 13:34