From: Meino Christian Cramer Date: 2004-08-21T05:07:11+09:00 Subject: Re: Neat trick for Steckerboard of Enigma needed... From: Jamis Buck Subject: Re: Neat trick for Steckerboard of Enigma needed... Date: Sat, 21 Aug 2004 04:50:05 +0900 > Hal Fulton wrote: > > Hal Fulton wrote: > > > >> Meino Christian Cramer wrote: > >> > >>> So I get a string, for example "AGQTRXDF" into the simulator. > >>> Does anyone of the Ruby gurus here know a neat trick to convert > >>> this into a hash of the form > >>> steckers={ > >>> "A" => "G", > >>> "Q" => "T", > >>> "R" => "X" > >>> "D" => "F" > >>> } in "one turn"? I only know a very "unrubyish" way to do > >>> this in > >>> single steps -- kinda "slow motion" programming... ;) > >> > >> > >> > >> Would this work? > >> > >> hash = Hash.new(*string.split(/./)) > > > > > > Ah, no, sorry. Make that: > > > > hash = Hash.new(*string.split("")) > > Hal, > > This one still isn't working for me. I keep getting an empty hash back. > Isn't the parameter to Hash.new used as the return value for when a > query misses? > > - Jamis Together were are unbeatable,hahaha ! ;O))) What's about this: a="ABCDEFGHIJ" hash=Hash[*a.split(//)] => {"K"=>"L", "A"=>"B", "C"=>"D", "E"=>"F", "G"=>"H", "I"=>"J"} (but what is this littele '*' good for ?) Thanks a lot for all your help! Ruby.use! Meino