View Single Post
Old 12-27-2005, 07:53 PM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
You can replace your nested loops with a (your favorite type!) recursive function. Basically the trigger for recursion would be the if statement that is at the end of each loop.

Aside from that though you could refactor this in a better fashion by
writing a function to handle permuting the array, that is a function which returns all possible combinations of the digits in an array of arbitrary size (algorithms for which are googleable). For all I know, the java array class might already have a method for this.

Then team up array.permute with a function to return a list of factors for a given integer. Now all you have to do for leastFactors() is pass the output from array.permute() to int.factor() and choose the one that returns the shortest list of factors.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote