# 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?) Commented Jul 5, 2017 at 15:20
• Can we take inputs reversed? Commented Jul 5, 2017 at 15:20
• As trivial as this is, a few test cases would be nice. Commented Jul 5, 2017 at 16:20
• Interesting, a code golf about golf. Commented Jul 6, 2017 at 0:07

# 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. Commented Jul 6, 2017 at 13:34

# GolfScript, 23 bytes

~[.;3,]zip{~3+*}%{+}*\-


Try it online!

Takes input as difficulty rating [num_of_3_pars num_of_4_pars num_of_5_pars].

# PHP>=7.1, 43 bytes

[,$x,$y,$z,$d]=$argv;echo$x*3+$y*4+$z*5-$d;  PHP Sandbox Online # Pyth, 9 bytes -s*V}3 5E  Try it here. Takes input as difficulty rating\n[num_of_3_pars, num_of_4_pars, num_of_5_pars]. • The code you posted and the TIO don't match. Commented Jul 5, 2017 at 16:41 • @jacoblaw Sorry that's what you get for writing code by hand >_< Commented Jul 5, 2017 at 16:43 # CJam, 12 bytes {6,3>.*:+\-}  Try it online! -1 thanks to Challenger5. Takes input as difficulty rating [num_of_3_pars num_of_4_pars num_of_5_pars]. • Use 6,3> instead of 345Ab to save a byte. Commented Jul 5, 2017 at 16:54 # Batch, 28 bytes @cmd/cset/a%1*3+%2*4+%3*5-%4  Can't believe I'm tying with Python! • Just curious, do you need the cmd/c - if the rest is in a batch file won't it just work? Commented Jul 6, 2017 at 1:28 • @JerryJeremiah set/a normally doesn't print its result, so I would have to assign it to a variable and echo it, which costs far too many bytes. However, when you use it interactively then it does print the result. Invoking cmd/c fools it into printing the result. – Neil Commented Jul 6, 2017 at 7:53 • Would the rules require the @ sign, which only hides the command? Commented Jul 6, 2017 at 11:20 • @trlkly I'm not actually sure, so I've been erring on the side of caution. – Neil Commented Jul 6, 2017 at 14:08 # QBIC, 14 bytes ?:*3+:*4+:*5-:  Functionally equivalent to this. # MATL, 7 bytes 3:5*si-  Try it online! Input vector times range 3:5 minus the second input. Contrary to my Octave answer, it's actually shorter to have the inputs as two separate inputs, and shorter to element-wise multiply, then sum, than to do a direct dot product. # cQuents, 14 bytes #|1:3A+4B+5C-D  Try it online! Input is 3par 4par 5par diff. cQuents is not at all built for this type of problem, but it still did fairly well. ## Explanation #|1 Append 1 to the end of the user input - call it n : Mode: sequence 3A+4B+5C-D Each item in the sequence equals the first input times three plus the second input times four plus the third input times five minus the fourth input. The last input, n, which came from the program's parameters, prints the nth item in the sequece.  # Pyt, 13 8 bytes 35Ř←*Ʃ←-  Takes as input from stdin inputs separately in the following order: [num_of_3_pars,num_of_4_pars,num_of_5_pars], difficulty_rating # K (ngn/k), 12 bytes {-y-/x*3+!3}  Try it online! Called like f[1 2 3;4]. Takes the number of par 3/4/5 holes as one list of three values, and the difficulty rating as the second arg. • x*3+!3 generate 3 4 5, multiplying by the first input • -y-/ equivalent to (-y)+/x, or (+/x)-y. In this instance, the leading - negates the entire y-/... expression. # MMIX, 24 bytes (6 instrs) 00000000: 2a020202 28000000 26020203 2a000100 *£££(¡¡¡&££¤*¡¢¡ 00000010: 22000002 f8010000 "¡¡£ẏ¢¡¡  scratch 4ADDU$2,$2,$2      // p5 *= 5
2ADDU $0,$0,$0 // p3 *= 3 SUBU$2,$2,$3      // p5 -= diff
4ADDU $0,$1,$0 // p3 += 4 * p4 ADDU$0,$0,$2      // p3 += p5
POP   1,0           // return p3


I ordered the instructions to avoid as many short-term data dependencies as possible.

# Factor, 23 22 bytes

[ { 3 4 5 } v. - neg ]


Try it online!

-1 thanks to @Bubbler

The quotation takes the input as difficulty list.

• { 3 4 5 } v. Take the dot product between the input list and { 3 4 5 }.
• - neg Subtract the difficulty rating from the dot product.
• - neg is one byte shorter than swap -. Commented May 20, 2021 at 0:56

# BRASCA, 18 bytes

Takes input as <3-par>,<4-par>,<5-par>,<difficulty>

Ci',G,3*$4*+$5*+$-  Try it online! ## Explanation C - Set implicit output to number mode i',G - Use numbers instead of charcodes for 0-9. Then split by commas. , - Reverse stack so the 3par is at the top. 3* - 3par * 3$4*+        - 4par * 4, then add to 3par
$5*+ - 5par * 5, then add to total$-  - total - difficulty
<implicit>          - Print it


# Vyxalas, 8 7 bytes

-1 thanks to Aaron Miller

2ʀ3+uJ*


Takes input as par3 \n par4 \n par5 \n difficulty. Try it Online!

2ʀ3+uJ*
2ʀ        # Push the range [0, 1, 2]
3+      # Add 3: [3, 4, 5]
uJ    # Append -1: [3, 4, 5, -1]
*   # Multiply the list by its counterpart in...
# the (implicit) input, and...
# Print the sum of the result (s flag)

• 7 bytes Commented May 21, 2021 at 13:20

# TI-Basic, 19 bytes

Prompt A,B,C,D:3A+4B+5C-D


Alternatively (21 bytes):

3Ans(1)+4Ans(2)+5Ans(3)-Ans(4


D,g,@@@@!,3 4 5 1ECBcB*0$_s  Try it online! ## How it works D,g, - Create a function called g... @@@@ - ...that takes 4 arguments... !, - ...as a list. e.g. [4 3 2 1] 3 4 5 1 - Push 3 4 5 1; STACK = [[4 3 2 1] 3 4 5 1] EC - Collect; STACK = [[4 3 2 1] [3 4 5 1]] Bc - Zip; STACK = [[4 3] [3 4] [2 5] [1 1]] B* - Products; STACK = [12 12 10 1] 0$_     - Negate;       STACK = [12 12 10 -1]
s       - Sum;          STACK = [33]


# Ly, 13 bytes

3n*4n*5n*&+n-


Try it online!

# Desmos, 21 bytes

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


Try It On Desmos!

Input is a function where $$\a=3\ \text{par holes},b=4\ \text{par holes},c=5\ \text{par holes},d=\text{difficulty rating}\$$

Example Test Case:

# Stax, 13 bytes

╨E⌡u╥Diüaë¬~▼


Run and debug it

If I can find a way to read in the array and the number as is instead of evaluating them from string, this program will be shorter.

# PHP, 66 bytes

list($a,$b,$c,$d,$e)=$argv;echo eval("return 3*$b+4*$c+5*$d-$e;");


first attempt:

# PHP, 145 bytes

<?php $a=$_SERVER['argv'];$b=[0,3,4,5,-1];$r=array_map(function($x,$y){return$x*$y;},$a,$b);echo array_reduce($r,function($i,$c){return$i+=$c;});  ## Ungolfed: <?php$a = $_SERVER['argv'];$b = [0,3,4,5,-1]; // the first element always contains the filename, and is hereby disregarded
$r = array_map(function($x,$y){return$x*$y;},$a,$b); echo array_reduce($r, function ($i,$c) {return $i+=$c;});


With 10, 5 and 3 holes respectivly, and a difficulty of 5, it's to be called with \$ php codegolf.php 10 5 3 5

Note: it throws a warning, as we multiply a string with zero. Add 1 byte for the error-supression-operator to get rid if that.

# Julia 1.0, 13 bytes

v->[3:5;-1]'v


Try it online!

improvement of Dennis's Julia 0.5 answer