Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Golf: Factorials

by srawls (Friar)
on May 23, 2001 at 04:59 UTC ( #82440=perlmeditation: print w/ replies, xml ) Need Help??

This is geared more towards the beginner, to give him a chance to golf, but if you are more advanced and still want to post, than you can just post your code in a 'black box'.

The problem: Passed to your function is a list of numbers, and the function should return a list of those number's factorials. (factorial of 5 is 5*4*3*2*1).


@a = factorial(5); $a[0] = 120<br> @a = factorial(5,3,10); $a[0..2] = (120,6,3628800)

Again, this is meant for beggining to intermidately skilled programmers, but if you are better than that, you can see if you can beat my humble (and probably futile) atempt at the golf. (Click readmore to see my code).

sub f { push@a,eval join'*',1..$_ for@_;@a }

The 15 year old, freshman programmer,
Stephen Rawls

Comment on Golf: Factorials
Select or Download Code
Re: Golf: Factorials
by japhy (Canon) on May 23, 2001 at 05:43 UTC
Re: Golf: Factorials
by mr.nick (Chaplain) on May 23, 2001 at 06:17 UTC
    I don't know ... am I a beginner? :) I guess at golf, I am.
    sub f{map{eval join"*",1..$_}@_;}
    33 chars. Duh! Identical as someone else's answer ...
      32 characters if you delete that last ';'...
      sub f{map{eval join"*",1..$_}@_}

      Update: Sorry it's the same as japhy... nothing new.

      BobiOne KenoBi ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://82440]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2015-03-29 05:00 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (630 votes), past polls