Aliquot sequence classifications: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Library name change.)
(→‎{{header|Wren}}: Now uses Wren-math module.)
Line 3,668: Line 3,668:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<lang ecmascript>import "/fmt" for Conv, Fmt
<lang ecmascript>import "/fmt" for Conv, Fmt
import "/math" for Int, Stat

class Classification {
class Classification {
construct new(seq, aliquot) {
construct new(seq, aliquot) {
Line 3,680: Line 3,682:
var THRESHOLD = 2.pow(47)
var THRESHOLD = 2.pow(47)
var sumProperDivisors = Fn.new { |n|
if (n < 2) return 0
var sqrt = n.sqrt.floor
var sum = 1
if (sqrt >= 2) {
sum = (2..sqrt).
where { |i| n % i == 0 }.
reduce(1) { |acc, i| acc + i + (n/i).floor }
}
if (sqrt * sqrt == n) sum = sum - sqrt
return sum
}
var listIndexOf = Fn.new { |lst, search|
var listIndexOf = Fn.new { |lst, search|
Line 3,706: Line 3,695:
var seq = [k]
var seq = [k]
while (true) {
while (true) {
last = sumProperDivisors.call(last)
last = Stat.sum(Int.properDivisors(last))
seq.add(last)
seq.add(last)
var n = seq.count
var n = seq.count