Task
Given an integer \$n\in[0,10^{12})\$ in any convenient format, return the number of strokes needed to write that character in simplified Chinese.
Background
Chinese numerals are expressed in base 10 with a system of digits and places, with an important distinction that digits are in groups of four, rather than three.
The individual characters used to write Chinese can be described at the lowest level as a collection of strokes, laid out in a certain order and manner. The number of strokes required to write a character is that character's stroke count.
The (simplified) characters used to write numbers in Chinese are:
num char strokes
0 零* 13
1 一 1
2 二** 2
3 三 3
4 四 5
5 五 4
6 六 4
7 七 2
8 八 2
9 九 2
10 十 2
100 百 6
1000 千 3
10^4 万 3
10^8 亿 3
* 0 can also be written 〇, but we won't use that here.
** 两 is largely interchangeable with 二, apart from never
appearing before 十. We won't consider it here for simplicity,
but 两 is very common in actual usage.
For example, 9 8765 4321 is 九亿八千七百六十五万四千三百二十一: nine hundred-million (九 亿), eight thousand seven hundred sixty-five ten-thousand (八千七百六十五 万), four thousand three hundred twenty-one (四千三百二十一). In all, 53 strokes are needed to write this out.
There are additionally some special rules involving the digits 0
and 1
. These can vary slightly between dialects, but we'll choose these:
When there are non-trailing
0
s in a 4-digit group, they are combined into a single零
. No place marker is used.
(This is because e.g. 一百二 is a common way to say 120. We won't consider that form.)- 1020 is 一千零二十.
- 6 0708 is 六万零七百零八.
- 3 0000 4005 is 三亿四千零五.
- 0 is 零.
If the number would begin with
一十
, the一
is omitted.- Powers of 10 are 一, 十, 一百, 一千, 一万, 十万, 一百万, etc.
- 111 is 一百一十一.
Test Cases
n strokes chinese
0 13 零
10 2 十
236 17 二百三十六
7041 26 七千零四十一
50010 23 五万零一十
100000 5 十万
860483 42 八十六万零四百八十三
4941507 52 四百九十四万一千五百零七
51001924 38 五千一百万一千九百二十四
105064519 70 一亿零五百零六万四千五百一十九
300004005 31 三亿四千零五
987654321 53 九亿八千七百六十五万四千三百二十一
1240601851 56 十二亿四千零六十万一千八百五十一
608726402463 79 六千零八十七亿二千六百四十万二千四百六十三
@user202729 provided a script in the sandbox to help with reading the Chinese numbers: Try it online!
一十
rule applies to just the start of the whole number, right, not each group? \$\endgroup\$