How to resolve the algorithm Rare numbers step by step in the langur programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Rare numbers step by step in the langur programming language
Table of Contents
Problem Statement
Rare numbers are positive integers n where:
Show all output here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Rare numbers step by step in the langur programming language
Source code in the langur programming language
val .perfectsquare = f isInteger .n ^/ 2
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)
val .reverse = f toNumber join reverse split .n
You may also check:How to resolve the algorithm Function definition step by step in the Phix programming language
You may also check:How to resolve the algorithm Tree traversal step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Balanced ternary step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Tonelli-Shanks algorithm step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Empty string step by step in the PHP programming language