Factor-perfect numbers
func erdosFactorCount (n) is cached {
var sum = 1
var divs = proper_divisors(n).slice(1)
divs.each {|d|
sum += __FUNC__(idiv(n,d))
}
return sum
}
func moreMultiples (to, from) {
var oneMores = []
from.each {|j|
if (j > to.tail && to.tail.divides(j)) {
oneMores << [to..., j]
}
}
for k in (oneMores.range) {
oneMores << __FUNC__(oneMores[k], from)...
}
return oneMores
}
var listing = [[1]]
listing << moreMultiples([1], proper_divisors(48))...
listing.each {|a| a << 48 }
say "#{listing.len} sequences using first definition:"
listing.slices(3).each { .map { .join(' ') }.map{ '%-20s' % _ }.join.say }
var listing2 = gather {
for j in (^listing.len) {
var seq = listing[j]
take(1..seq.end -> map {|j| seq[j] / seq[j-1] })
}
}
say "\n#{listing2.len} sequences using second definition:"
listing2.slices(3).each { .map { .join(' ') }.map{ '%-20s' % _ }.join.say }
print "\nOEIS A163272: "
say [0, 1, (1..Inf -> lazy.map {|n| 4*n }.grep{|n| erdosFactorCount(n) == n }.first(5))...]Output:
Last updated
Was this helpful?