xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
Hi gurus,
I have big trouble!Last day, a python fan have claimed perl is a garbage language.python is much better than it. And raise a question to test perl's "ability":
using letters of a string,enumerate all secret code.
below is my code(I admit it's a garbage)
I'm a perl fan and zealot,but not a accomplished programmer.So my question is:
1.Who can transfer his code to perl, or tell me algorithm of his code? I don't know python at all!
2.We could write a better code with perl,couldn't we?
Thanks in advance for answer my foolish and childish question!
All responds are appreciated!
I have big trouble!Last day, a python fan have claimed perl is a garbage language.python is much better than it. And raise a question to test perl's "ability":
using letters of a string,enumerate all secret code.
below is my code(I admit it's a garbage)
below is his code (with python)$letters = shift @ARGV ||"ABC"; @letter = split //,$letters; for $a (1..$#letter) { for $b (1..$#letter) { for $c (1..$#letter) { $scode = $letter[$c].$letter[$b].$letter[$a] +; print $scode."\n"; } } }
import string DEFAULT_CHAR_SET = string.letters + string.digits + st +ring.punctuation class PasswordGenerator(object) : def __init__(self, seeds = DEFAULT_CHAR_SET) : self.seeds = seeds self.Outer = None self.cursor = 0 def next(self) : self.cursor += 1 if self.cursor == len(self.seeds) : self.cursor = 0 if not self.Outer : self.Outer = PasswordGenerator(s +elf.seeds) else : self.Outer.next() def value(self) : if self.Outer : return self.Outer.value() + self.seeds +[self.cursor] else : return self.seeds[self.cursor] def __iter__(self) : while 1 : yield self.value() self.next() if __name__ == "__main__" : g = PasswordGenerator() for i in g : print i
I'm a perl fan and zealot,but not a accomplished programmer.So my question is:
1.Who can transfer his code to perl, or tell me algorithm of his code? I don't know python at all!
2.We could write a better code with perl,couldn't we?
Thanks in advance for answer my foolish and childish question!
All responds are appreciated!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: secret code generator
by tilly (Archbishop) on Dec 19, 2006 at 06:33 UTC | |
by johngg (Canon) on Dec 19, 2006 at 10:22 UTC | |
by BrowserUk (Patriarch) on Dec 19, 2006 at 10:25 UTC | |
by johngg (Canon) on Dec 19, 2006 at 11:16 UTC | |
by Hofmator (Curate) on Dec 19, 2006 at 10:28 UTC | |
by johngg (Canon) on Dec 19, 2006 at 11:32 UTC | |
by xiaoyafeng (Deacon) on Dec 20, 2006 at 02:41 UTC | |
Re: secret code generator
by BrowserUk (Patriarch) on Dec 19, 2006 at 10:21 UTC | |
by tilly (Archbishop) on Dec 19, 2006 at 20:34 UTC | |
by BrowserUk (Patriarch) on Dec 20, 2006 at 02:49 UTC | |
by tilly (Archbishop) on Dec 21, 2006 at 03:58 UTC | |
by BrowserUk (Patriarch) on Dec 21, 2006 at 04:32 UTC | |
| |
Re: secret code generator
by SheridanCat (Pilgrim) on Dec 19, 2006 at 06:44 UTC | |
Re: secret code generator
by MonkOfAnotherSect (Sexton) on Dec 22, 2006 at 11:21 UTC | |
by BrowserUk (Patriarch) on Dec 22, 2006 at 12:03 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Seekers of Perl Wisdom