interesting...

ree-1.8.7-2010.01 > puts eval(gets.gsub(/(?:-\d|[^0-9])+/, '+')<<'+0')
1 2 3 -4
6
 =3D> nil=20
ree-1.8.7-2010.01 > puts eval(gets.gsub(/(?:-\d|[^0-9])+/, '+')<<'+0')
1 -2 3 4
8
 =3D> nil=20

ol' ruby?

Am 09.03.2010 um 04:39 schrieb Prasanth Ravi:

> Florian A=DFmann wrote:
>> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'+0')
>>=20
>> Am 08.03.2010 um 22:10 schrieb Prasanth Ravi:
>=20
> irb(main):001:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'+0')
> 1 2 3 4
> 10
> =3D> nil
> irb(main):002:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'+0')
> 1 -2 3 4
> 10
> =3D> nil
> irb(main):003:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'+0')
> 1 -2 -34 5
> 42
> =3D> nil
> irb(main):004:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'+0')
> -234
> 0
> =3D> nil
> irb(main):005:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'+0')
> -2 -3 -4
> 7
> =3D> nil
> irb(main):006:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'0')
> 1 2 3 43
> 49
> =3D> nil
> irb(main):007:0> puts eval(gets.gsub(/-\d+|[^0-9]+/, '+')<<'0')
> 1 -2 3 4
> 10
> =3D> nil
>=20
>=20
> it's shorter code(45 chars) but i think negative numbers also get =
added=20
> to result( or not- check case 5), seems can't get below 35
> --=20
> Posted via http://www.ruby-forum.com/.
>=20