Sort pseudo-lists

a = [[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]
puts '{{' + a.map{|b| b.join(', ')}.join('}, {') + '}}'

=>{{1.4, 2.2, 2.1, 4.2}, {2.1, 3.1, 2.4, 2.2}, {3.1, 1.3, 2.5, 2.1}}

cheers

Simon

···

-----Original Message-----
From: pete boardman [mailto:pete.boardman@pobox.com]
Sent: Tuesday, October 11, 2005 2:27 PM
To: ruby-talk ML
Subject: Re: Sort pseudo-lists

One more thing - I forgot that I need to get the result back to a
string... So (thanks to your help andn Ruby's 'eval') I can go from
this:

"{{3.1, 1.3, 2.5, 2.1}, {2.1, 3.1, 2.4, 2.2}, {1.4, 2.2, 2.1, 4.2}}"

to this:

[[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]

but I can't persuade the 'p' method to turn this back into a string:

"[[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]"

(and I should be able to go from here to :

"{{1.4, 2.2, 2.1, 4.2}, {2.1, 3.1, 2.4, 2.2}, {3.1, 1.3, 2.5, 2.1}}"

on my own :slight_smile:

Pete

Cool - didn't realise Ruby had mapcar stuff. Haven't got that far in the tutorials yet! :slight_smile:

thanks

Pete

···

On 11 Oct 2005, at 13:38, Kroeger, Simon (ext) wrote:

a = [[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]
puts '{{' + a.map{|b| b.join(', ')}.join('}, {') + '}}'

=>{{1.4, 2.2, 2.1, 4.2}, {2.1, 3.1, 2.4, 2.2}, {3.1, 1.3, 2.5, 2.1}}