| Bytes | Lang | Time | Link |
|---|---|---|---|
| 009 | Japt x | 170705T150946Z | Shaggy |
| 037 | Scratch | 170705T232515Z | Laurel |
| 011 | Emacs calc | 250330T175922Z | bindiff |
| 020 | AWK | 250330T001037Z | xrs |
| 007 | Vyxal as | 210519T043412Z | a stone |
| 013 | Julia 1.0 | 210520T143847Z | MarcMush |
| 018 | BRASCA | 210519T125115Z | SjoerdPe |
| 022 | Factor | 210519T152814Z | chunes |
| 246 | MMIX | 210519T044839Z | NoLonger |
| 024 | Javascript | 170705T150510Z | SuperSto |
| 012 | K ngn/k | 201229T210743Z | coltim |
| 066 | PHP | 201017T222256Z | Zsolt Sz |
| 009 | Husk | 201016T201417Z | LegionMa |
| 013 | Stax | 201017T155855Z | Razetime |
| 021 | Desmos | 201016T203329Z | Aiden Ch |
| 023 | R | 170706T185213Z | Giuseppe |
| 008 | Pyt | 171225T033914Z | mudkip20 |
| 020 | Excel VBA | 170706T184843Z | Taylor R |
| 013 | Ly | 171122T090110Z | LyricLy |
| 027 | Add++ | 171120T212908Z | caird co |
| 019 | TIBasic | 171120T212614Z | Timtech |
| 014 | cQuents | 170705T152010Z | Stephen |
| 007 | MATL | 170706T174259Z | Sanchise |
| 014 | QBIC | 170707T092331Z | steenber |
| 014 | Octave | 170706T174600Z | Sanchise |
| 014 | HP15C RPN | 170707T020855Z | Ryan |
| 036 | Cubix | 170706T192107Z | MickyT |
| 012 | 170705T163643Z | totallyh | |
| 007 | Jelly | 170705T150409Z | caird co |
| 016 | Brachylog | 170705T180710Z | Erik the |
| 014 | dc | 170706T121657Z | manatwor |
| 038 | Gallina | 170706T120200Z | Biv |
| 014 | x8664 Machine Code | 170706T105837Z | Cody Gra |
| 028 | Batch | 170705T151954Z | Neil |
| 039 | brainfuck | 170706T014640Z | musicman |
| 006 | Jelly | 170705T161926Z | Dennis |
| 1314 | Mathematica | 170705T150716Z | Keyu Gan |
| 012 | CJam | 170705T154429Z | Erik the |
| 009 | Pyth | 170705T160329Z | Erik the |
| 043 | PHP>=7.1 | 170705T163637Z | Jör |
| 015 | Julia 0.5 | 170705T163443Z | Dennis |
| 019 | Swift 3 | 170705T151928Z | Mr. Xcod |
| 023 | GolfScript | 170705T161758Z | Erik the |
| 022 | Haskell | 170705T161636Z | Laikoni |
| 030 | C gcc | 170705T155159Z | Giacomo |
| 007 | Neim | 170705T153718Z | Okx |
| 007 | 05AB1E | 170705T153149Z | Erik the |
| 024 | C# | 170705T152810Z | TheLetha |
| 016 | Perl6 | 170705T152626Z | manatwor |
| 021 | Julia | 170705T151612Z | Julian W |
| 014 | Braingolf | 170705T151454Z | Mayube |
| 024 | Java OpenJDK 8 | 170705T150842Z | Olivier |
| 015 | Befunge | 170705T150709Z | ovs |
| 028 | Python 3 | 170705T150352Z | notjagan |
Japt -x, 12 9 bytes
Takes input as:
[difficulty rating, num_of_3_pars, num_of_4_pars, num_of_5_pars]
Includes an unprintable after the #.
í*#5ì)vn
Scratch, 40 37 Norwegian bytes
-2 thanks to boboquack
-1 because "si" (Norwegian) is shorter than "say". Another (same length) option was Haitian Creole.
(Because Scratch is the standard scratch.)

Orange blocks are variables. Here's a sample run:
.
Emacs calc, 11 bytes
Setup this on the stack:
1: difficulty rating
2: [num_of_3_pars, num_of_4_pars, num_of_5_pars]
Keypresses:
'[3,4,5 <Ret> * <Tab> -
Vyxal as, 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)
BRASCA, 18 bytes
Takes input as <3-par>,<4-par>,<5-par>,<difficulty>
Ci',G,3*$4*+$5*+$-
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
Factor, 23 22 bytes
[ { 3 4 5 } v. - neg ]
-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 }.- negSubtract the difficulty rating from the dot product.
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.
Javascript, 24 bytes
(a,b,c,d)=>3*a+4*b+5*c-d
K (ngn/k), 12 bytes
{-y-/x*3+!3}
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+!3generate3 4 5, multiplying by the first input-y-/equivalent to(-y)+/x, or(+/x)-y. In this instance, the leading-negates the entirey-/...expression.
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.
Stax, 13 bytes
╨E⌡u╥Diüaë¬~▼
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.
Desmos, 21 bytes
f(a,b,c,d)=3a+4b+5c-d
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:
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
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
Add++, 27 bytes
D,g,@@@@!,3 4 5 1ECBcB*0$_s
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]
TI-Basic, 19 bytes
Prompt A,B,C,D:3A+4B+5C-D
Alternatively (21 bytes):
3Ans(1)+4Ans(2)+5Ans(3)-Ans(4
cQuents, 14 bytes
#|1:3A+4B+5C-D
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.
MATL, 7 bytes
3:5*si-
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.
Octave, 14 bytes
@(a)[3:5 -1]*a
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.
HP-15C (RPN), 14 bytes
Instruction hex codes:
41 C4 F5 FC C5 F4 FC FA C5 F3 FC FA 31 FB
Readable version:
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.
Cubix, 36 bytes
w;r5*U4I;I3*r;UW;;r;<\r/;r-I/+p+O@;w
w ; r
5 * U
4 I ;
I 3 * r ; U W ; ; r ; <
\ r / ; r - I / + p + O
@ ; w . . . . . . . . .
. . .
. . .
. . .
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 stackI4*/r\get next input and multiply by 4. Rotate result down.Iw5*Ur;w<;r;;Wget next input, multiply by 5 and clean up the stackI-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
,,,, 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
Jelly, 10 7 bytes
3r5×⁸S_
-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)
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
Gallina, 38 bytes
Definition f a b c d := 3*a+4*b+5*c-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_holesESI= num_of_4_par_holesEDX= num_of_5_par_holesECX= 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.
Batch, 28 bytes
@cmd/cset/a%1*3+%2*4+%3*5-%4
Can't believe I'm tying with Python!
brainfuck, 39 bytes
,[->+++<],[->++++<],[->+++++<],[->-<]>.
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
Jelly, 6 bytes
JḊ~æ.N
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.
Mathematica, 13 14 bytes
{3,4,5,-1}.#&
Thanks to @GregMartin. Take input as a length-4 list.
CJam, 12 bytes
{6,3>.*:+\-}
-1 thanks to Challenger5.
Takes input as difficulty rating [num_of_3_pars num_of_4_pars num_of_5_pars].
Pyth, 9 bytes
-s*V}3 5E
Takes input as difficulty rating\n[num_of_3_pars, num_of_4_pars, num_of_5_pars].
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}
Usage: {$0*3+$1*4+$2*5-$3}(a,b,c,d), where a,b,c,d are the parameters.
GolfScript, 23 bytes
~[.;3,]zip{~3+*}%{+}*\-
Takes input as difficulty rating [num_of_3_pars num_of_4_pars num_of_5_pars].
Haskell, 22 bytes
(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.
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 ᛖ.
C#, 24 bytes
(a,b,c,d)=>a*3+b*4+c*5-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


