Rare numbers: Difference between revisions

(→‎Turbo: Updated to incorporate improvements suggested by Enter your username.)
Line 3,401:
 
=== not optimized ===
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 returnsappears to return the right answer, tested with individual numbers.
 
{{works with|langur|0.8.11}}
<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
Line 3,425:
# if you have the time...
writeln "the first 5 rare numbers: ", .findfirst(5)</lang>
 
With 0.8.11, reverse() also reverses the digits of a number. Without this, you could write your own function to do so as follows, if not passed any negative numbers.
 
<lang langur>val .reverse = f toNumber join reverse split toString .n</lang>
 
=={{header|Phix}}==
1,007

edits