How to resolve the algorithm N'th step by step in the Clojure programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm N'th step by step in the Clojure 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 Clojure programming language
Source code in the clojure programming language
(defn n-th [n]
(str n
(let [rem (mod n 100)]
(if (and (>= rem 11) (<= rem 13))
"th"
(condp = (mod n 10)
1 "st"
2 "nd"
3 "rd"
"th")))))
(apply str (interpose " " (map n-th (range 0 26))))
(apply str (interpose " " (map n-th (range 250 266))))
(apply str (interpose " " (map n-th (range 1000 1026))))
(apply str (interpose " " (map #(clojure.pprint/cl-format nil "~:R" %) (range 0 26))))
You may also check:How to resolve the algorithm Create an HTML table step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Brilliant numbers step by step in the jq programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Rosetta Code/Fix code tags step by step in the Scala programming language
You may also check:How to resolve the algorithm Command-line arguments step by step in the Jsish programming language