-
Notifications
You must be signed in to change notification settings - Fork 0
/
00017.q
34 lines (31 loc) · 826 Bytes
/
00017.q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 17. Number letter counts
/setup look-up arrays
ones:("";"one";"two";"three";"four";"five";"six";"seven";"eight";"nine")
teen:("ten";"eleven";"twelve";"thirteen";"fourteen";"fifteen";"sixteen";"seventeen";"eighteen";"nineteen")
tens:("";"";"twenty";"thirty";"forty";"fifty";"sixty";"seventy";"eighty";"ninety")
/works from 1..9999
text:{
T:x div 1000; / Thousands
h:(x mod 1000) div 100; / hundreds
t:(x mod 100) div 10; / tens
u:x mod 10; / units
txt:"";
if[T;
txt,:ones[T],"thousand",$[max (h;t;u);"and";""]
];
if[h;
txt,:ones[h],"hundred",$[max (t;u);"and";""]
];
if[t;
$[t=1;
:txt,:teen[u]; / return as no units
txt,:tens[t]]
];
if[u;
txt,:ones[u]
];
txt
}
/convert 1..1000 to text and count
count raze text 1 + til 1000
/21124