Re: [QUIZ] Perl 'Easy' Quiz #2005-2

Brad Greenlee <[email protected]> Thu, 03 Feb 2005 21:43:07 -0800
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
My interpretation of "different" was a significantly different 
method/algorithm, usually using different functions. Given a particular 
algorithm there are certainly many possible variations; I usually tried 
a few and picked the fastest one.

-b


Rod Adams wrote:
>>
>>
>> Your mission is to write as many different solutions as possible to 
>> this problem. You should write functions which will accept a single 
>> scalar argument containing the string, and return a single scalar 
>> containing the modified string.
>>  
>>
> I came up with the following block to put at the head of a single script 
> file to make life a little easier.
> 
> It takes every sub defined in the file, and feeds it every string that 
> was provided on the command line, and prints out the results in a nice 
> table. It even counts them for you. Put this in, then you only need to 
> worry about making more subs.
> 
> for $name (sort keys %::) {
>  next unless *{$name}{CODE};
>  printf("%2d %10s:", ++$solcount, $name);
> 
>  for $input (@ARGV) {
>    print "   ", *{$name}{CODE}->($input);
>  }
>  print "\n";
> }
> 
> 
> And now... a question of what makes up a "different" solution. Let's say 
> I have M different ways of detecting if I need to keep going, and N 
> different ways of doing the next step. Theoritically, I could easily 
> generate M*N "different" solutions by combining all the different 
> options. However, this is not only tediius for me to generate, but also 
> seems a bit at odds with the spirit of TMTOWTDI.
> 
> What are other's thoughts on this?
> 
> -- Rod Adams
>