RosettaCodeData/Task/Nth/Elena/nth.elena
2024-03-06 22:25:12 -08:00

29 lines
702 B
Text

import extensions;
import system'math;
import system'routines;
extension op
{
ordinalize()
{
int i := self.Absolute;
if (new int[]{11,12,13}.ifExists(i.mod(100)))
{
^ i.toPrintable() + "th"
};
(i.mod(10)) =>
1 { ^ i.toPrintable() + "st" }
2 { ^ i.toPrintable() + "nd" }
3 { ^ i.toPrintable() + "rd" };
^ i.toPrintable() + "th"
}
}
public program()
{
console.printLine(new Range(0,26).selectBy(mssgconst ordinalize<op>[1]));
console.printLine(new Range(250,26).selectBy(mssgconst ordinalize<op>[1]));
console.printLine(new Range(1000,26).selectBy(mssgconst ordinalize<op>[1]))
}