Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Counting positive numbers

by eyepopslikeamosquito (Chancellor)
on Jun 29, 2010 at 13:18 UTC ( #847120=note: print w/replies, xml ) Need Help??


in reply to Re: Counting positive numbers
in thread Counting positive numbers

Using ~~ inchworm secret operator saves a stroke:

#1234567890123456789012 perl -wle "print~~map{1..<>}2..<>"
Update: The inchworm secret operator is more clearly described here. I remember it from good old TPR0 way back in 2002. You can read all about TPR0 and the other early Perl golf tournaments by downloading Terje/mtv's excellent Book of Perl Golf.

Relaxing the first line restriction allows 20 strokes (which can probably be further shortened):

#12345678901234567890 perl -pe "$.>1&$_>0and$\+=$_}{"
This time we use the }{ eskimo greeting secret operator in harness with Eugene's infamous $\ trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://847120]
help
Chatterbox?
[Discipulus]: good morning folks!
choroba mornings back
[Corion]: Hi choroba!
[Corion]: And Discipulus!
Corion arrived back from London. Always nice to meet people again, even if it's just once per year.
[Corion]: Also, dk contributed some cool stuff to App::ShaderToy, like menu settings and real fullscreen, eliminating many of my #TO-DO comments ;)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2016-12-06 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (101 votes). Check out past polls.