Sha256: e4abf17fbf995c54f05df78c4f03fb15e77ad358eef1be7581ba814b9973aa50

Contents?: true

Size: 800 Bytes

Versions: 71

Compression:

Stored size: 800 Bytes

Contents

unit uPerfectNumbers;

interface
uses System.SysUtils;

type
  ENotNaturalNumber = class(Exception);

  NumberType = (Perfect, Abundant, Deficient);

  PerfectNumber = class
  public
    class function Classify(aNumber: integer): Numbertype; static;
  end;

implementation

class function PerfectNumber.Classify(aNumber: Integer): NumberType;
var sumOfFactors: integer;
    i: integer;
begin
  if aNumber < 1 then
    raise ENotNaturalNumber.Create('Classification is only possible for natural numbers.');

  sumOfFactors := 0;

  for i := 1 to aNumber - 1 do
    if aNumber mod i = 0 then
      sumOfFactors := sumOfFactors + i;

  if sumOfFactors < aNumber then
    result := Deficient
  else
    if sumOfFactors = aNumber then
      result := Perfect
    else
      result := Abundant;
end;

end.

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.179 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.178 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.177 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.176 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.175 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.174 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.173 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.172 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.171 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.170 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.169 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.167 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.166 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.165 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.164 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.163 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.162 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.161 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas
trackler-2.2.1.160 tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas