-
Notifications
You must be signed in to change notification settings - Fork 0
/
v.pl
116 lines (95 loc) · 3.12 KB
/
v.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# Date: 25 March 2019
# https://github.com/trizen
# Generate the Pascal-Fibonacci triangle.
# Definition by Elliott Line, Mar 22 2019:
# Consider a version of Pascal's Triangle: a triangular array with a single 1 on row 0,
# with numbers below equal to the sum of the two numbers above it if and only if that sum
# appears in the Fibonacci sequence. If the sum is not a Fibonacci number, `1` is put in its place.
# OEIS sequence:
# https://oeis.org/A307069
use 5.010;
use strict;
use warnings;
use ntheory qw(is_square :all);
use experimental qw(signatures);
sub is_fibonacci($n) {
my $m = 5 * $n * $n;
is_square($m - 4) or is_square($m + 4);
}
sub prime_power_count ($n) {
vecsum(map { prime_count(rootint($n, $_)) } 1 .. logint($n, 2));
}
sub isok($n) {
is_square($n);
#is_prime_power($n);
}
my @row = (1);
my $rows = 40;
my %seen;
my %table;
foreach my $n (1 .. $rows) {
my @t = (
map {
my $t = $row[$_] + $row[$_ + 1];
isok($t) ? $t : 0;
} 0 .. ($n - ($n % 2)) / 2 - 1
);
my @f = grep{isok($_) and !$seen{$_}++} @t;
#foreach my $k (@f) {
#say prime_power_count($k), ' -> ', $k, ' on row ', $n;
# $table{prime_power_count($k)} = $n;
#}
say "@row";
# The triangle is symmetric
# See also: https://photos.app.goo.gl/q3981kei8LJyvzgZ9
my @u = reverse(@t);
if ($n % 2 == 0) {
shift @u;
}
@row = (1, @t, @u, 1);
}
use Data::Dump qw(pp);
pp \%table;
__END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