Numerical and alphabetical suffixes
This task is about expressing numbers with an attached (abutted) suffix multiplier(s), the suffix(es) could be:
- an alphabetic (named) multiplier which could be abbreviated
- metric multiplier(s) which can be specified multiple times
- "binary" multiplies(s) which can be specified multiple times
- explanation marks (!) which indicate a factorial or multifactorial
The (decimal) numbers can be expressed generally as:
{±} {digits} {.} {digits} ────── or ────── {±} {digits} {.} {digits} {E or e} {±} {digits}
where:
- numbers won't have embedded blanks (contrary to the expaciated examples above where whitespace was used for readability)
- this task will only be dealing with decimal numbers, both in the mantissa and exponent
- ± indicates an optional plus or minus sign (+ or -)
- digits are the decimal digits (0 ──► 9)
- the digits can have comma(s) interjected to separate the periods (thousands) such as: 12,467,000
- . is the decimal point, sometimes also called a dot
- e or E denotes the use of decimal exponentiation (a number multiplied by raising ten to some power)
This isn't a pure or perfect definition of the way we express decimal numbers, but it should convey the intent for this task.
The use of the word periods (thousands) is not meant to confuse, that word (as used above) is what the comma separates;
the groups of decimal digits are called periods, and in almost all cases, are groups of three decimal digits.
If an e or E is specified, there must be a legal number expressed before it, and there must be a legal (exponent) expressed after it.
Also, there must be some digits expressed in all cases, not just a sign and/or decimal point.
Superfluous signs, decimal points, exponent numbers, and zeros need not be preserved.
I.E.: +7 007 7.00 7E-0 7E000 70e-1 could all be expressed as 7
All numbers to be "expanded" can be assumed to be valid and there won't be a requirement to verify their validity.
- Abbreviated alphabetic suffixes to be supported (where the capital letters signify the minimum abbreation that can be used)
PAIRs multiply the number by 2 (as in pairs of shoes or pants) SCOres multiply the number by 20 (as 3score would be 60) DOZens multiply the number by 12 GRoss multiply the number by 144 (twelve dozen) GREATGRoss multiply the number by 1,728 (a dozen gross) GOOGLEs multiply the number by 10^100 (ten raised to the 100&sup>th power)
Note that the plurals are supported, even though they're usually used when expressing exact numbers (She has 2 dozen eggs, and dozens of quavas)
- Metric suffixes to be supported (whether or not they're officially sanctioned)
K multiply the number by 10^3 kilo (1,000) M multiply the number by 10^6 mega (1,000,000) G multiply the number by 10^9 giga (1,000,000,000) T multiply the number by 10^12 tera (1,000,000,000,000) P multiply the number by 10^15 peta (1,000,000,000,000,000) E multiply the number by 10^18 exa (1,000,000,000,000,000,000) Z multiply the number by 10^21 zetta (1,000,000,000,000,000,000,000) Y multiply the number by 10^24 yotta (1,000,000,000,000,000,000,000,000) X multiply the number by 10^27 xenta (1,000,000,000,000,000,000,000,000,000) W multiply the number by 10^30 wekta (1,000,000,000,000,000,000,000,000,000,000) V multiply the number by 10^33 vendeka (1,000,000,000,000,000,000,000,000,000,000,000) U multiply the number by 10^36 udekta (1,000,000,000,000,000,000,000,000,000,000,000,000)
- Binary suffixes to be supported (whether or not they're officially sanctioned)
Ki multiply the number by 2^10 kibi (1,024) Mi multiply the number by 2^20 mebi (1,048,576) Gi multiply the number by 2^30 gibi (1,073,741,824) Ti multiply the number by 2^40 tebi (1,099,571,627,776) Pi multiply the number by 2^50 pebi (1,125,899,906,884,629) Ei multiply the number by 2^60 exbi (1,152,921,504,606,846,976) Zi multiply the number by 2^70 zeb1 (1,180,591,620,717,411,303,424) Yi multiply the number by 2^80 yobi (1,208,925,819,614,629,174,706,176) Xi multiply the number by 2^90 xebi (1,237,940,039,285,380,274,899,124,224) Wi multiply the number by 2^100 webi (1,267,650,600,228,229,401,496,703,205,376) Vi multiply the number by 2^110 vebi (1,298,074,214,633,706,907,132,624,082,305,024) Ui multiply the number by 2^120 uebi (1,329,227,995,784,915,872,903,807,060,280,344,576)
All of the metric and binary suffixes can be expressed in lowercase, uppercase, or mixed case.
All of the metric and binary suffixes can be stacked (expressed multiple times), and also be intermixed:
I.E.: 123k 123K 123GKi 12.3GiGG 12.3e-7T .78E100e
- Factorial suffixes to be supported
! compute the (regular) factorial product: 5! is 5 × 4 × 3 × 2 × 1 = 120 !! compute the double factorial product: 8! is 8 × 6 × 4 × 2 = 384 !!! compute the triple factorial product: 8! is 8 × 5 × 2 = 80 !!!! compute the quadruple factorial product: 8! is 8 × 4 = 32 !!!!! compute the quintuple factorial product: 8! is 8 × 3 = 24 ··· the number of factorial symbols that can be specified is to be unlimited (as per what can be/entered/typed) ···
Note that these factorial products aren't super─factorials where (4!)! would be (24)!.
Factorial suffixes aren't, of course, the usual type of multipliers, but are used here in a similar vein.
Multifactorials aren't to be confused with super─factorials where (4!)! would be (24)!.
- Task
-
- Using the test cases (below), show the "expanded" numbers here, on this page.
- For each list, show the input on one line, and also show the output on one line.
- When showing the input line, keep the spaces (whitespace) and case (capitalizations) as is.
- For each result (list) displayed on one line, separate each number with two blanks.
- Add commas to the output numbers were appropriate.
- Test cases
2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre 1,567 +1.567k 0.1567e-2m 25.123kK 25.123m 2.5123e-00002G 25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei -.25123e-34Vikki 2e-77gooGols 9! 9!! 9!!! 9!!!! 9!!!!! 9!!!!!! 9!!!!!!! 9!!!!!!!! 9!!!!!!!!!
where the last number for the factorials has nine factorial symbols (!) after the 9
- Related tasks
-
- Multifactorial (which has a clearer and more succinct definition of multifactorials.)
- Factorial
- Abbreviations, simple
- Abbreviations, easy
- Abbreviations, automatic
- Longest common prefix
REXX
<lang rexx>/*REXX pgm converts numbers (with commas) with suffix multipliers──►pure decimal numbers*/ numeric digits 2000 /*allow the usage of ginormous numbers.*/ @.=; @.1= '2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre'
@.2= '1,567 +1.567k 0.1567e-2m' @.3= '25.123kK 25.123m 2.5123e-00002G' @.4= '25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei' @.5= '-.25123e-34Vikki 2e-77gooGols' @.6= 9! 9!! 9!!! 9!!!! 9!!!!! 9!!!!!! 9!!!!!!! 9!!!!!!!! 9!!!!!!!!!
parse arg x /*obtain optional arguments from the CL*/ if x\== then do; @.2=; @.1=x /*use the number(s) specified on the CL*/
end /*allow user to specify their own list.*/ /* [↓] handle a list or multiple lists*/ do n=1 while @.n\==; $= /*process each of the numbers in lists.*/ say 'numbers= ' @.n /*echo the original arg to the terminal*/
do j=1 for words(@.n); y= word(@.n, j) /*obtain a single number from the input*/ $= $ ' 'commas( num(y) ) /*process a number; add result to list.*/ end /*j*/ /* [↑] add commas to number if needed.*/ /* [↑] add extra blank betweenst nums.*/ say ' result= ' strip($); say /*echo the result(s) to the terminal. */ end /*n*/ /* [↑] elide the pre-pended blank. */
exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ isInt: return datatype( arg(1), 'Whole') /*return 1 if arg is an integer, or 0 */ isNum: return datatype( arg(1), 'Number') /* " " " " " a number. " " */ p: return word( arg(1), 1) /*pick 1st argument or 2nd argument. */ ser: say; say '***error*** ' arg(1); say; exit 13 shorten:procedure; parse arg a,n; return left(a, max(0, length(a) - p(n 1) ) ) /*──────────────────────────────────────────────────────────────────────────────────────*/ $fact!: procedure; parse arg x _ .; L= length(x); n= L - length(strip(x, 'T', "!") )
if n<=-n | _\== | arg()\==1 then return x; z= left(x, L - n) if z<0 | \isInt(z) then return x; return $fact(z, n)
/*──────────────────────────────────────────────────────────────────────────────────────*/ $fact: procedure; parse arg x _ .; arg ,n ! .; n= p(n 1); if \isInt(n) then n= 0
if x<-n | \isInt(x) |n<1 | _||!\== |arg()>2 then return x||copies("!",max(1,n)) s= x // n; if s==0 then s= n /*compute where to start multiplying. */ != 1 /*the initial factorial product so far.*/ do j=s to x by n; != !*j /*perform the actual factorial product.*/ end /*j*/ /*{operator // is REXX's ÷ remainder}*/ return ! /* [↑] handles any level of factorial.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/ $sfxa: parse arg u,s 1 c,m; upper u c /*get original version & upper version.*/
if pos( left(s, 2), u)\==0 then do j=length(s) to compare(s, c)-1 by -1 if right(u, j) \== left(c, j) then iterate _= left(u, length(u) - j) /*get the num.*/ if isNum(_) then return m * _ /*good suffix.*/ leave /*return as is*/ end return arg(1) /* [↑] handles an alphabetic suffixes.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/ $sfx!: parse arg y; if right(y, 1)=='!' then y= $fact!(y)
if \isNum(y) then y=$sfxz(); if isNum(y) then return y; return $sfxm(y)
/*──────────────────────────────────────────────────────────────────────────────────────*/ $sfxm: parse arg z 1 w; upper w; @= 'KMGTPEZYXWVU'; b= 1000
if right(w, 1)=='I' then do; z= shorten(z); w= z; upper w; b= 1024 end _= pos( right(w, 1), @); if _==0 then return arg(1) n= shorten(z); r= num(n, , 1); if isNum(r) then return r * b**_ return arg(1) /* [↑] handles metric or binary suffix*/
/*──────────────────────────────────────────────────────────────────────────────────────*/ $sfxz: return $sfxa( $sfxa( $sfxa( $sfxa( $sfxa( $sfxa(y, 'PAIRs', 2), 'DOZens', 12), ,
'SCores', 20), 'GREATGRoss', 1728), 'GRoss', 144), 'GOOGOLs', 1e100)
/*──────────────────────────────────────────────────────────────────────────────────────*/ commas: procedure; parse arg _; n= _'.9'; #= 123456789; b= verify(n, #, "M")
e= verify(n, #'0', , verify(n, #"0.", 'M') ) - 4 /* [↑] add commas.*/ do j=e to b by -3; _= insert(',', _, j); end /*j*/; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/ num: procedure; parse arg x .,,q; if x== then return x
if isNum(x) then return x/1; x= space( translate(x, , ','), 0) if \isNum(x) then x= $sfx!(x); if isNum(x) then return x/1 if q==1 then return x if q== then call ser "argument isn't numeric or doesn't have a legal suffix:" x</lang>
- output when using the default inputs:
numbers= 2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre result= 3,456 3,456 3,456 3,456 3,456 numbers= 1,567 +1.567k 0.1567e-2m result= 1,567 1,567 1,567 numbers= 25.123kK 25.123m 2.5123e-00002G result= 25,123,000 25,123,000 25,123,000 numbers= 25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei result= 26,343,374.848 26,343,374.848 26,975,615.844352 28,964,846,960.237816578048 numbers= -.25123e-34Vikki 2e-77gooGols result= -33,394.194938104441474962344775423096782848 200,000,000,000,000,000,000,000 numbers= 9! 9!! 9!!! 9!!!! 9!!!!! 9!!!!!! 9!!!!!!! 9!!!!!!!! 9!!!!!!!!! result= 362,880 945 162 45 36 27 18 9 9