-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog2.pl
88 lines (65 loc) · 1.73 KB
/
prog2.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
#!/usr/bin/perl
# Numbers with record number of iterations of x -> A306938(x) required to reach 1 (A306944).
# https://oeis.org/A306978
use 5.020;
use warnings;
use Math::AnyNum qw(:overload ceil sqrt floor round);
use experimental qw(signatures);
sub f ($n) {
my $count = 0;
my $cons = 0;
while ($n != 1) {
++$count;
if ($n % 3 == 0) {
$n = int($n/3);
$cons = 0;
}
else {
if ($cons) {
return -1;
}
$n = int($n * sqrt(3));
$cons = 1;
}
}
$count;
}
# Conjecture: sqrt(3) < a(n)/a(n-1) <= 3. - ~~~~
my $prev = 1;
foreach my $k(
2, 4, 7, 21, 49, 85, 253, 442, 766, 1327, 2299, 3982, 11839, 20506, 35518, 61519, 184557, 553645, 966928, 1674769, 2900785, 8701141, 25877593, 44821306, 77676682, 134539960, 402368674, 696922987, 1207106023, 2090768962, 3632578906,
6291811228, 10897736719, 18875433685
) {
#say "$k -> ", ceil($k * sqrt(3));
say "$k -> ", $k/$prev, ' -> ', ($k/$prev) > sqrt(3);
$prev = $k;
}
__END__
my $prev = 6291811228;
foreach my $n(1..10) {
my $curr = ceil($prev * sqrt(3));
say $curr;
if (f($curr) == -1) {
$curr = $prev * 3;
say "$curr -> ", f($curr);
}
else {
say "$curr -> ", f($curr);
}
$prev = $curr;
}
__END__
foreach my $k(77676682, 134539960, 402368674, 696922987, 1207106023, 2090768962, 3632578906, 6291811228, 10897736719, 18875433685, 56626301055) {
say "$k -> ", f($k);
}
__END__
# 6291811228 -- 55
# 10897736719 -- 57
# 18875433685 -- 59
my $record = 59;
foreach my $k(18875433685 * 1.732 ..1e11) {
if (f($k) > $record) {
$record = f($k);
say "New record: $record with $k";
}
}