12
\$\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
  • 13
    \$\begingroup\$ As trivial as this is, a few test cases would be nice. \$\endgroup\$ – Dennis Jul 5 '17 at 16:20
  • 9
    \$\begingroup\$ Interesting, a code golf about golf. \$\endgroup\$ – sergiol Jul 6 '17 at 0:07

42 Answers 42

1
2
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\$
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\$
1
2

Your Answer

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