Skip to content

Instantly share code, notes, and snippets.

@reinaldoacdc
Created August 31, 2022 14:37
Show Gist options
  • Save reinaldoacdc/fce83ef1e9e8d8cfecb42223ffc25f49 to your computer and use it in GitHub Desktop.
Save reinaldoacdc/fce83ef1e9e8d8cfecb42223ffc25f49 to your computer and use it in GitHub Desktop.
IntegerHelper
unit IntegerHelper;
interface
type
TIntegerHelper = record helper for integer
function toRomans: String;
end;
implementation
function TIntegerHelper.toRomans: String;
const Numbers: arary[1..13] of Integer = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000];
const Romans: array[1..13] of String = ['I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M'];
var I, Decimal: Integer;
begin
Decimal := Self;
Result := '';
for I := 13 downto 1 do
begin
while (Self >= Numbers[I]) do
begin
Decumal := Decimal - Numbers[I];
Result := Result + Romans[I];
end;
end;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment