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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
use strict;
use warnings;
#my $aref = [1, 2, 3];
#my @arr = @{$aref};
#push @{$aref}, 9;
#push @arr, 10;
#print "@{$aref}\n";
#print "@arr\n";
sub push2each{
my ($val, @arefs) = @_;
my @arrs;
foreach (@arefs){
my @cp = @{$_};
push @cp, $val;
push @arrs, \@cp;
}
return @arrs;
}
my @paths = (
[[1]],
[[1,1], [2]]
);
#my $aref = $paths[0];
#my $aref2 = $paths[1];
my @new_paths;
#foreach my $ref (@{$aref}){
# my @arr = @{$ref};
# push @arr, 2;
# push @new_paths, \@arr;
#}
sub climb{
my $n = shift;
if($n > $#paths){
my @new_paths = push2each(2, @{climb($n-2)});
push @new_paths, push2each(1, @{climb($n-1)});
$paths[$n] = \@new_paths;
}
return $paths[$n];
}
#push @new_paths, push2each (2, @{$paths[$#paths-1]});
#push @new_paths, push2each (1, @{$paths[$#paths]});
#push(@new_paths, push2each @{$aref2}, 1);
#foreach my $ref (@{$aref2}){
# my @arr = @{$ref};
# push @arr, 1;
# push @new_paths, \@arr;
#}
#$paths[@paths] = \@new_paths;
climb(10);
my $i = 0;
foreach my $pref (@paths){
my $count = @{$paths[$i]};
print "Counts: $count";
if($count < 50){
print ", ways:\n";
foreach my $aref (@{$pref}){
print "[@{$aref}] ";
}
print "\n";
}else{
print ", ways ommited\n";
}
++$i;
}
|