File size: 3,386 Bytes
5536535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class TifinaghNumberConverter:
    AND = " ⴷ "
    UNITS = ["ⴰⵎⵢⴰ", "ⵢⴰⵏ", "ⵙⵉⵏ", "ⴽⵕⴰⴹ", "ⴽⴽⵓⵥ", "ⵙⵎⵎⵓⵙ", "ⵚⴹⵉⵚ", "ⵙⴰ", "ⵜⴰⵎ", "ⵜⵥⴰ"]
    TENS = ["", "ⵎⵔⴰⵡ", "ⵙⵉⵎⵔⴰⵡ", "ⴽⵕⴰⵎⵔⴰⵡ", "ⴽⴽⵓⵎⵔⴰⵡ", "ⵙⵎⵎⵓⵎⵔⴰⵡ", "ⵚⴹⵉⵎⵔⴰⵡ", "ⵙⴰⵎⵔⴰⵡ", "ⵜⴰⵎⵔⴰⵡ", "ⵜⵥⴰⵎⵔⴰⵡ"]
    HUNDREDS = ["", "ⵜⵉⵎⵉⴹⵉ", "ⵙⵏⴰⵜ ⵜⵎⴰⴹ", "ⴽⵕⴰⴹⵜ ⵜⵎⴰⴹ", "ⴽⴽⵓⵥⵜ ⵜⵎⴰⴹ", "ⵙⵎⵎⵓⵙⵜ ⵜⵎⴰⴹ", "ⵚⴹⵉⵚⵜ ⵜⵎⴰⴹ", "ⵙⴰⵜ ⵜⵎⴰⴹ", "ⵜⴰⵎⵜ ⵜⵎⴰⴹ", "ⵜⵥⴰⵜ ⵜⵎⴰⴹ"]
    ORDERS = ["", "ⵉⴼⴹ", "ⴰⵎⵍⵢⵓⵏ", "ⴰⵎⵍⵢⴰⵕ", "ⴰⵜⵔⵉⵍⵢⵓⵏ", "ⴰⴽⵡⴰⴹⵕⵉⵍⵢⵓⵏ", "ⴰⴽⵡⵉⵏⵜⵔⵉⵍⵢⵓⵏ", "ⴰⵙⵉⴽⵙⵜⵉⵍⵢⵓⵏ", "ⴰⵙⵉⴱⵜⵉⵍⵢⵓⵏ", "ⴰⵡⴽⵜⵉⵍⵢⵓⵏ", "ⴰⵏⵓⵏⵉⵍⵢⵓⵏ"]
    ORDERS_PLURAL = ["", "ⵡⴰⴼⴹⴰⵏ", "ⵉⴷ ⴰⵎⵍⵢⵓⵏ", "ⵉⴷ ⴰⵎⵍⵢⴰⵕ", "ⵉⵜⵔⵉⵍⵢⵓⵏⵏ", "ⵉⴽⵡⴰⴹⵕⵉⵍⵢⵓⵏⵏ", "ⵉⴽⵡⵉⵏⵜⵔⵉⵍⵢⵓⵏⵏ", "ⵉⵙⵉⴽⵙⵜⵉⵍⵢⵓⵏⵏ", "ⵉⵙⵉⴱⵜⵉⵍⵢⵓⵏⵏ", "ⵉⵡⴽⵜⵉⵍⵢⵓⵏⵏ", "ⵉⵏⵓⵏⵉⵍⵢⵓⵏⵏ"]

    @classmethod
    def convert_number_to_999(cls, n):
        """Convert numbers from 0 to 999 to Tifinagh."""
        if n == 0:
            return ""
        if n < 10:
            return cls.UNITS[n]
        if n < 20:
            if n % 10 == 0:
                return cls.TENS[n // 10]
            return cls.UNITS[n % 10] + cls.AND + cls.TENS[n // 10]
        if n < 100:
            if n % 10 == 0:
                return cls.TENS[n // 10]
            return cls.TENS[n // 10] + cls.AND + cls.UNITS[n % 10]
        if n < 1000:
            if n % 100 == 0:
                return cls.HUNDREDS[n // 100]
            return cls.HUNDREDS[n // 100] + cls.AND + cls.convert_number_to_999(n % 100)
        return ""

    @classmethod
    def convert_large_number(cls, n):
        """Convert large numbers to Tifinagh."""
        if n < 1000:
            return cls.convert_number_to_999(n)
        
        for order in range(len(cls.ORDERS) - 1, 0, -1):
            order_value = 10 ** (order * 3)
            if n >= order_value:
                quotient = n // order_value
                remainder = n % order_value
                
                if quotient == 1:
                    if remainder:
                        return cls.ORDERS[order] + cls.AND + cls.convert_large_number(remainder)
                    return cls.ORDERS[order]
                else:
                    if remainder:
                        return cls.convert_number_to_999(quotient) + " " + \
                               cls.ORDERS_PLURAL[order] + cls.AND + cls.convert_large_number(remainder)
                    return cls.convert_number_to_999(quotient) + " " + cls.ORDERS_PLURAL[order]
        
        return ""

    @classmethod
    def convert(cls, number):
        """Main conversion method."""
        if number == 0:
            return "ⴰⵎⵢⴰ"
        if number < 0:
            return "- " + cls.convert_large_number(abs(number))
        return cls.convert_large_number(number)