aboutsummaryrefslogtreecommitdiff
path: root/challenge-093/bkb/test/make-tree.pl
blob: 52b20199e82af401686433feafd31e2220823736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/home/ben/software/install/bin/perl

# Make like a tree and blow.

use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use JSON::Create 'create_json';

my $avd = 3;
my $min = 1;
my $max = 5;
my $prob = 1/$avd;
print create_json (node (0), indent => 1, sort => 1);
exit;

sub node
{
    my ($depth) = @_;
    if (($depth > $min && rand () < $prob) || $depth >= $max) {
	return number ();
    }
    my %node;
    $node{l} = node ($depth + 1);
    $node{r} = node ($depth + 1);
    $node{n} = number ();
    return \%node;
}

sub number
{
    return int (rand (10));
}