{"id":28254741,"url":"https://github.com/practicalli/numbers-to-words","last_synced_at":"2026-07-03T13:01:51.785Z","repository":{"id":140403465,"uuid":"275200272","full_name":"practicalli/numbers-to-words","owner":"practicalli","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-14T22:37:10.000Z","size":58,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"live","last_synced_at":"2025-05-25T10:43:11.409Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/practicalli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["practicalli-johnny"]}},"created_at":"2020-06-26T16:27:44.000Z","updated_at":"2025-04-14T22:37:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"3a03d488-4fce-4c3f-99df-a56cf6aefb2b","html_url":"https://github.com/practicalli/numbers-to-words","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/practicalli/numbers-to-words","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practicalli%2Fnumbers-to-words","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practicalli%2Fnumbers-to-words/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practicalli%2Fnumbers-to-words/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practicalli%2Fnumbers-to-words/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/practicalli","download_url":"https://codeload.github.com/practicalli/numbers-to-words/tar.gz/refs/heads/live","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practicalli%2Fnumbers-to-words/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260096618,"owners_count":22958083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-19T20:15:32.133Z","updated_at":"2026-07-03T13:01:46.753Z","avatar_url":"https://github.com/practicalli.png","language":"Clojure","funding_links":["https://github.com/sponsors/practicalli-johnny"],"categories":[],"sub_categories":[],"readme":"# word-conversion\n\nA Clojure library to convert numerical representation of whole numbers to British English representation, using correct basic grammar.\n\n\n## Usage\n\nAs this is a library and does not include a user interface.  Open a REPL and load the namespace then evaluate the examples and experiment with the design journal section.\n\n### Command Line / Terminal\nIn a terminal window, change to the root of the `word-conversion` project and run the command `lein repl`.  Once the repl starts either include the project namespace in the current `user` namespace, using `(require 'word-conversion.core)`\n\n### Clojure aware editors\nOr open this project in your favourite editor, run a repl and switch to the `word-conversion.core` namespace.\n\n### main function\n\nUse the `speak-number-as-words` to convert a number to a sentence that describes that word.  For example:\n\n```clojure\n(speak-number-as-words british-english-dictionary 1105)\n\n```\n\n## License\n\nCreative Commons Attribution Share-Alike 4.0 International\n\nCopyright © 2019 John Stevenson\n\n\n## Number to Words Conversion\n\n### Problem Description\nCreate a Clojure library, suitable for use in a server-side application,that can take a Java int in the range 0 to 999,999,999 inclusive andreturns the equivalent number, as a String, in British English words.\n\n### Sample Data\n\n|     Input | Output                                                                                                   |\n|-----------|----------------------------------------------------------------------------------------------------------|\n|         0 | zero                                                                                                     |\n|         1 | one                                                                                                      |\n|        21 | twenty  one                                                                                              |\n|       105 | one hundred  and five                                                                                    |\n|       123 | one hundred and twenty three                                                                             |\n|      1005 | one thousand and five                                                                                    |\n|      1042 | one thousand and forty two                                                                               |\n|      1105 | one thousand one hundred and five                                                                        |\n|  56945781 | fifty six million nine hundred and forty five thousand seven hundred and eighty one                      |\n| 999999999 | nine hundred and ninety  nine million nine hundred and ninety nine thousand nine hundred and ninety nine |\n\n\n### Guidelines\n\n●The solution must be correct.\nPlease pay attention to the specific conventions of British English, particularly concerning the use of ‘and’between certain phrases.\n\n●The solution is not expected to involve a command line or GUI application\n– we’re looking for a Clojure library that could be packaged as a jar andused in a larger application.\n\n\n\n## Refactored algorithm\n- take a dictionary and a number\n- convert number to string\n- split into individual digits (characters) of that number\n- partition from right into groups of threes (partition-all where there are less than 3 digits)\n- process each partition of three (hundreds, tens, ones)\n- convert partitions from digits (characters) to words (keep return values in same groups)\n-- apply specific look-up for tens and ones combination\n--- if ten = \\0 then lookup digit in digits dictionary (a digit is whole numbers 0-9), dont return anything for tens\n--- if ten = \\1 then combine ten and digit and lookup in tens dictionary (could refine this around teens)\n--- if ten \u003e= \\2 then lookup ten in tens dictionary and digit in digits dictionary\n-- lookup hundred in digits dictionary and post-fix hundred\n- apply relevant grammar rules\n-- andify\n--- any number after one hundred requires an `and`\n--- no and after thousand if there is a hundred value or no value at all\n-- hyphenate\n- add number levels based on groups, each group after the first is a higher number level (thousand, million, billion)\n- turn in to a string sentence\n\nwhere to apply the dictionary?\n\n### andify-sentence\n\none hundred\none hundred and one\none hundred and ten\none hundred and eleven\n...\nany number after one hundred requires an and\n\n\none thousand\none thousand and one\none thousand and ten\none thousand one hundred\none thousand one hundred and one\none thousand one hundred and ten\none thousand nine hundred and ninety nine\n...\nno and after thousand if there is a hundred value or no value at all\n\nthe same for million, billion, trillion\n\none hundred thousand\none hundred and one thousand\none hundred and ten thousand\none hundred thousand and one\none hundred thousand and ten\none hundred thousand one hundred\none hundred thousand one hundred and one\none hundred thousand one hundred and ten\none hundred and one thousand one hundred and ten\n\n\n## Original Analysis of the problem statement\n\nThoughts about the solution before a personal matter interrupted solving the solution.\n\n### Notes\n* the British English words are all lower case, no capitalisation is required for the start of each sentence.\n\n\n### Initial thoughts for a solution\n\nTaking a simplest set first approach:\n\n#### Convert each word to a string using a simple lookup\n\nDefine a dictionary that maps numbers 0 to 9 to their word equivalents.\n\n\n#### Insert the number scales in the correct places\n\nInsert `hundred`, `thousand`, and `million` number scale names into the words.\n\n\u003e Wondering if this needs to be done first or at least at the same time as converting from numbers to strings.\n\n\n#### Insert the correct grammar into the words (and)\n\nParse a collection of words inserting `and` at the appropriate point in the sentence.  The rules seem to be positional, so we can just process the word strings for the correct places to insert `and`.\n\nThe rules seem to be:\n- numbers between 101 and 999 have `and` after the first number (or before the last two numbers).\n- the above rule should be applied all at each number scale for numbers larger than 1001\n\n\n### Additional thoughts ###\n\n#### Splitting up a number into digits ####\n\nHow can we split up a number into its digits?  Unlike string, a number is not seen as a collection.  We can convert each number to a string, this would allow us to split the number into individual digits, although if using clojure.core functions then the string will be treated as a collection of characters.  Can we convert characters back to numbers (should we need to)?  Strings can be converted back to numbers easily with the `java.lang.Integer` class.\n\nIf we use strings or characters in our dictionary lookup, then we don't need to convert back.\n\nSome experiments in partitioning are in the design journal.\n\n\n#### replace each number with its whole value ####\n\nIf we took each digit in the original number and converted it to its representative number in terms of position, then the dictionary lookup becomes much simpler.\n\nFor example, if the original number is 12345, then we would first generate a sequence of `[10000 2000 300 40 5]`.\n\nThis approach seems to be pretty obvious, although we still need to group along number levels, for numbers such as 124,110 (One hundred and twenty four thousand, one hundred and ten)\n\n\n#### Break down numbers into their smallest parts\n\nReplacing the whole number with a value to represent each digit is close to how I want to solve this problem.  However, for larger numbers they still need to be broken down further and have some notation to represent their number level.  Then it is just a simple matter of using a dictionary to map over the individual numbers and levels to convert it to words.\n\nSome post processing on the converted sequence adds grammar correction to the words and gives a sentence by injecting `and` at the relevant place.  This seems to be after any instance of `hundred` which is followed by another number.\n\n\n## Interesting functions to consider\n\n`partition` will group consistently and provide an simple way to insert new strings into the right parts of the words.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpracticalli%2Fnumbers-to-words","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpracticalli%2Fnumbers-to-words","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpracticalli%2Fnumbers-to-words/lists"}