Numbers which are the cube roots of the product of their proper divisors: Difference between revisions

→‎{{header|jq}}: def numbers_being_cube_roots_of_their_proper_divisors:
(→‎{{header|jq}}: def numbers_being_cube_roots_of_their_proper_divisors:)
Line 483:
def prod(s): reduce s as $x (1; . * $x);
 
# Output: the unordered stream of proper divisors of .
def proper_divisors:
. as $n
Line 497:
'''The Task'''
<syntaxhighlight lang=jq>
# Emit a stream beginning with 1 and followed by the integers that are
# cube-roots of their proper divisors
def numbers_being_cube_roots_of_their_proper_divisors:
range(1; infinite)
| select(prod(proper_divisors) == .*.*.);
 
# print first 50 and then the 500th, 5000th, and $limit-th
def task($limit):
"First 50 numbers which are the cube roots of the products of their proper divisors:",
( {label numbers50: [],$out
| foreach numbers_being_cube_roots_of_their_proper_divisors as $n (
count: 0,
n: 1 }{ numbers50: [],
| while( .count <= $limit count: 0};
.emit = null
| if .n | (prod(proper_divisors)count =+= .*.*.)1
| thenif .count +=> 1$limit
then break $out
| if .count <= 50
else thenif .numbers50count +<= [.n]50
else then .numbers50 += [$n]
end else .
| if .count <= 50 end
| if .count == 50
then .emit = .numbers50
elif .count | IN(500, 5000, $limit)
then .emit = "\(.count)th: \(.$n)"
else .
end
elseend .)
| .emit // empty ) ; end
| .n += 1 )
| .emit // empty ) ;
 
task(50000)
</syntaxhighlight>
 
{{out}}
<pre>
2,498

edits