1
2
3
4
5
6
7
for ($i1 = 0; $i1 <= $k; $i1++) {
for ($i2 = 0; $i2 <= $k; $i2++) {
for ($i3 = 0; $i3 <= $k; $i3++ {
print "hier ist alles zusammen: $i1\t$i2\$i3\t und wird weiter verarbeitet\n";
};
};
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
my $n = 3; my $k = 2; sub iterate { my ($curr_n, @values) = @_; for my $curr_k (1..$k) { if ($curr_n == $n) { say join(', ', (@values, $curr_k)); } else { iterate($curr_n +1, (@values, $curr_k)); } } } iterate(1, ());
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
my $n = 3; my $k = 2; my @todo_list = ([ 0, [] ]); while (@todo_list) { my $todo = pop @todo_list; my $local_n = $todo->[0] +1; for my $curr_k (1..$k) { if ($local_n == $n) { say join(', ', @{$todo->[1]}, $curr_k); } else { push @todo_list, [ $local_n, [ @{$todo->[1]}, $curr_k ] ]; } } }
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
#!/usr/bin/python # coding: utf-8 n = 3; k = 2; def toFlatString(todo1, curr_k, callevel, a = None): if a is None: a = [] for i in todo1: if isinstance(i, list): toFlatString(i, None, callevel + 1, a) else: a.append(str(i)) if callevel == 1: a.append(str(curr_k)) return ", ".join(a) todo_list = [[0, []]] while todo_list: todo = todo_list.pop() local_n = todo[0] + 1; for curr_k in range(k + 1): if local_n == n: print toFlatString(todo[1], curr_k, 1) else: todo_list.append([local_n, [todo[1], curr_k]])
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
#!/usr/bin/perl use warnings; use strict; use feature 'say'; use Data::Dumper; $Data::Dumper::Indent = 0; my $n = 3; my $k = 2; my @todo_list = ([ 0, [] ]); while (@todo_list) { my $todo = pop @todo_list; my $local_n = $todo->[0] +1; for my $curr_k (1..$k) { if ($local_n == $n) { print "x "; print Dumper(\@todo_list); print " -> "; say join(', ', @{$todo->[1]}, $curr_k); } else { push @todo_list, [ $local_n, [ @{$todo->[1]}, $curr_k ] ]; print Dumper(\@todo_list); print " : "; say join(', ', @{$todo->[1]}, $curr_k); } } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$VAR1 = [[1,[1]]]; : 1
$VAR1 = [[1,[1]],[1,[2]]]; : 2
$VAR1 = [[1,[1]],[2,[2,1]]]; : 2, 1
$VAR1 = [[1,[1]],[2,[2,1]],[2,[2,2]]]; : 2, 2
x $VAR1 = [[1,[1]],[2,[2,1]]]; -> 2, 2, 1
x $VAR1 = [[1,[1]],[2,[2,1]]]; -> 2, 2, 2
x $VAR1 = [[1,[1]]]; -> 2, 1, 1
x $VAR1 = [[1,[1]]]; -> 2, 1, 2
$VAR1 = [[2,[1,1]]]; : 1, 1
$VAR1 = [[2,[1,1]],[2,[1,2]]]; : 1, 2
x $VAR1 = [[2,[1,1]]]; -> 1, 2, 1
x $VAR1 = [[2,[1,1]]]; -> 1, 2, 2
x $VAR1 = []; -> 1, 1, 1
x $VAR1 = []; -> 1, 1, 2