14
\$\begingroup\$

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 !

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

47 Answers 47

1
2
1
\$\begingroup\$

05AB1E, 7 bytes

3LÌ*O²-

Try it online!

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

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].

\$\endgroup\$
1
\$\begingroup\$

PHP>=7.1, 43 bytes

[,$x,$y,$z,$d]=$argv;echo$x*3+$y*4+$z*5-$d;

PHP Sandbox Online

\$\endgroup\$
1
\$\begingroup\$

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].

\$\endgroup\$
  • \$\begingroup\$ The code you posted and the TIO don't match. \$\endgroup\$ – jacoblaw Jul 5 '17 at 16:41
  • \$\begingroup\$ @jacoblaw Sorry that's what you get for writing code by hand >_< \$\endgroup\$ – Erik the Outgolfer Jul 5 '17 at 16:43
1
\$\begingroup\$

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].

\$\endgroup\$
  • \$\begingroup\$ Use 6,3> instead of 345Ab to save a byte. \$\endgroup\$ – Esolanging Fruit Jul 5 '17 at 16:54
1
\$\begingroup\$

Batch, 28 bytes

@cmd/cset/a%1*3+%2*4+%3*5-%4

Can't believe I'm tying with Python!

\$\endgroup\$
  • \$\begingroup\$ Just curious, do you need the cmd/c - if the rest is in a batch file won't it just work? \$\endgroup\$ – Jerry Jeremiah Jul 6 '17 at 1:28
  • \$\begingroup\$ @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. \$\endgroup\$ – Neil Jul 6 '17 at 7:53
  • \$\begingroup\$ Would the rules require the @ sign, which only hides the command? \$\endgroup\$ – trlkly Jul 6 '17 at 11:20
  • \$\begingroup\$ @trlkly I'm not actually sure, so I've been erring on the side of caution. \$\endgroup\$ – Neil Jul 6 '17 at 14:08
1
\$\begingroup\$

QBIC, 14 bytes

?:*3+:*4+:*5-:

Functionally equivalent to this.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.
                  
\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.
\$\endgroup\$
0
\$\begingroup\$

TI-Basic, 19 bytes

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

Alternatively (21 bytes):

3Ans(1)+4Ans(2)+5Ans(3)-Ans(4
\$\endgroup\$
0
\$\begingroup\$

Add++, 27 bytes

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]
\$\endgroup\$
0
\$\begingroup\$

Ly, 13 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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:

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy