[oak perl] GNU and recursion
George Woolley
george at metaart.org
Tue Feb 18 14:13:33 CST 2003
Belden,
An iterative solution and a recursive solution. kool!
And the parentheses in the output are instructive. nice!
If I understand your solution,
I gather your answer to question one is:
GNU(0) equals GNU
GNU(1) equals GNU's Not Unix's Not Unix
GNU(2) equals GNU's Not Unix's Not Unix's Not Unix
GNU(3) equals GNU's Not Unix's Not Unix's Not Unix's Not Unix
...
Do you or anyone else have alternative suggestions
for answers to question one?
-- George
On Tuesday 18 February 2003 8:51 am, Belden Lyman wrote:
> George Woolley wrote:
> > My understanding from the GNU project site is that:
> > GNU is a recursive acronym for "GNU's Not Unix'"
> >
> > So I'm thinking:
> > GNU(0) equals GNU
> > GNU(1) equals GNU's Not Unix
> >
> > My first question: what do
> > GNU(2), GNU(3), etc. equal?
> >
> > And my second question:
> > what would the Perl function look like
> > for generating the values of GNU(0), GNU(1), GNU(2), etc.?
>
> An iterative solution:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> print gnu_i('GNU',2),"\n";
>
> sub gnu_i {
> my ($str, $itr) = @_;
> for ( 0..$itr ) {
> $str =~ s/GNU/(GNU's Not Unix)/;
> }
> $str;
> }
> __END__
>
>
>
> A recursive solution:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> print gnu_r('GNU',2), "\n";
>
> sub gnu_r {
> my ( $str, $itr ) = @_;
> if ( $itr < 0 ) {
> return $str;
> }
> $str =~ s/GNU/(GNU's Not Unix)/;
> return gnu_r( $str, --$itr );
> }
> __END__
>
>
> Belden
>
> _______________________________________________
> Oakland mailing list
> Oakland at mail.pm.org
> http://mail.pm.org/mailman/listinfo/oakland
More information about the Oakland
mailing list