-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnarcisistic_harmonic_numbers.sf
85 lines (72 loc) · 1.8 KB
/
narcisistic_harmonic_numbers.sf
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
#!/usr/bin/ruby
# Numbers k such that the decimal expansion of the k-th harmonic number starts with the digits of k, in the same order.
# https://oeis.org/A337904
# This program generates such values of `k` (with possible gaps?).
func isok(k) {
k.harmreal.to_s.sub('.', '').first(k.len) == k.to_s
}
var n = 1
for k in (1..100) {
local Num!PREC = numify(4*(n + 10))
if (harmreal(k * 10**n).to_s.begins_with(k.to_s)) {
var (min, max) = (harmreal(k * 10**n) * 10**n, harmreal((k+1) * 10**n) * 10**n)
var v = bsearch_le(min, max, {|k|
(k / 10**n) <=> harmreal(k)
})
var ok = false
if (isok(v-1)) {
say v-1
ok = true
}
if (isok(v)) {
say v
ok = true
}
++n if ok
}
}
__END__
43
714
715
9763
122968
122969
1478366
17239955
196746419
2209316467
24499118645
268950072605
2928264676792
31663398162514
340383084842938
3640820101879826
38773735148047406
38773735148047407
411354473689969709
4349378018952283972
45849102972919835109
482017272880546223321
5055191842047792613562
52899904144628296988725
552458815055031196782525
5759002212954326201649741
59932476432458393252342721
622733769885549555429595981
6461284125481523641339765370
66950973792848320411792499601
692878680960562864969363384910
7162360810346449261192969637028
73958269462680913376461650794152
762919205903660944920523210661377
7862462356803215299533205007813806
80956434902985402104622557703016977
832874061781047994819672246576419514
8561758460942363424315837377300688366
87947013526805356793864093102783600499
902757327901213687376081267798908754616
9260377915106116852616564230637740582108
94931186568893878451195580899916418846736
972579864870501412683269238042780744028743
9958420807622547975400738352360988337988344