44 lines
1.2 KiB
Text
44 lines
1.2 KiB
Text
#!/usr/local/bin/spar
|
|
pragma annotate( summary, "perfect" );
|
|
pragma annotate( description, "In mathematics, a perfect number is a positive integer" );
|
|
pragma annotate( description, "that is the sum of its proper positive divisors, that is," );
|
|
pragma annotate( description, "the sum of the positive divisors excluding the number" );
|
|
pragma annotate( description, "itself." );
|
|
pragma annotate( see_also, "http://en.wikipedia.org/wiki/Perfect_number" );
|
|
pragma annotate( author, "Ken O. Burtch" );
|
|
pragma license( unrestricted );
|
|
|
|
pragma restriction( no_external_commands );
|
|
|
|
procedure perfect is
|
|
|
|
function is_perfect( n : positive ) return boolean is
|
|
total : natural := 0;
|
|
begin
|
|
for i in 1..n-1 loop
|
|
if n mod i = 0 then
|
|
total := @+i;
|
|
end if;
|
|
end loop;
|
|
return total = natural( n );
|
|
end is_perfect;
|
|
|
|
number : positive;
|
|
result : boolean;
|
|
begin
|
|
number := 6;
|
|
result := is_perfect( number );
|
|
put( number ) @ ( " : " ) @ ( result );
|
|
new_line;
|
|
|
|
number := 18;
|
|
result := is_perfect( number );
|
|
put( number ) @ ( " : " ) @ ( result );
|
|
new_line;
|
|
|
|
number := 28;
|
|
result := is_perfect( number );
|
|
put( number ) @ ( " : " ) @ ( result );
|
|
new_line;
|
|
|
|
end perfect;
|