in reply to Counting positive numbers
I count your attempt at 40 chars:
#1234567890123456789012345678901234567890 perl -wle "$a=<>;($x=<>)>0?$_+=$x:0 while$a--;print
My attempt is 23 chars:
#123456789012345678901234 perl -wle "print 0+map{1..<>}2..<>"
Likely there are ways to improve on that, for example the space between print and 0 likely can be eliminated. If you use Perl 5.10 or higher, you can replace print with say, shaving off another two characters.
Update: Relaxing the condition of respecting the number of items in the first line doesn't shorten the code for me:
#123456789012345678901234 perl -wle "<>;print 0+map{1..<>}<>"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting positive numbers
by eyepopslikeamosquito (Archbishop) on Jun 29, 2010 at 13:18 UTC | |
|
Re^2: Counting positive numbers
by ikegami (Patriarch) on Jun 29, 2010 at 15:46 UTC | |
|
Re^2: Counting positive numbers
by Anonymous Monk on Jun 29, 2010 at 12:53 UTC |