From: "Wolfgang Nádasi-donner" Date: 2007-07-22T10:25:09+09:00 Subject: Re: line.split with some complicating factors... Marc Hoeppner wrote: > a line contains a list of coordinates (specifying a range) separated by > a "," like so: > > 50586..50639,50795..51859,60005..60058,60256..61236 > > Now, a way this could look like would be: > > E50586..50639,50640..50795,E50795..51859,.. I see that the problem is already solved, but in Ruby I always have the feeling, that there must be something like a "one-liner" for nearly all problems. Unfortunately I ended only with "something" like a one-liner. >>>>> code >>>>> intxts = [ "50586..50639,50795..51859,60005..60058,60256..61236", "0..10,50000..50100,50101..51000,60005..60058,60059..61236" ] def put(a);(a = a.push(a.shift))[0];end intxts.each do |intxt| pre = ['', 'E'] p intxt.split(',').collect{|e|e.split('..').collect{|v|Integer(v)}}. inject([[],0]){|c,e| c[1]==0 ? (c[0]<>>>> result >>>>> "E50586..50639,50640..50794,E50795..51859,51860..60004,E60005..60058,60059..60255,E60256..61236" "E0..10,11..49999,E50000..50100,E50101..51000,51001..60004,E60005..60058,E60059..61236" >>>>> end of example >>>>> Sorry, but it is a Ruby generated addiction... Wolfgang Nádasi-Donner -- Posted via http://www.ruby-forum.com/.