-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanna_numbers.pl
79 lines (73 loc) · 2.3 KB
/
anna_numbers.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#anna_numbers.pl: this script was inspired by some homework of my kids.
#see also https://de.wikipedia.org/wiki/Zahlenpalindrom
#Ralph Schuler, 2. Juni 2017
use strict;
use warnings;
use Data::Dumper;
my @z;
my %res;
my $cnt = 0;
for my $f (1001..9889) {
push(@z, $f) if substr($f, 0, 1) == substr($f, 3, 1) and substr($f, 1, 1) == substr($f, 2, 1);
}
for my $r (sort @z) {
for my $i (sort @z) {
my $sum = $r - $i;
next if $sum <= 0;
next unless substr($r, 0, 1) == substr($i, 1, 1);
next unless substr($r, 1, 1) == substr($i, 0, 1);
$cnt++;
printf("(%02d)\t$r - $i = %04d ", $cnt, $sum);
print "#" for (1..int((($sum / 100)) + 1) / 2);
print "\n";
$res{$sum} = 1;
}
}
print Dumper \%res;
__DATA__
(01) 2112 - 1221 = 0891 ####
(02) 3113 - 1331 = 1782 #########
(03) 3223 - 2332 = 0891 ####
(04) 4114 - 1441 = 2673 #############
(05) 4224 - 2442 = 1782 #########
(06) 4334 - 3443 = 0891 ####
(07) 5115 - 1551 = 3564 ##################
(08) 5225 - 2552 = 2673 #############
(09) 5335 - 3553 = 1782 #########
(10) 5445 - 4554 = 0891 ####
(11) 6116 - 1661 = 4455 ######################
(12) 6226 - 2662 = 3564 ##################
(13) 6336 - 3663 = 2673 #############
(14) 6446 - 4664 = 1782 #########
(15) 6556 - 5665 = 0891 ####
(16) 7117 - 1771 = 5346 ###########################
(17) 7227 - 2772 = 4455 ######################
(18) 7337 - 3773 = 3564 ##################
(19) 7447 - 4774 = 2673 #############
(20) 7557 - 5775 = 1782 #########
(21) 7667 - 6776 = 0891 ####
(22) 8118 - 1881 = 6237 ###############################
(23) 8228 - 2882 = 5346 ###########################
(24) 8338 - 3883 = 4455 ######################
(25) 8448 - 4884 = 3564 ##################
(26) 8558 - 5885 = 2673 #############
(27) 8668 - 6886 = 1782 #########
(28) 8778 - 7887 = 0891 ####
(29) 9119 - 1991 = 7128 ####################################
(30) 9229 - 2992 = 6237 ###############################
(31) 9339 - 3993 = 5346 ###########################
(32) 9449 - 4994 = 4455 ######################
(33) 9559 - 5995 = 3564 ##################
(34) 9669 - 6996 = 2673 #############
(35) 9779 - 7997 = 1782 #########
(36) 9889 - 8998 = 0891 ####
$VAR1 = {
'1782' => 1,
'6237' => 1,
'891' => 1,
'5346' => 1,
'3564' => 1,
'4455' => 1,
'2673' => 1,
'7128' => 1
};