X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=newstable.pl;h=67957b8d8da967c0e78d3dd9446823630b007219;hb=46a95fd39e0ef114dd837bed285f8ca6acf6bb32;hp=402de4f33aaf4e9077476e04c1e0aa5a75a30631;hpb=23c26e0422eda4cb868569e6c3cc4f41fe6e2864;p=clump.git diff --git a/newstable.pl b/newstable.pl index 402de4f..67957b8 100644 --- a/newstable.pl +++ b/newstable.pl @@ -4,17 +4,19 @@ use warnings; my @diffs = ( [-1, 0], - [-1, 1], [0 , 1], - [1 , 1], [1 , 0], - [1 , -1], [0 , -1], - [-1, -1] + [-1, -1], + [-1, 1], + [1 , 1], + [1 , -1], ); my @cpus; +my @newstable; + my $side = 4; # there are $side * $side CPUs for my $line (0 .. ($side - 1)) { @@ -24,9 +26,19 @@ for my $line (0 .. ($side - 1)) { for my $cpu (0 .. ($side * $side - 1)) { my $x = $cpu / $side; my $y = $cpu % $side; - for my $direction (0 .. 7) { + for my $direction (0 .. $#diffs) { my $nx = ($x + $diffs[$direction][0] + $side) % $side; my $ny = ($y + $diffs[$direction][1] + $side) % $side; - say "newstable[$cpu][$direction] = ", $cpus[$nx][$ny], ';'; + $newstable[$cpu][$direction] = $cpus[$nx][$ny]; + } +} + +for my $direction (0 .. $#diffs) { + print "$direction: news_out = {"; + printf 'news_in[%2d]', $newstable[$side * $side - 1][$direction]; + my @lst = 0 .. ($side * $side - 2); + for my $cpu (reverse @lst) { + printf ', news_in[%2d]', $newstable[$cpu][$direction]; } + say '};' }