Super-d numbers: Difference between revisions

Content added Content deleted
(R language)
Line 278: Line 278:
=={{header|C++}}==
=={{header|C++}}==
{{trans|D}}
{{trans|D}}
There are insufficiant bits avaiolable to calculate the super-5 or super-6 numbers without a biginteger library
There are insufficiant bits avalaible to calculate the super-5 or super-6 numbers without a biginteger library
<lang cpp>#include <iostream>
<lang cpp>#include <iostream>
#include <sstream>
#include <sstream>
Line 1,470: Line 1,470:
First 10 super-5: [4602,5517,7539,12955,14555,20137,20379,26629,32767,35689]
First 10 super-5: [4602,5517,7539,12955,14555,20137,20379,26629,32767,35689]
First 10 super-6: [27257,272570,302693,323576,364509,502785,513675,537771,676657,678146]</pre>
First 10 super-6: [27257,272570,302693,323576,364509,502785,513675,537771,676657,678146]</pre>


=={{header|R}}==

{{libheader|Rmpfr}}
Library is necessary to go beyond super-4 numbers. Indeed [https://cran.r-project.org/web/packages/Rmpfr/Rmpfr.pdf Rmpfr] allows to augment precision for floating point numbers. I didn't go for extra task, because it took some minutes for super-6 numbers.

<lang R>library(Rmpfr)
options(scipen = 999)

find_super_d_number <- function(d, N = 10){
super_number <- c(NA)
n = 0
n_found = 0
while(length(super_number) < N){
n = n + 1
test = d * mpfr(n, precBits = 200) ** d #Here I augment precision
test_formatted = .mpfr2str(test)$str #and I extract the string from S4 class object
iterable = strsplit(test_formatted, "")[[1]]
if (length(iterable) < d) next
for(i in d:length(iterable)){
if (iterable[i] != d) next
equalities = 0
for(j in 1:d) {
if (i == j) break
if(iterable[i] == iterable[i-j])
equalities = equalities + 1
else break
}
if (equalities >= (d-1)) {
n_found = n_found + 1
super_number[n_found] = n
break
}
}
}
message(paste0("First ", N, " super-", d, " numbers:"))
print((super_number))
return(super_number)
}

for(d in 2:6){find_super_d_number(d, N = 10)}
</lang>

{{out}}
<pre>
First 10 super-2 numbers:
[1] 19 31 69 81 105 106 107 119 127 131
First 10 super-3 numbers:
[1] 261 462 471 481 558 753 1036 1046 1471 1645
First 10 super-4 numbers:
[1] 1168 4972 7423 7752 8431 10267 11317 11487 11549 11680
First 10 super-5 numbers:
[1] 4602 5517 7539 12955 14555 20137 20379 26629 32767 35689
First 10 super-6 numbers:
[1] 27257 272570 302693 323576 364509 502785 513675 537771 676657 678146
</pre>


=={{header|Raku}}==
=={{header|Raku}}==