]> iEval git - clump.git/blame - newstable.pl
Add diagrams and pictures
[clump.git] / newstable.pl
CommitLineData
23c26e04
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5my @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
16my @cpus;
17
3b542afc
MG
18my @newstable;
19
7f1b6bd9 20my $side = 4; # there are $side * $side CPUs
23c26e04
MG
21
22for my $line (0 .. ($side - 1)) {
23 $cpus[$line] = [ ($line * $side) .. (($line + 1) * $side - 1) ]
24}
25
26for 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
36for 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}
This page took 0.029839 seconds and 4 git commands to generate.