in reply to search overlap paths

I can't get an example running, (its late here), but I think to get all possible paths from the beginning number to the end number would involve a powerset. Something like if there are 8 numbers from lowest to highest, then you would need to generate the powerset of the 6 numbers between the highest and lowest numbers - 2^6 = 64 possible paths.

List::PowerSet can do this for you.

Here is a small program using the data you provided, (followed by the results of the run).

#!/usr/bin/perl use strict; use warnings; use List::PowerSet qw(powerset); my $nums = '0-200 200-400 400-600 600-800 800-1000 1000-2000 0,1800'; my %hash; @hash{ split /\D+/, $nums } = (); my @sorted = sort {$a<=> $b} keys %hash; my $start = shift @sorted; my $end = pop @sorted; my $ps = powerset(@sorted); for my $set (@$ps) { print join("-", $start, @$set, $end), "\n"; } __END__ 0-200-400-600-800-1000-1800-2000 0-400-600-800-1000-1800-2000 0-200-600-800-1000-1800-2000 0-600-800-1000-1800-2000 0-200-400-800-1000-1800-2000 0-400-800-1000-1800-2000 0-200-800-1000-1800-2000 0-800-1000-1800-2000 0-200-400-600-1000-1800-2000 0-400-600-1000-1800-2000 0-200-600-1000-1800-2000 0-600-1000-1800-2000 0-200-400-1000-1800-2000 0-400-1000-1800-2000 0-200-1000-1800-2000 0-1000-1800-2000 0-200-400-600-800-1800-2000 0-400-600-800-1800-2000 0-200-600-800-1800-2000 0-600-800-1800-2000 0-200-400-800-1800-2000 0-400-800-1800-2000 0-200-800-1800-2000 0-800-1800-2000 0-200-400-600-1800-2000 0-400-600-1800-2000 0-200-600-1800-2000 0-600-1800-2000 0-200-400-1800-2000 0-400-1800-2000 0-200-1800-2000 0-1800-2000 0-200-400-600-800-1000-2000 0-400-600-800-1000-2000 0-200-600-800-1000-2000 0-600-800-1000-2000 0-200-400-800-1000-2000 0-400-800-1000-2000 0-200-800-1000-2000 0-800-1000-2000 0-200-400-600-1000-2000 0-400-600-1000-2000 0-200-600-1000-2000 0-600-1000-2000 0-200-400-1000-2000 0-400-1000-2000 0-200-1000-2000 0-1000-2000 0-200-400-600-800-2000 0-400-600-800-2000 0-200-600-800-2000 0-600-800-2000 0-200-400-800-2000 0-400-800-2000 0-200-800-2000 0-800-2000 0-200-400-600-2000 0-400-600-2000 0-200-600-2000 0-600-2000 0-200-400-2000 0-400-2000 0-200-2000 0-2000

Replies are listed 'Best First'.
Re^2: search overlap paths
by Anonymous Monk on Jun 13, 2014 at 05:01 UTC