From: Holger Mack Date: 2008-09-20T19:30:28+09:00 Subject: Re: [QUIZ] One-Liners Mashup (#177 again) ------=_Part_80146_11673839.1221907098807 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/9/20 Sebastian Hungerecker > Next question: > Sort an array of words by the words' values where a word's value is the > sum of the values of its letters and a letter's value is its position in > the alphabet. So the value of "Hello" is 8+5+12+12+15. > class Array; def sortval() sort {|x,y| x.upcase.sum-x.length*64 <=> y.upcase.sum-y.length*64};end;end Solution works fine, if array countains only words of only letters. Now I know, what sum() is for ;-) ---------------------- NEXT QUIZ Write a function per(n) which returns the periodicity of 1/n, i.e. per(3) => 1 per(4) => 0 per(7) => 6 per(11) => 2 Holger ------=_Part_80146_11673839.1221907098807--