% irb
irb(main):001:0> require 'enumerator'
=> true
irb(main):002:0> letters = ("a".."z").to_a
=> ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
irb(main):003:0> letters.delete("j")
=> "j"
irb(main):004:0> letters2d = letters.sort_by { rand }.to_enum(:each_slice, 5).to_a
=> [["v", "t", "p", "c", "e"], ["h", "q", "z", "u", "n"], ["k", "m", "y", "g", "i"], ["x", "o", "s", "w", "d"], ["a", "b", "l", "r", "f"]]
irb(main):005:0> require 'pp'
=> true
irb(main):006:0> pp letters2d
[["v", "t", "p", "c", "e"],
["h", "q", "z", "u", "n"],
["k", "m", "y", "g", "i"],
["x", "o", "s", "w", "d"],
["a", "b", "l", "r", "f"]]
=> nil
···
On Apr 6, 2006, at 2:28 PM, Meino Christian Cramer wrote:
Hi,
recently I asked, how one would distribute all letters of
the alphabet randomly and each statistically equal handled
(oh...damn...this looks like awful german English...sorry...)
And the solution was too simple, as I would have thought
of it...hrrmmm...
And now I fear, that the next question will result again in
such simple kind of answer since we all program ruby here...
How can I distribute all 25 letters (I will skip the "J" for this)
over a 5x5 matrix (two dimensional array) that way, that each letter
is handled equally from the statistical point of view ?
Thank you very much for your help in advance !
Ruby!
mcc