]>
Commit | Line | Data |
---|---|---|
23c26e04 MG |
1 | #!/usr/bin/perl |
2 | use v5.14; | |
3 | use warnings; | |
4 | ||
5 | my @diffs = ( | |
6 | [-1, 0], | |
23c26e04 | 7 | [0 , 1], |
23c26e04 | 8 | [1 , 0], |
23c26e04 | 9 | [0 , -1], |
46a95fd3 MG |
10 | [-1, -1], |
11 | [-1, 1], | |
12 | [1 , 1], | |
13 | [1 , -1], | |
23c26e04 MG |
14 | ); |
15 | ||
16 | my @cpus; | |
17 | ||
3b542afc MG |
18 | my @newstable; |
19 | ||
7f1b6bd9 | 20 | my $side = 4; # there are $side * $side CPUs |
23c26e04 MG |
21 | |
22 | for my $line (0 .. ($side - 1)) { | |
23 | $cpus[$line] = [ ($line * $side) .. (($line + 1) * $side - 1) ] | |
24 | } | |
25 | ||
26 | for my $cpu (0 .. ($side * $side - 1)) { | |
27 | my $x = $cpu / $side; | |
28 | my $y = $cpu % $side; | |
3b542afc | 29 | for my $direction (0 .. $#diffs) { |
23c26e04 MG |
30 | my $nx = ($x + $diffs[$direction][0] + $side) % $side; |
31 | my $ny = ($y + $diffs[$direction][1] + $side) % $side; | |
3b542afc MG |
32 | $newstable[$cpu][$direction] = $cpus[$nx][$ny]; |
33 | } | |
34 | } | |
35 | ||
36 | for my $direction (0 .. $#diffs) { | |
7f1b6bd9 | 37 | print "$direction: news_out = {"; |
46a95fd3 MG |
38 | printf 'news_in[%2d]', $newstable[$side * $side - 1][$direction]; |
39 | my @lst = 0 .. ($side * $side - 2); | |
40 | for my $cpu (reverse @lst) { | |
7f1b6bd9 | 41 | printf ', news_in[%2d]', $newstable[$cpu][$direction]; |
23c26e04 | 42 | } |
3b542afc | 43 | say '};' |
23c26e04 | 44 | } |