Sha256: b323174c8a4eefa895d77b954cfd785134da1c31eb76fcb02827ab301babc7ad

Contents?: true

Size: 645 Bytes

Versions: 201

Compression:

Stored size: 645 Bytes

Contents

unit uCollatzconjecture;

interface
uses System.SysUtils;

type
  EIllegalNumber = class(Exception);

  function collatzSteps(aNumber: integer): integer;

implementation

function collatzSteps(aNumber: integer): integer;

  function computeCollatzValue(aValue: integer): integer;
  begin
    if odd(aValue) then
      result := aValue * 3 + 1
    else
      result := aValue div 2;
  end;

begin
  if aNumber <= 0 then
    raise EIllegalNumber.Create('error: Only positive numbers are allowed');

  result := 0;
  while (aNumber > 1) and (result < 1000) do
  begin
    aNumber := computeCollatzValue(aNumber);
    inc(result);
  end;
end;

end.

Version data entries

201 entries across 201 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.138 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.137 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.136 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.135 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.134 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.133 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.132 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.131 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.130 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.129 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.128 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.127 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.126 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.125 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.124 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.123 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.122 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.121 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas
trackler-2.2.1.120 tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureExample.pas