| A Continental Perl Adventure | Day One | 15 of 96 : [PREV] [NEXT] |
Permutations using ClosuresUsing closures and a technique called memoization, we can reduce this by up to 25%. How?Each call comprises a set of arguments (items in the list). Should a potion of those arguments be the same, eg last 4 items from a total of 11, will occur 5040, the resulting set will always be the same, and so reducing the the need to make 24 * 5039 further calls. The function remembers permutations of subsets that it's already done, which it therefore doesn't need to calculate it again, and so just returns the know result of the permutation. |
| © 2003 Barbie barbie@missbarbell.co.uk | Home | http://birmingham.pm.org/ |