Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Golf: Factorials

by choroba (Cardinal)
on Apr 10, 2015 at 21:49 UTC ( [id://1123084]=note: print w/replies, xml ) Need Help??


in reply to Re: Golf: Factorials
in thread Golf: Factorials

Easy to make it 30 with
$a=1;print$a*=$b+=1,$/for a..k
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^3: Golf: Factorials
by Athanasius (Archbishop) on Apr 11, 2015 at 03:43 UTC

      Though we may have strayed a bit from the original golf, yours can be whittled by three strokes:

      > perl -E "$a=1;say$a*=++$}for a..k" > perl -E "say$x*=$_ for++$x..11" 1 2 6 24 120 720 5040 40320 362880 3628800 39916800

        yes a bit from the original post: in fact:
        perl -E "say$x*=$_ for++$x..3,0,1,-1" 1 2 6 0 # must be 1 0 # too 0 # must be undef or Error


        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      also this solution works only for series of consecutive integers starting with 1
      perl -E "$a=1;say$a*=++$}for @ARGV" 0 1 2 3 1 2 6 24 perl -E "$a=1;say$a*=++$}for @ARGV" 1 3 1 2


      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found