Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: [QUIZ] Numbers Can Be Words (#133
Josef 'Jupp' Schugt
8/5/2007 4:11:00 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
James Koppel wrote:
> I found this Quiz to be extremely easy. I wrote this solution in a
> minute or two:
>
> dict = File.open("wordlist.txt"){|f| f.readlines.reject {|word|
> ('A'..'Z') === word[0,1]}}
>
> base = ARGV[0].to_i
>
> puts dict.select{|word| word.unpack("C*").select{|char|
> char > ?a+base-11}.empty?}
Indeed. Here's my two-liner. ARGV[0] is the base to be used, ARGV[1] is
the file to be processed.
p = /^[#{"0123456789abcdefghijklmnopqrstuvwxyz"[0...ARGV[0].to_i]}]+$/i
puts File.open(ARGV[1]).readlines.reject!{|l| l !~ p}
I do not reject words that contain digits. That would reject valid
Internet slang like "l8er" or "gn8", leetspeak like "1337" or "H4X0R",
and acronyms like I18N or L10N.
Josef 'Jupp' Schugt
- --
Blog available at
http://www.mynetcologne.de/~nc-schu...
PGP key with id 6CC6574F available at
http://wwwkeys.d...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora -
http://enigmail....
iD8DBQFGtfavrhv7B2zGV08RAg8MAJ0a592lTGVyH636SdZzcK8qDP3AogCgnIBZ
+CcWYwTWoMIP7XmSwqYG3OE=
=rKWG
-----END PGP SIGNATURE-----
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: [QUIZ] Numbers Can Be Words (#133
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password