RosettaCodeData/Task/Proper-divisors/Langur/proper-divisors.langur
2024-04-19 16:56:29 -07:00

26 lines
674 B
Text

val .getproper = fn(.x) for[=[]] .i of .x \ 2 { if .x div .i: _for ~= [.i] }
val .cntproper = fn(.x) for[=0] .i of .x \ 2 { if .x div .i: _for += 1 }
val .listproper = fn(.x) {
if .x < 1: return null
for[=""] .i of .x {
_for ~= $"\.i:2; -> \.getproper(.i);\n"
}
}
writeln "The proper divisors of the following numbers are :"
writeln .listproper(10)
var .max = 0
var .most = []
for .n in 2 .. 20_000 {
val .cnt = .cntproper(.n)
if .cnt == .max {
.most = more .most, .n
} else if .cnt > .max {
.max, .most = .cnt, [.n]
}
}
writeln $"The following number(s) <= 20000 have the most proper divisors (\.max;)"
writeln .most