Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
61
Task/Number-names/Jq/number-names-1.jq
Normal file
61
Task/Number-names/Jq/number-names-1.jq
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# Adapted from the go version.
|
||||
# Tested with jq 1.4
|
||||
#
|
||||
# say/0 as defined here supports positive and negative integers within
|
||||
# the range of accuracy of jq, or up to the quintillions, whichever is
|
||||
# less. As of jq version 1.4, jq's integer accuracy is about 10^16.
|
||||
|
||||
def say:
|
||||
|
||||
# subfunction zillions recursively handles the thousands,
|
||||
# millions, billions, etc.
|
||||
# input: the number
|
||||
# i: which "illion" to use
|
||||
# sx: the string so far
|
||||
# output: the updated string
|
||||
def zillions(i; sx):
|
||||
["thousand", "million", "billion",
|
||||
"trillion", "quadrillion", "quintillion"] as $illions
|
||||
| if . == 0 then sx
|
||||
else (. / 1000 | floor)
|
||||
| (. % 1000) as $p
|
||||
| zillions(i + 1;
|
||||
if $p > 0 then
|
||||
(($p | say) + " " + $illions[i]) as $ix
|
||||
| if sx != "" then $ix + ", " + sx
|
||||
else $ix
|
||||
end
|
||||
else sx
|
||||
end)
|
||||
end
|
||||
;
|
||||
|
||||
[ "", "one", "two", "three", "four", "five", "six", "seven",
|
||||
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
|
||||
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] as $small
|
||||
| ["ones", "ten", "twenty", "thirty", "forty",
|
||||
"fifty", "sixty", "seventy", "eighty", "ninety"] as $tens
|
||||
|
||||
| if . == 0 then "zero"
|
||||
elif . < 0 then "minus " + (-(.) | say)
|
||||
elif . < 20 then $small[.]
|
||||
elif . < 100 then
|
||||
$tens[./10|floor] as $t
|
||||
| (. % 10)
|
||||
| if . > 0 then ($t + " " + $small[.]) else $t end
|
||||
elif . < 1000 then
|
||||
($small[./100|floor] + " hundred") as $h
|
||||
| (. % 100)
|
||||
| if . > 0 then $h + " and " + (say) else $h end
|
||||
else
|
||||
# Handle values larger than 1000 by considering
|
||||
# the rightmost three digits separately from the rest:
|
||||
((. % 1000)
|
||||
| if . == 0 then ""
|
||||
elif . < 100 then "and " + say
|
||||
else say
|
||||
end ) as $sx
|
||||
| zillions(0; $sx)
|
||||
end ;
|
||||
|
||||
say
|
||||
16
Task/Number-names/Jq/number-names-2.jq
Normal file
16
Task/Number-names/Jq/number-names-2.jq
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
0
|
||||
"zero"
|
||||
-0
|
||||
"zero"
|
||||
111
|
||||
"one hundred and eleven"
|
||||
1230000
|
||||
"one million, two hundred and thirty thousand"
|
||||
123456
|
||||
"one hundred and twenty three thousand, four hundred and fifty six"
|
||||
123456789
|
||||
"one hundred and twenty three million, four hundred and fifty six thousand, seven hundred and eighty nine"
|
||||
-123000000123
|
||||
"minus one hundred and twenty three billion, one hundred and twenty three"
|
||||
12345678912345678
|
||||
"twelve quadrillion, three hundred and forty five trillion, six hundred and seventy eight billion, nine hundred and twelve million, three hundred and forty five thousand, six hundred and seventy eight"
|
||||
Loading…
Add table
Add a link
Reference in a new issue