Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,132 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Integers_In_English is
|
||||
|
||||
type Spellable is range -999_999_999_999_999_999..999_999_999_999_999_999;
|
||||
function Spell (N : Spellable) return String is
|
||||
function Twenty (N : Spellable) return String is
|
||||
begin
|
||||
case N mod 20 is
|
||||
when 0 => return "zero";
|
||||
when 1 => return "one";
|
||||
when 2 => return "two";
|
||||
when 3 => return "three";
|
||||
when 4 => return "four";
|
||||
when 5 => return "five";
|
||||
when 6 => return "six";
|
||||
when 7 => return "seven";
|
||||
when 8 => return "eight";
|
||||
when 9 => return "nine";
|
||||
when 10 => return "ten";
|
||||
when 11 => return "eleven";
|
||||
when 12 => return "twelve";
|
||||
when 13 => return "thirteen";
|
||||
when 14 => return "fourteen";
|
||||
when 15 => return "fifteen";
|
||||
when 16 => return "sixteen";
|
||||
when 17 => return "seventeen";
|
||||
when 18 => return "eighteen";
|
||||
when others => return "nineteen";
|
||||
end case;
|
||||
end Twenty;
|
||||
|
||||
function Decade (N : Spellable) return String is
|
||||
begin
|
||||
case N mod 10 is
|
||||
when 2 => return "twenty";
|
||||
when 3 => return "thirty";
|
||||
when 4 => return "forty";
|
||||
when 5 => return "fifty";
|
||||
when 6 => return "sixty";
|
||||
when 7 => return "seventy";
|
||||
when 8 => return "eighty";
|
||||
when others => return "ninety";
|
||||
end case;
|
||||
end Decade;
|
||||
|
||||
function Hundred (N : Spellable) return String is
|
||||
begin
|
||||
if N < 20 then
|
||||
return Twenty (N);
|
||||
elsif 0 = N mod 10 then
|
||||
return Decade (N / 10 mod 10);
|
||||
else
|
||||
return Decade (N / 10) & '-' & Twenty (N mod 10);
|
||||
end if;
|
||||
end Hundred;
|
||||
|
||||
function Thousand (N : Spellable) return String is
|
||||
begin
|
||||
if N < 100 then
|
||||
return Hundred (N);
|
||||
elsif 0 = N mod 100 then
|
||||
return Twenty (N / 100) & " hundred";
|
||||
else
|
||||
return Twenty (N / 100) & " hundred and " & Hundred (N mod 100);
|
||||
end if;
|
||||
end Thousand;
|
||||
|
||||
function Triplet
|
||||
( N : Spellable;
|
||||
Order : Spellable;
|
||||
Name : String;
|
||||
Rest : not null access function (N : Spellable) return String
|
||||
) return String is
|
||||
High : Spellable := N / Order;
|
||||
Low : Spellable := N mod Order;
|
||||
begin
|
||||
if High = 0 then
|
||||
return Rest (Low);
|
||||
elsif Low = 0 then
|
||||
return Thousand (High) & ' ' & Name;
|
||||
else
|
||||
return Thousand (High) & ' ' & Name & ", " & Rest (Low);
|
||||
end if;
|
||||
end Triplet;
|
||||
|
||||
function Million (N : Spellable) return String is
|
||||
begin
|
||||
return Triplet (N, 10**3, "thousand", Thousand'Access);
|
||||
end Million;
|
||||
|
||||
function Milliard (N : Spellable) return String is
|
||||
begin
|
||||
return Triplet (N, 10**6, "million", Million'Access);
|
||||
end Milliard;
|
||||
|
||||
function Billion (N : Spellable) return String is
|
||||
begin
|
||||
return Triplet (N, 10**9, "milliard", Milliard'Access);
|
||||
end Billion;
|
||||
|
||||
function Billiard (N : Spellable) return String is
|
||||
begin
|
||||
return Triplet (N, 10**12, "billion", Billion'Access);
|
||||
end Billiard;
|
||||
|
||||
begin
|
||||
if N < 0 then
|
||||
return "negative " & Spell(-N);
|
||||
else
|
||||
return Triplet (N, 10**15, "billiard", Billiard'Access);
|
||||
end if;
|
||||
end Spell;
|
||||
|
||||
procedure Spell_And_Print(N: Spellable) is
|
||||
Number: constant String := Spellable'Image(N);
|
||||
Spaces: constant String(1 .. 20) := (others => ' '); -- 20 * ' '
|
||||
begin
|
||||
Ada.Text_IO.Put_Line(Spaces(Spaces'First .. Spaces'Last-Number'Length)
|
||||
& Number & ' ' & Spell(N));
|
||||
end Spell_And_Print;
|
||||
|
||||
Samples: constant array (Natural range <>) of Spellable
|
||||
:= (99, 300, 310, 1_501, 12_609, 512_609, 43_112_609, 77_000_112_609,
|
||||
2_000_000_000_100, 999_999_999_999_999_999,
|
||||
0, -99, -1501, -77_000_112_609, -123_456_789_987_654_321);
|
||||
|
||||
begin
|
||||
for I in Samples'Range loop
|
||||
Spell_And_Print(Samples(I));
|
||||
end loop;
|
||||
end Integers_In_English;
|
||||
|
|
@ -57,4 +57,4 @@ loop @[
|
|||
45039,123456,91740274651983,
|
||||
neg 83125311200, neg 12, neg 7
|
||||
] 'num ->
|
||||
print [pad to :string num 15, join.with: "\n"++ (repeat " " 16) split.lines wordwrap.at: 40 wordify num
|
||||
print [pad to :string num 15, join.with: "\n"++ (repeat " " 16) split.lines wordwrap.at: 40 wordify num]
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
function abs(atom i)
|
||||
if i < 0 then
|
||||
return -i
|
||||
else
|
||||
return i
|
||||
end if
|
||||
end function
|
||||
|
||||
constant small = {"one", "two", "three", "four", "five", "six", "seven", "eight",
|
||||
"nine", "ten","eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
|
||||
"seventeen", "eighteen", "nineteen"}
|
||||
|
||||
constant tens = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty",
|
||||
"ninety"}
|
||||
|
||||
constant big = {"thousand", "million", "billion"}
|
||||
|
||||
function int2text(atom number)
|
||||
atom num
|
||||
integer unit, tmpLng1
|
||||
sequence outP
|
||||
outP = ""
|
||||
num = 0
|
||||
unit = 1
|
||||
tmpLng1 = 0
|
||||
|
||||
if number = 0 then
|
||||
return "zero"
|
||||
end if
|
||||
|
||||
num = abs(number)
|
||||
while 1 do
|
||||
tmpLng1 = remainder(num,100)
|
||||
if tmpLng1 > 0 and tmpLng1 < 20 then
|
||||
outP = small[tmpLng1] & ' ' & outP
|
||||
elsif tmpLng1 >= 20 then
|
||||
if remainder(tmpLng1,10) = 0 then
|
||||
outP = tens[floor(tmpLng1/10)-1] & ' ' & outP
|
||||
else
|
||||
outP = tens[floor(tmpLng1/10)-1] & '-' & small[remainder(tmpLng1, 10)] & ' ' & outP
|
||||
end if
|
||||
end if
|
||||
|
||||
tmpLng1 = floor(remainder(num, 1000) / 100)
|
||||
if tmpLng1 then
|
||||
outP = small[tmpLng1] & " hundred " & outP
|
||||
end if
|
||||
|
||||
num = floor(num/1000)
|
||||
if num < 1 then
|
||||
exit
|
||||
end if
|
||||
|
||||
tmpLng1 = remainder(num,1000)
|
||||
if tmpLng1 then
|
||||
outP = big[unit] & ' ' & outP
|
||||
end if
|
||||
|
||||
unit = unit + 1
|
||||
end while
|
||||
|
||||
if number < 0 then
|
||||
outP = "negative " & outP
|
||||
end if
|
||||
|
||||
return outP[1..$-1]
|
||||
end function
|
||||
|
||||
puts(1,int2text(900000001) & "\n")
|
||||
puts(1,int2text(1234567890) & "\n")
|
||||
puts(1,int2text(-987654321) & "\n")
|
||||
puts(1,int2text(0) & "\n")
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
function Get-NumberName
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Spells out a number in English.
|
||||
.DESCRIPTION
|
||||
Spells out a number in English in the range of 0 to 999,999,999.
|
||||
.NOTES
|
||||
The code for this function was copied (almost word for word) from the C#
|
||||
example on this page to show how similar Powershell is to C#.
|
||||
.PARAMETER Number
|
||||
One or more integers in the range of 0 to 999,999,999.
|
||||
.EXAMPLE
|
||||
Get-NumberName -Number 666
|
||||
.EXAMPLE
|
||||
Get-NumberName 1, 234, 31337, 987654321
|
||||
.EXAMPLE
|
||||
1, 234, 31337, 987654321 | Get-NumberName
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
[OutputType([string])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[ValidateRange(0,999999999)]
|
||||
[int[]]
|
||||
$Number
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
[string[]]$incrementsOfOne = "zero", "one", "two", "three", "four",
|
||||
"five", "six", "seven", "eight", "nine",
|
||||
"ten", "eleven", "twelve", "thirteen", "fourteen",
|
||||
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
|
||||
|
||||
[string[]]$incrementsOfTen = "", "", "twenty", "thirty", "fourty",
|
||||
"fifty", "sixty", "seventy", "eighty", "ninety"
|
||||
|
||||
[string]$millionName = "million"
|
||||
[string]$thousandName = "thousand"
|
||||
[string]$hundredName = "hundred"
|
||||
[string]$andName = "and"
|
||||
|
||||
function GetName([int]$i)
|
||||
{
|
||||
[string]$output = ""
|
||||
|
||||
if ($i -ge 1000000)
|
||||
{
|
||||
$remainder = $null
|
||||
$output += (ParseTriplet ([Math]::DivRem($i,1000000,[ref]$remainder))) + " " + $millionName
|
||||
$i = $remainder
|
||||
|
||||
if ($i -eq 0) { return $output }
|
||||
}
|
||||
|
||||
if ($i -ge 1000)
|
||||
{
|
||||
if ($output.Length -gt 0)
|
||||
{
|
||||
$output += ", "
|
||||
}
|
||||
|
||||
$remainder = $null
|
||||
$output += (ParseTriplet ([Math]::DivRem($i,1000,[ref]$remainder))) + " " + $thousandName
|
||||
$i = $remainder
|
||||
|
||||
if ($i -eq 0) { return $output }
|
||||
}
|
||||
|
||||
if ($output.Length -gt 0)
|
||||
{
|
||||
$output += ", "
|
||||
}
|
||||
|
||||
$output += (ParseTriplet $i)
|
||||
|
||||
return $output
|
||||
}
|
||||
|
||||
function ParseTriplet([int]$i)
|
||||
{
|
||||
[string]$output = ""
|
||||
|
||||
if ($i -ge 100)
|
||||
{
|
||||
$remainder = $null
|
||||
$output += $incrementsOfOne[([Math]::DivRem($i,100,[ref]$remainder))] + " " + $hundredName
|
||||
$i = $remainder
|
||||
|
||||
if ($i -eq 0) { return $output }
|
||||
}
|
||||
|
||||
if ($output.Length -gt 0)
|
||||
{
|
||||
$output += " " + $andName + " "
|
||||
}
|
||||
|
||||
if ($i -ge 20)
|
||||
{
|
||||
$remainder = $null
|
||||
$output += $incrementsOfTen[([Math]::DivRem($i,10,[ref]$remainder))]
|
||||
$i = $remainder
|
||||
|
||||
if ($i -eq 0) { return $output }
|
||||
}
|
||||
|
||||
if ($output.Length -gt 0)
|
||||
{
|
||||
$output += " "
|
||||
}
|
||||
|
||||
$output += $incrementsOfOne[$i]
|
||||
|
||||
return $output
|
||||
}
|
||||
}
|
||||
Process
|
||||
{
|
||||
foreach ($n in $Number)
|
||||
{
|
||||
[PSCustomObject]@{
|
||||
Number = $n
|
||||
Name = GetName $n
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1, 234, 31337, 987654321 | Get-NumberName
|
||||
Loading…
Add table
Add a link
Reference in a new issue