From: Prasanth Ravi Date: 2010-03-10T01:14:31+09:00 Subject: Re: Shortest code Siep Korteling wrote: > Prasanth Ravi wrote: >> Aaron D. Gifford wrote: >>> Ruby 1.9: 34 characters >>> >>> eval(gets.scan(/(?:^| )(\d+)/)*?+) >>> >>> Aaron out >> >> tx aaron this is by far the shortest code ive seen... > > A variation: > > p eval gets.split(/ |-\d+/)*?+ > > Siep irb(main):003:0> p eval gets.split(/ |-\d+/)*?+ 1 -2 -3 -5 SyntaxError: (eval):1: syntax error, unexpected $end from (irb):3:in `eval' from (irb):3 from /usr/bin/irb1.9:12:in `
' irb(main):004:0> p eval gets.split(/ |-\d+/)*?+ 1 2 3 4 5 15 => 15 irb(main):005:0> i got this output maybe some env change? -- Posted via http://www.ruby-forum.com/.