CGI/Perl Guide | Learning Center | Forums | Advertise | Login Site Search: in Perl Guide PerlGuru Forums Learning Ctr
 MAIN INDEX SEARCHPOSTS WHO'S ONLINE LOG IN

Home: Perl Programming Help: Beginner: Re: [rovf] Recursive functions (an algorithm question): Edit Log

siskos1
Novice

Mar 28, 2010, 8:44 PM

Views: 3825
 Re: [rovf] Recursive functions (an algorithm question)
thanks a lot. i tried to solve this particular question today. and my code doesnt work for some reason. it is most likely about my references but i couldnt find. if you delete line 14 and line 25-27, you will see that it works fine but to get the all combinations, we have to introduce the results found in the previous level. thats where i am stuck. i am playing with this code for some hours, but the logic behind it seems ok to me. i thought maybe i miss something about references here. thanks in advance. + the problem in the first post is for any number that can be divided by 3 or 4 up to target number; here below code is for all possible combinations of dividers of target number. no difference in logic though.

 Code
`use strict; use warnings;  my @a =();   sub func   {  my \$y=shift; my \$x;  for (\$x=2; \$x<=\$y; \$x++)        {      my @copy_upper_array =  @a;      #line 14            if(\$y % \$x == 0)                  {                                                         foreach( @a) {  push ( @{\$_}, \$x );   }                    my \$array_ref = [ \$x ];                         push(@a, \$array_ref);                                         if( @copy_upper_array )                     #line 25-27      {  foreach (@copy_upper_array)  {   unshift(@a, \$_);  }    }                  }         }  }   &func(12);   foreach(   @a  ) { print "\n  @{\$_}" ; }`

(This post was edited by siskos1 on Mar 28, 2010, 8:55 PM)

 Edit Log: Post edited by siskos1 (Novice) on Mar 28, 2010, 8:49 PM Post edited by siskos1 (Novice) on Mar 28, 2010, 8:50 PM Post edited by siskos1 (Novice) on Mar 28, 2010, 8:52 PM Post edited by siskos1 (Novice) on Mar 28, 2010, 8:53 PM Post edited by siskos1 (Novice) on Mar 28, 2010, 8:54 PM Post edited by siskos1 (Novice) on Mar 28, 2010, 8:55 PM

 Search this forum this category all forums for All words Any words Whole Phrase (options) Powered by Gossamer Forum v.1.2.0