{ my @untested_blocks; my @needed_paths; sub test_all_paths { @needed_paths = @untested_blocks = (); _test_all_paths(@_); return @needed_paths; } sub _test_all_paths { my @to_test = @_; return unless @to_test; # Mark the first half as not to test. push @untested_blocks, [splice @to_test, 0, int(@to_test/2)]; # Find needed blocks in second half recursively if (not path_works( (map @$_, @untested_blocks), @needed_paths ) { if (1 == @to_test) { push @needed_paths, @to_test; } else { _test_all_paths(@to_test); } } # Find needed paths in the untested block we just added _test_all_paths( @{ pop @untested_blocks } ); } }