Rare numbers: Difference between revisions
→{{header|langur}}
imported>Sassela (Add Racket solution) |
Langurmonkey (talk | contribs) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 3,896:
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 appears to return the right answer, tested with individual numbers.
▲<syntaxhighlight lang="langur">val .perfectsquare = f isInteger .n ^/ 2
val .israre =
val .r = reverse(.n)
if .n == .r: return false
Line 3,907 ⟶ 3,906:
}
val .findfirst =
for[=[]] .i = 0; len(_for) < .max; .i += 1 {
if .israre(.i) {
_for ~= [.i]
}
}
Line 3,918 ⟶ 3,916:
# if you have the time...
writeln "the first 5 rare numbers: ", .findfirst(5)</syntaxhighlight>
=={{header|Lua}}==
Line 6,512 ⟶ 6,506:
===Traditional===
About 9.5 minutes to find the first 25 rare numbers.
<syntaxhighlight lang="
import "./fmt" for Fmt
class Term {
Line 6,786 ⟶ 6,780:
===Turbo===
Ruffles the feathers a little with a time 5 times quicker than the 'traditional' version.
<syntaxhighlight lang="
import "./fmt" for Fmt
import "./date" for Date
class Z2 {
|