Created
August 31, 2022 14:37
-
-
Save reinaldoacdc/fce83ef1e9e8d8cfecb42223ffc25f49 to your computer and use it in GitHub Desktop.
IntegerHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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