How to resolve the algorithm N'th step by step in the SETL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm N'th step by step in the SETL programming language
Table of Contents
Problem Statement
Write a function/method/subroutine/... that when given an integer greater than or equal to zero returns a string of the number followed by an apostrophe then the ordinal suffix.
Returns would include 1'st 2'nd 3'rd 11'th 111'th 1001'st 1012'th
Use your routine to show here the output for at least the following (inclusive) ranges of integer inputs: 0..25, 250..265, 1000..1025
Note: apostrophes are now optional to allow correct apostrophe-less English.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm N'th step by step in the SETL programming language
Source code in the setl programming language
program nth;
loop for r in [[0..25], [250..265], [1000..1025]] do
showrange(r);
end loop;
proc showrange(r);
i := 0;
loop for s in [nth(n) : n in r] do
putchar(rpad(s, 8));
if (i +:= 1) mod 6 = 0 then print(); end if;
end loop;
print();
end proc;
proc nth(n);
sfx := {[1,"st"], [2,"nd"], [3,"rd"]};
return str n +
if n div 10 mod 10 = 1
then "th"
else sfx(n mod 10) ? "th"
end if;
end proc;
end program;
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the TypeScript programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Rate counter step by step in the Crystal programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Java programming language
You may also check:How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the OCaml programming language