Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- so the idea is to simplify the number structure and to do this we need to turn our number into a string so that we can easily split the magnitudes out
- once our number is a string we get the string to return true for this conditional statement (number.length % 3 == 0)
- from there we split the string into equal parts of three so for an example lets take 6984321847654131
- we'll split it to look like (006)(984)(321)(847)(654)(131)
- from here we can use our understanding on our numbering system of magnitude
- (006) = quadrillion
- (984) = trillions
- (321) = billions
- (847) = millions
- (654) = thousands
- (131) = hundreds and lower
- so the idea is to take groups of three which in our numbering system will always have the structure of (hundreds + tens/or ones)+ magnitude compound
- example:
- (for the trillions magnitude) (984)trillion will look like "nine hundred and eighty four trillion"
- so to turn our number into a word we can use a back tracking recursive algorithm (this is honestly here just to satisfy the program requirement and to get my rocks off to another world)
- so we push our lower magnitude numbers into a lifo structure which will look like this
- (006)
- (984)
- (321)
- (847)
- (654)
- (131)
- and once we have this pushed onto the stack we write the number to a string and += the number word together and pop it off the stack
- which gives us the result of
- six quadrillion nine hundred eighty four trillion three hundred twenty one billion eight hundred fourty seven million six hundred fifty four thousand one hundred and thirty one
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement