Rare numbers: Difference between revisions
Content deleted Content added
→Turbo: Updated to incorporate improvements suggested by Enter your username. |
Langurmonkey (talk | contribs) |
||
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
{{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 =
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}}==
|