]> iEval git - clump.git/blame - intermediare.pl
Add diagrams and pictures
[clump.git] / intermediare.pl
CommitLineData
23c26e04
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5my @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
12my @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
23sub 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
39use Data::Dumper;
40
41my @sum1;
42my @sum2;
43
44for 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.023999 seconds and 4 git commands to generate.