]> iEval git - clump.git/blob - newstable.pl
Add diagrams and pictures
[clump.git] / newstable.pl
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 my @diffs = (
6 [-1, 0],
7 [0 , 1],
8 [1 , 0],
9 [0 , -1],
10 [-1, -1],
11 [-1, 1],
12 [1 , 1],
13 [1 , -1],
14 );
15
16 my @cpus;
17
18 my @newstable;
19
20 my $side = 4; # there are $side * $side CPUs
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;
29 for my $direction (0 .. $#diffs) {
30 my $nx = ($x + $diffs[$direction][0] + $side) % $side;
31 my $ny = ($y + $diffs[$direction][1] + $side) % $side;
32 $newstable[$cpu][$direction] = $cpus[$nx][$ny];
33 }
34 }
35
36 for my $direction (0 .. $#diffs) {
37 print "$direction: news_out = {";
38 printf 'news_in[%2d]', $newstable[$side * $side - 1][$direction];
39 my @lst = 0 .. ($side * $side - 2);
40 for my $cpu (reverse @lst) {
41 printf ', news_in[%2d]', $newstable[$cpu][$direction];
42 }
43 say '};'
44 }
This page took 0.075742 seconds and 4 git commands to generate.