這是自然數映射到基底-3字符串:將自然數轉換爲三位字符串的簡單算法是什麼?
0 => 0
1 => 1
2 => 2
3 => 00
4 => 01
5 => 02
6 => 10
7 => 11
8 => 12
9 => 20
10 => 21
11 => 22
12 => 000
13 => 001
14 => 002
15 => 010
16 => 011
17 => 012
18 => 020
19 => 021
20 => 022
21 => 100
22 => 101
23 => 102
24 => 110
25 => 111
26 => 112
27 => 120
28 => 121
29 => 122
30 => 200
31 => 201
32 => 202
33 => 210
34 => 211
35 => 212
36 => 220
37 => 221
38 => 222
39 => 0000
40 => 0001
...
什麼是執行這種映射,來回最簡單,最有效的功能?
應該不是0對應於空串? – Bergi
@Bergi nah,空字符串是NaN,或者是undefined。我想過使用它,但是桌子不對齊。讓我知道你是否有想法。 – MaiaVictor
String.toString(n,3)產生一個以3爲底的字符串 –