48
\$\begingroup\$

Your task is simple: given two integers \$a\$ and \$b\$, output \$\Pi[a,b]\$; that is, the product of the range between \$a\$ and \$b\$. You may take \$a\$ and \$b\$ in any reasonable format, whether that be arguments to a function, a list input, STDIN, et cetera. You may output in any reasonable format, such as a return value (for functions) or STDOUT. \$a\$ will always be less than \$b\$.

Note that the end may be exclusive or inclusive of \$b\$. I'm not picky. ^_^

Test cases

[a,b) => result
[2,5) => 24
[5,10) => 15120
[-4,3) => 0
[0,3) => 0
[-4,0) => 24

[a,b] => result
[2,5] => 120
[5,10] => 151200
[-4,3] => 0
[0,3] => 0
[-4,-1] => 24

This is a , so the shortest program in bytes wins.


Leaderboard

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=66202,OVERRIDE_USER=44713;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
4
  • 2
    \$\begingroup\$ I'm answering this in TI-BASIC tomorrow. \$\endgroup\$ Dec 10, 2015 at 2:48
  • \$\begingroup\$ @SuperJedi224 Good luck ;) \$\endgroup\$ Dec 10, 2015 at 2:48
  • \$\begingroup\$ Can the input be taken as b, a? \$\endgroup\$
    – FlipTack
    Feb 12, 2017 at 20:01
  • \$\begingroup\$ @FlipTack yes you can \$\endgroup\$ Feb 12, 2017 at 20:03

114 Answers 114

38
\$\begingroup\$

Jelly, 2 bytes

rP

Takes two numbers as command line arguments. Try it online.

Note that this is inclusive range. For the cost of a byte (3 bytes), we can make this exclusive:

’rP

Try it online. Note that the arguments must be given in the order b a for this version.

Explanation

Inclusive

a rP b
  r   dyadic atom, creates inclusive range between a and b
   P  computes product of the list

Exclusive

b ’rP a
  ’   decrement b (by default, monadic atoms in dyadic chains operate on the left argument)
   r  range
    P product 
\$\endgroup\$
2
  • 11
    \$\begingroup\$ I doubt this is beatable... \$\endgroup\$ Dec 10, 2015 at 2:52
  • 19
    \$\begingroup\$ @kirbyfan64sos you jelly? \$\endgroup\$
    – Aaron
    Dec 10, 2015 at 13:23
34
\$\begingroup\$

ArnoldC, 522 511 bytes

First post on codegolf !

I had fun doing this. Exclusive range.

LISTEN TO ME VERY CAREFULLY f
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE a
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE b
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE r
YOU SET US UP 1
HEY CHRISTMAS TREE l
YOU SET US UP 1
STICK AROUND l
GET TO THE CHOPPER r
HERE IS MY INVITATION r
YOU'RE FIRED a
ENOUGH TALK
GET TO THE CHOPPER a
HERE IS MY INVITATION a
GET UP 1
ENOUGH TALK
GET TO THE CHOPPER l
HERE IS MY INVITATION b
LET OFF SOME STEAM BENNET a
ENOUGH TALK
CHILL
I'LL BE BACK r
HASTA LA VISTA, BABY

Explanations (Thanks Bijan):

DeclareMethod f
        MethodArguments a
        MethodArguments b
        NonVoidMethod
        DeclareInt r
        SetInitialValue 1
        DeclareInt l
        SetInitialValue 1
        WHILE l
                AssignVariable r
                        SetValue r
                        MultiplicationOperator a
                EndAssignVariable
                AssignVariable a
                        SetValue a
                        + 1
                EndAssignVariable
                AssignVariable l
                        SetValue b
                        > a
                EndAssignVariable
        EndWhile
        Return r
EndMethodDeclaration
\$\endgroup\$
8
  • \$\begingroup\$ Hahaha... I am stil laughing \$\endgroup\$
    – rpax
    Dec 10, 2015 at 20:23
  • \$\begingroup\$ but an explanation would be great \$\endgroup\$
    – rpax
    Dec 10, 2015 at 20:25
  • \$\begingroup\$ Here it is converted and indented using this as reference \$\endgroup\$
    – Bijan
    Dec 10, 2015 at 23:22
  • \$\begingroup\$ Which interpreter are you using? \$\endgroup\$
    – lirtosiast
    Dec 10, 2015 at 23:58
  • \$\begingroup\$ The official one. You're right about @NO PROBLEMO and 1 (not 0 ;) ) \$\endgroup\$
    – Zycho
    Dec 11, 2015 at 9:12
21
\$\begingroup\$

Python, 30 bytes

f=lambda a,b:a>b or a*f(a+1,b)

Inclusive range. Repeatedly multiplies by and increments the left endpoint, until it is higher than the right endpoint, in which case it's the empty product of 1 (as True).

\$\endgroup\$
18
\$\begingroup\$

Minecraft 15w35a+, program size 456 total (see below)

enter image description here

This calculates PI [a,b). Input is given by using these two commands: /scoreboard players set A A {num} and /scoreboard players set B A {num}. Remember to use /scoreboard objectives add A dummy before input.

Scored using: {program size} + ( 2 * {input command} ) + {scoreboard command} = 356 + ( 2 * 33 ) + 34 = 456.

This code corresponds to the following psuedocode:

R = 1
loop:
  R *= A
  A += 1
  if A == B:
    print R
    end program

Download the world here.

\$\endgroup\$
5
  • \$\begingroup\$ Program size is counted by this scoring method. \$\endgroup\$
    – GamrCorps
    Dec 10, 2015 at 23:47
  • \$\begingroup\$ Dammit, you got to it before I did. :I \$\endgroup\$ Dec 11, 2015 at 11:25
  • \$\begingroup\$ You need to specify snapshot version, i.e. 15w46a or something. \$\endgroup\$ Dec 11, 2015 at 11:26
  • 1
    \$\begingroup\$ Minecraft :D LoL, golfing in Minecraft :D \$\endgroup\$ Feb 3, 2016 at 10:07
  • \$\begingroup\$ @username.ak This may surprise you, but it's not that uncommon here. Lol \$\endgroup\$
    – Makonede
    Feb 26, 2021 at 21:05
14
\$\begingroup\$

TI-BASIC, 9 bytes

Input A
prod(randIntNoRep(A,Ans

Takes one number from Ans and another from a prompt.

Also 9 bytes, taking input as a list from Ans:

prod(randIntNoRep(min(Ans),max(Ans
\$\endgroup\$
2
  • 1
    \$\begingroup\$ It took me a while to figure out for myself, so I'm gonna post it here: Each function in TI-BASIC is one byte. \$\endgroup\$
    – Nic
    Dec 11, 2015 at 20:13
  • 3
    \$\begingroup\$ @QPaysTaxes Lots of them do, but not all of them. % is two bytes. \$\endgroup\$
    – mbomb007
    Dec 11, 2015 at 21:20
12
\$\begingroup\$

Python 2, 44 38 bytes

lambda l:reduce(int.__mul__,range(*l))

Pretty much the obvious anonymous function answer.

EDIT: Thanks to xnor for saving 6 bytes with some features I didn't know.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ You can use the built-in int.__mul__, which works in place of your lambda. The two numbers x,y can also be written unpacked as *l. \$\endgroup\$
    – xnor
    Dec 10, 2015 at 3:32
  • 43
    \$\begingroup\$ Crossed out 44 still looks like 44. \$\endgroup\$ Dec 10, 2015 at 3:45
10
\$\begingroup\$

Pyth, 5 bytes

*FrQE

Pyth doesn't have product, so we reduce * over the range.

Uses exclusive range.

\$\endgroup\$
3
  • 5
    \$\begingroup\$ *FrFQ is equivalent but with different input, just for fun :) \$\endgroup\$ Dec 10, 2015 at 3:24
  • \$\begingroup\$ Q is implicitly read, so this can become *FrF - 4 bytes \$\endgroup\$
    – Scott
    Sep 5, 2020 at 21:23
  • \$\begingroup\$ @Scott This question and answer were written long before Pyth had implicit input, so I'm keeping it. \$\endgroup\$
    – lirtosiast
    Sep 7, 2020 at 21:18
10
\$\begingroup\$

R, 22 bytes

function(a,b)prod(a:b)
\$\endgroup\$
8
\$\begingroup\$

Mathematica, 15 bytes

1##&@@Range@##&

A shorter solution that only works for non-negative integers:

#2!/(#-1)!&
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Even shorter for non-negative integers: #2!#/#!& \$\endgroup\$ Mar 25, 2016 at 22:52
8
\$\begingroup\$

JavaScript (ES6), 34 bytes

(a,b)=>eval("for(c=a;a<b;)c*=++a")

Sometimes the simplest answer is the best! Just a for loop inside eval. Inclusive range.

\$\endgroup\$
3
  • \$\begingroup\$ Wow. That's impressive! \$\endgroup\$ Dec 10, 2015 at 12:13
  • \$\begingroup\$ Aw man, I thought of this exact solution while trying to golf mine just now... +1 \$\endgroup\$ Dec 10, 2015 at 16:04
  • 1
    \$\begingroup\$ This one is even shorter with 25 characters: f=(a,b)=>a<b?a*f(a+1,b):1 \$\endgroup\$ May 14, 2019 at 18:26
7
\$\begingroup\$

Japt, 7 bytes

Easy challenges like this are always fun. :)

UoV r*1

Try it online!

Explanation

UoV r*1  // Implicit: U = first input, V = second input
UoV      // Generate range [U,V).
    r*1  // Reduce by multiplication, starting at 1.

Wow, this seems pathetic compared to the other answers so far. I need to work on Japt some more...

\$\endgroup\$
4
  • \$\begingroup\$ Explanation? :3 \$\endgroup\$ Dec 10, 2015 at 3:01
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ Done :) \$\endgroup\$ Dec 10, 2015 at 3:03
  • 2
    \$\begingroup\$ Woot, 5K rep! :D \$\endgroup\$ Dec 10, 2015 at 3:09
  • \$\begingroup\$ looks like you got it to 5 bytes: oV r* Try It Online \$\endgroup\$
    – Hydrazer
    Oct 10, 2021 at 17:01
6
\$\begingroup\$

Seriously, 4 bytes

,ixπ

,         Read list [a,b] from stdin
 i        Flatten it to a b
  x       Pop a,b, push range(a,b)
   π      Pop the list and push its product.

Hex Dump:

2c6978e3

Try it online

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

Prolog, 45 bytes

Code:

p(A,B,C):-A=B,C=A;D is A+1,p(D,B,E),C is A*E.

Explained:

p(A,B,C):-A=B,      % A is unifiable with B
          C=A       % Unify C with A
          ;         % OR
          D is A+1, % D is the next number in the range
          p(D,B,E), % Recurse on the range after the first element
          C is A*E. % The result C is the product of the first element and the result 
                      of the recursion

Example:

p(5,10,X).
X = 151200

p(-4,-1,X).
X = 24
\$\endgroup\$
6
\$\begingroup\$

Octave, 15 bytes

@(a,b)prod(a:b)

Straightforward. Uses the inclusive range.

\$\endgroup\$
6
\$\begingroup\$

CJam, 6 19 18 10 bytes

Thanks to Dennis and RetoKoradi for help with golfing!

q~1$-,f+:*

Try it online

Takes input as a b. Calculates PI [a,b).

Note: this program is 6 bytes long, and only works if a and b are positive.

q~,>:*

Try it online

Takes input as a b. Calculates PI [a,b).

\$\endgroup\$
2
  • \$\begingroup\$ q~{_)_W$<}g;]:* saves three bytes. \$\endgroup\$
    – Dennis
    Dec 10, 2015 at 5:18
  • 4
    \$\begingroup\$ q~1$-,f+:* for 10 bytes. \$\endgroup\$ Dec 10, 2015 at 7:17
6
\$\begingroup\$

Haskell, 19 17 bytes

a#b=product[a..b]

Usage example: 2#5-> 120.

\$\endgroup\$
4
  • \$\begingroup\$ You're allowed to choose to include b. \$\endgroup\$
    – xnor
    Dec 10, 2015 at 17:06
  • \$\begingroup\$ @xnor: Ups, must have overlooked that. Thanks! \$\endgroup\$
    – nimi
    Dec 10, 2015 at 18:01
  • \$\begingroup\$ I'm not sure, but I think PPCG allows answers given as expressions. \$\endgroup\$ Dec 11, 2015 at 14:04
  • \$\begingroup\$ @proudhaskeller: the default is to allow full programs and functions. Snippets, expressions, etc. have to be explicitly permitted in the task description. \$\endgroup\$
    – nimi
    Dec 11, 2015 at 15:26
5
\$\begingroup\$

C, 32 bytes

For [a,b):

f(a,b){return a-b?a*f(a+1,b):1;}

For [a,b] (On Katenkyo's suggestions, 32 bytes again) :

f(a,b){return a<b?a*f(a+1,b):b;}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I found an other solution in C, if you're interested, it's also 32 bytes f(a,b){return a<b?a*f(a+1,b):b;}. :) \$\endgroup\$
    – Katenkyo
    Dec 14, 2015 at 15:24
  • 1
    \$\begingroup\$ -5 bytes in gcc with a=... instead of return... \$\endgroup\$
    – user77406
    Feb 22, 2019 at 18:57
  • \$\begingroup\$ -1 (inclusive) with a>b?:a*f(a+1,b) as the body \$\endgroup\$
    – att
    Jul 13 at 17:08
5
\$\begingroup\$

Bash + GNU utilities, 13

seq -s* $@|bc

Assumes there are no files in the current directory whose names start with -s. Start and end (inclusive) are passed as command-line parameters.

This simply produces the sequence from start to end, separated by *, then pipes to bc for arithmetic evaluation.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ But I start all my files with -s! :P \$\endgroup\$ Dec 10, 2015 at 5:40
5
\$\begingroup\$

Brachylog, 3 bytes

⟦₃×

Try it online!

Input is passed as [A,B]. The range is exclusive of B, but could be made inclusive by replacing the with .

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Welcome to PPCG! Nowadays, it doesn't matter when languages are made, so this answer is perfectly competitive. Hope you enjoy your stay! \$\endgroup\$ Feb 20, 2019 at 4:45
  • \$\begingroup\$ Ah, good to know! I guess I've been looking at too many old challenges with answers sorted by votes. \$\endgroup\$ Feb 20, 2019 at 4:46
  • \$\begingroup\$ @UnrelatedString By the way, if you see those non-competing messages it's perfectly fine to edit them out. \$\endgroup\$ Feb 22, 2019 at 5:42
5
\$\begingroup\$

MATL, 4 bytes

Inclusive Range

2$:p

Try it online!

Explanation

2$: % Implicitly grab two input arguments and create the array input1:input2
p   % Take the product of all array elements

Thanks to @Don Muesli for helping me get the hang of this whole MATL thing.

\$\endgroup\$
2
  • \$\begingroup\$ Isn't &:p a byte shorter? \$\endgroup\$
    – DJMcMayhem
    Jul 25, 2016 at 23:23
  • \$\begingroup\$ @DrGreenEggsandIronMan at the time I posted my answer we didn't have & \$\endgroup\$
    – Suever
    Jul 25, 2016 at 23:24
4
\$\begingroup\$

Jolf, 4 bytes

Try it here!

OrjJ
  jJ two inputs
 r   range between them [j,J)
O    product
\$\endgroup\$
1
  • \$\begingroup\$ In modern Jolf, this can be Orj (which automatically is transpiled to Orjx) \$\endgroup\$ Sep 18, 2019 at 12:25
4
\$\begingroup\$

Julia, 16 bytes

f(a,b)=prod(a:b)

Note: if the range object a:b (which is literally stored as a start value and a stop value, and internally includes a "increment by 1 on each step" value) is permitted as the input, then just 4 bytes are required: prod.

\$\endgroup\$
4
\$\begingroup\$

Ruby, 22 bytes

->i,n{(i..n).reduce:*}

Ungolfed:

-> i,n {
  (i..n).reduce:* # Product of a range
}

Usage:

->i,n{(i..n).reduce:*}[5,10]
=> 151200
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I was thinking about this same solution last night but didn't have the time to write it up. \$\endgroup\$ Dec 10, 2015 at 13:59
  • \$\begingroup\$ A byte is saved with the introduction of implicit named parameters ->{(_1.._2).reduce:*}. \$\endgroup\$
    – south
    Aug 30 at 14:56
4
\$\begingroup\$

PowerShell, 30 Bytes

param($a,$b)$a..$b-join'*'|iex

Takes input as two integers, creates a range with .., then -joins that with asterisks, pipes it into Invoke-Expression (similar to eval). The range operator in PowerShell is inclusive.

Pretty competitive with non-golfing languages.

\$\endgroup\$
4
\$\begingroup\$

J, 8 bytes

[:%/!@<:

Usage

>> f =: [:%/!@<:
>> f 10 5
<< 15120

where >> is STDIN and << is STDOUT.

Explanation

It computes ∏[a,b] as (b-1)!/(a-1)!.

minus_one =: <:
factorial =: !
of        =: @
monadic   =: [:
division  =: %/
f =: monadic division factorial of minus_one

Previous 13-byte version

Written when I had no idea what J even is :p

*/(}.[:>:i.)/

Usage:

   */(}.[:>:i.)/ 5 10
30240

Explanation:

*/            NB. multiply over
  (
   }.         NB. remove [the first x items] from
     [:>:     NB. increment all of
         i.   NB. the numbers from 0 to [y-1]
           )
            / NB. insert the above code into the following numbers

Detailed explanation:

i.10 would produce 0 1 2 3 4 5 6 7 8 9

>:i.10 would make it 1 2 3 4 5 6 6 7 8 9 10

the [: is used to make the ">:" take only one argument (a monad)
because if it takes two arguments, it is a different function.
so [:>:i.10 becomes 1 2 3 4 5 6 7 8 9 10

}. means take away the first [x] items from the following list,
so 5}.1 2 3 4 5 6 7 8 9 10 becomes 6 7 8 9 10

the two slashes "/" in the code are actually the same
for example, */6 7 8 9 10 becomes 6*7*8*9*10
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Great explanation! \$\endgroup\$
    – wizzwizz4
    Mar 30, 2016 at 7:24
  • 2
    \$\begingroup\$ You can use [:*/]+i.@- for 10 bytes if you take the range [a, b) as b ([:*/]+i.@-) a such that 10 ([:*/]+i.@-) 5 outputs 15120. \$\endgroup\$
    – miles
    Jun 8, 2016 at 1:36
  • \$\begingroup\$ @miles That answer was written when I didn't know J at all :p \$\endgroup\$
    – Leaky Nun
    Jun 8, 2016 at 2:07
  • \$\begingroup\$ Your 8 byte solution won't work if neither argument is positive. \$\endgroup\$
    – Dennis
    Jun 8, 2016 at 3:20
4
\$\begingroup\$

JavaScript (ES6), 22 bytes

I can't believe none of us JS golfers thought to use recursion...

a=>F=b=>a-b?b*F(b-1):a

Assign to a variable with e.g. var q = a=>F=b=>a-b?b*F(b-1):a, then call like q(2)(5).

\$\endgroup\$
4
\$\begingroup\$

APL (Dyalog Extended), 8 3 bytesSBCS

×/…

Try it online!

range

×/ multiplication across

This is an "atop" so a(×/…)b is ×/a…b.

\$\endgroup\$
4
\$\begingroup\$

R, 21 bytes

Thanks to Dominic van Essen for helping me brainstorm input methods.

prod((a=scan()):a[2])

Uses inclusive range. Try it online!

Explanation

      a=scan()         Read the two inputs as a vector and assign it to a
     (        ):       Use a as the lower end of a range (R interprets this as "use the
                        first element of the vector" by default)
                a[2]   Use the second element of a as the upper end of the range
prod(               )  Take the product of all numbers in the range
\$\endgroup\$
4
\$\begingroup\$

05AB1E, 2 bytes

Code:

ŸP

Explanation:

Ÿ   # Inclusive range [input, ..., input]
 P  # Total product of the list
    # Implicit printing top of the stack
\$\endgroup\$
3
\$\begingroup\$

Minkolang 0.14, 7 bytes

nnL$*N.

Try it here.

Explanation

nn         Takes two numbers from input
  L        Pops b,a and pushes a..b
   $*      Product the whole stack
     N.    Output as number and stop.
\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.