Rare numbers: Difference between revisions

added langur language example
m (→‎{{header|Phix}}: fixed spelling of naive)
(added langur language example)
Line 3,391:
39: 8,650,327,689,541,457
40: 8,650,349,867,341,457</pre>
 
=={{header|langur}}==
It could look something like the following (ignoring whatever optimizations the other examples are using), if it was fast enough. I did not have the time/processor to test finding the first 5. The .israre() function returns the right answer, tested with individual numbers.
 
<lang langur>val .perfectsquare = f isInteger .n ^/ 2
val .reverse = f toNumber join reverse split toString .n
 
val .israre = f(.n) {
val .r = .reverse(.n)
if .n == .r: return false
val .sum = .n + .r
val .diff = .n - .r
.diff > 0 and .perfectsquare(.sum) and .perfectsquare(.diff)
}
 
val .findfirst = f(.max) {
for[=[]] .i = 0; ; .i += 1 {
if .israre(.i) {
_for ~= [.i]
if len(_for) == .max: break
}
}
}
 
# if you have the time...
writeln "the first 5 rare numbers: ", .findfirst(5)</lang>
 
=={{header|Phix}}==
1,007

edits