[Perl] my quiz (easy)

Ido Trivizki ido at hotmail.com
Wed Oct 23 06:46:58 PDT 2002


{
 my %seen;
 my @chars=('A'..'Z','a'..'z','0'..'9');
 sub unique{
  my $string;
  do{$string=join '',map $chars[rand @chars],1..$_[0]} until not exists
$seen{$_[0]}{$string};
  $seen{$_[0]}{$string}=1;
  $string;
 }
}

That is disregarding the problem Omer Zak suggested...
Now I'll try to golf it;)
----- Original Message -----
From: "Shlomo Yona" <shlomo at cs.haifa.ac.il>
To: <perl at perl.org.il>
Sent: Wednesday, October 23, 2002 11:47 AM
Subject: [Perl] my quiz (easy)


> Hello.
>
> Write a sub which receives some integer number
> greater than zero (lets call the number N), and
> return a string of N characters (over [A-Za-z0-9]).
>
> Calling the sub within the same run of the program should
> guarantee no two strings of length N are equal (i.e. all the
> strings of same length are uniqe).
>
> Good luck.
>
> Let's see who writes the nicest and perhaps smartest peace of code.
>
>
> --
> Shlomo Yona
> shlomo at cs.haifa.ac.il
> http://cs.haifa.ac.il/~shlomo/
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/cgi/listinfo/perl
>



More information about the Perl mailing list