]> iEval git - clump.git/blob - intermediare.pl
91df8ae723dc4f842e6c4a8ca534fee5f97f535e
[clump.git] / intermediare.pl
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 my @initial = (
6 [qw/1 1 1 0/],
7 [qw/0 0 0 0/],
8 [qw/0 0 0 0/],
9 [qw/0 0 0 0/],
10 );
11
12 my @diffs = (
13 [-1, 0],
14 [-1, 1],
15 [0 , 1],
16 [1 , 1],
17 [1 , 0],
18 [1 , -1],
19 [0 , -1],
20 [-1, -1]
21 );
22
23 sub sum_for_diff {
24 my ($diff) = @_;
25 my @result;
26 my ($dx, $dy) = @{$diffs[$diff]};
27 for my $i (0 .. 3) {
28 for my $j (0 .. 3) {
29 my $ni = ($i + 4 + $dx) % 4;
30 my $nj = ($j + 4 + $dy) % 4;
31 $result[$i][$j] = $initial[$ni][$nj];
32 }
33 }
34 # say 'For diff ', $diff, ': ';
35 # say join ' ', @$_ for @result;
36 @result
37 }
38
39 use Data::Dumper;
40
41 my @sum1;
42 my @sum2;
43
44 for my $x (qw/0 2 4 6/) {
45 @sum1 = sum_for_diff $x;
46 @sum2 = sum_for_diff ($x+1);
47
48 my ($sum1, $sum2, $sumA, $sumB) = (0, 0, 0, 0);
49 my $cnt = 0;
50 for my $i (0 .. 3) {
51 for my $j (0 .. 3) {
52 my $sum = $sum1[$i][$j] + $sum2[$i][$j];
53 $sum1 += $sum1[$i][$j] << $cnt;
54 $sum2 += $sum2[$i][$j] << $cnt;
55 $sumA += ($sum&1) << $cnt;
56 $sumB += ($sum&2) << ($cnt - 1);
57 $cnt++;
58 }
59 }
60
61 printf "%04X + %04X = %016b %016b\n", $sum1, $sum2, $sumA, $sumB;
62 }
This page took 0.059433 seconds and 4 git commands to generate.