Thread Dynamisierung von Code - Grenzen der Machbarkeit? (13 answers)
Opened by ArthurDent at 2017-02-21 23:02

Muffi
 2017-02-22 14:31
#186155 #186155
User since
2012-07-18
1465 Artikel
BenutzerIn
[default_avatar]
Du kannsts auch ohne Rekursion machen.

Code (perl): (dl )
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 + 1 = 10

View full thread Dynamisierung von Code - Grenzen der Machbarkeit?