#!/usr/bin/perl
use strict;
use warnings;
my @ranges = 0;
push @ranges, $ranges[-1] + 1 + int rand 200 for 1..10000;
my @tests = map int rand $ranges[-1], 0..1000000;
match (\@ranges, \@tests);
sub div {
my ($border, $tests) = @_;
my ($lt, $ge) = ([], []);
push @{$_ < $border ? $lt : $ge}, $_ for @$tests;
($lt, $ge);
}
sub match {
my ($ranges, $tests) = @_;
if (@$ranges == 1) {
if (@$tests) {
print "tests in range $ranges->[0]:\n", join(", ", @$tests), "\n";
}
else {
print "range $ranges->[0] is empty\n";
}
}
else {
my $pivot = int((@$ranges + 1)/ 2);
my ($lt, $ge) = div($ranges->[$pivot], $tests);
match([@{$ranges}[0..$pivot-1]], $lt);
match([@{$ranges}[$pivot..$#$ranges]], $ge);
}
}