Abundant, deficient and perfect number classifications: Difference between revisions

Line 1,151:
<lang sh>$ jq -n -c -f AbundantDeficientPerfect.jq
{"deficient":15043,"perfect":4,"abundant":4953}</lang>
 
=={{header|Liberty BASIC}}==
<lang lb>
print "ROSETTA CODE - Abundant, deficient and perfect number classifications"
print
for x=1 to 20000
x$=NumberClassification$(x)
select case x$
case "deficient": de=de+1
case "perfect": pe=pe+1: print x; " is a perfect number"
case "abundant": ab=ab+1
end select
select case x
case 2000: print "Checking the number classifications of 20,000 integers..."
case 4000: print "Please be patient."
case 7000: print "7,000"
case 10000: print "10,000"
case 12000: print "12,000"
case 14000: print "14,000"
case 16000: print "16,000"
case 18000: print "18,000"
case 19000: print "Almost done..."
end select
next x
print "Deficient numbers = "; de
print "Perfect numbers = "; pe
print "Abundant numbers = "; ab
print "TOTAL = "; pe+de+ab
[Quit]
print "Program complete."
end
 
function NumberClassification$(n)
x=ProperDivisorCount(n)
for y=1 to x
PDtotal=PDtotal+ProperDivisor(y)
next y
if PDtotal=n then NumberClassification$="perfect": exit function
if PDtotal<n then NumberClassification$="deficient": exit function
if PDtotal>n then NumberClassification$="abundant": exit function
end function
 
function ProperDivisorCount(n)
n=abs(int(n)): if n=0 or n>20000 then exit function
dim ProperDivisor(100)
for y=2 to n
if (n mod y)=0 then
ProperDivisorCount=ProperDivisorCount+1
ProperDivisor(ProperDivisorCount)=n/y
end if
next y
end function
</lang>
{{out}}
<pre>
ROSETTA CODE - Abundant, deficient and perfect number classifications
 
6 is a perfect number
28 is a perfect number
496 is a perfect number
Checking the number classifications of 20,000 integers...
Please be patient.
7,000
8128 is a perfect number
10,000
12,000
14,000
16,000
18,000
Almost done...
Deficient numbers = 15043
Perfect numbers = 4
Abundant numbers = 4953
TOTAL = 20000
Program complete.
</pre>
 
=={{header|Lua}}==
Anonymous user