def parse_hieroglyph_number(hieroglyph_str):
"""
Parse a hieroglyph string representing a base-14 number.
Hieroglyph mappings:
𓍢 = 1, 𓍣 = 2, 𓍤 = 3, 𓍥 = 4, 𓎇 = 12
Missing values filled using sequential unicode codepoints
. = decimal point
Args:
hieroglyph_str (str): String containing hieroglyphs and optional decimal point
Returns:
float: The decimal equivalent of the hieroglyph number
Raises:
ValueError: If string contains invalid characters
"""
# Base mapping of known hieroglyphs
base_hieroglyph_map = {
'𓍢': 1, # U+1337A2
'𓍣': 2, # U+1337A3
'𓍤': 3, # U+1337A4
'𓍥': 4, # U+1337A5
'𓎇': 12 # U+13387
}
# Generate complete mapping by filling missing values with sequential unicode
hieroglyph_map = {}
# Add known mappings
for char, value in base_hieroglyph_map.items():
hieroglyph_map[char] = value
# Fill in missing values (0, 5-11, 13) using sequential unicode from base characters
# Start from 𓍢 (U+1337A2) and generate sequential characters
base_codepoint = ord('𓍢') # U+1337A2
# Generate missing characters for values 0, 5-11, 13
missing_values = [0, 5, 6, 7, 8, 9, 10, 11, 13]
used_codepoints = {ord(char) for char in base_hieroglyph_map.keys()}
current_codepoint = base_codepoint
for value in missing_values:
# Find next unused codepoint
while current_codepoint in used_codepoints:
current_codepoint += 1
char = chr(current_codepoint)
hieroglyph_map[char] = value
used_codepoints.add(current_codepoint)
current_codepoint += 1
# Check for decimal point
if '.' in hieroglyph_str:
if hieroglyph_str.count('.') > 1:
raise ValueError("Multiple decimal points found")
integer_part, fractional_part = hieroglyph_str.split('.')
else:
integer_part = hieroglyph_str
fractional_part = ""
# Parse integer part
integer_value = 0
for i, char in enumerate(reversed(integer_part)):
if char not in hieroglyph_map:
raise ValueError(f"Invalid hieroglyph: {char}")
digit_value = hieroglyph_map[char]
integer_value += digit_value * (14 ** i)
# Parse fractional part
fractional_value = 0.0
for i, char in enumerate(fractional_part):
if char not in hieroglyph_map:
raise ValueError(f"Invalid hieroglyph: {char}")
digit_value = hieroglyph_map[char]
fractional_value += digit_value * (14 ** -(i + 1))
return integer_value + fractional_value
def decimal_to_hieroglyph(decimal_num, precision=6):
"""
Convert a decimal number to hieroglyph representation in base-14.
Args:
decimal_num (float): Decimal number to convert
precision (int): Number of decimal places for fractional part
Returns:
str: Hieroglyph representation
"""
# Generate reverse mapping
base_hieroglyph_map = {
'𓍢': 1, # U+1337A2
'𓍣': 2, # U+1337A3
'𓍤': 3, # U+1337A4
'𓍥': 4, # U+1337A5
'𓎇': 12 # U+13387
}
# Create complete value-to-hieroglyph mapping
value_to_hieroglyph = {}
# Add known mappings
for char, value in base_hieroglyph_map.items():
value_to_hieroglyph[value] = char
# Fill in missing values using sequential unicode
base_codepoint = ord('𓍢')
missing_values = [0, 5, 6, 7, 8, 9, 10, 11, 13]
used_codepoints = {ord(char) for char in base_hieroglyph_map.keys()}
current_codepoint = base_codepoint
for value in missing_values:
while current_codepoint in used_codepoints:
current_codepoint += 1
char = chr(current_codepoint)
value_to_hieroglyph[value] = char
used_codepoints.add(current_codepoint)
current_codepoint += 1
# Handle negative numbers
if decimal_num < 0:
return "-" + decimal_to_hieroglyph(-decimal_num, precision)
# Separate integer and fractional parts
integer_part = int(decimal_num)
fractional_part = decimal_num - integer_part
# Convert integer part
if integer_part == 0:
integer_hieroglyphs = value_to_hieroglyph[0]
else:
integer_hieroglyphs = ""
temp = integer_part
while temp > 0:
remainder = temp % 14
temp = temp // 14
integer_hieroglyphs = value_to_hieroglyph[remainder] + integer_hieroglyphs
# Convert fractional part
fractional_hieroglyphs = ""
if fractional_part > 0:
for _ in range(precision):
fractional_part *= 14
digit = int(fractional_part)
fractional_part -= digit
fractional_hieroglyphs += value_to_hieroglyph[digit]
if fractional_part == 0:
break
# Combine parts
result = integer_hieroglyphs
if fractional_hieroglyphs:
result += "." + fractional_hieroglyphs
return result
def float_equals(a, b, epsilon=1e-9):
"""Compare two floats with epsilon tolerance."""
return abs(a - b) < epsilon
# Example usage and tests
if __name__ == "__main__":
# Test parsing with expected values
test_cases = [
("𓍢", 1.0), # 1
("𓍣", 2.0), # 2
("𓍢𓍢", 15.0), # 1*14 + 1 = 15
("𓍢𓍣", 16.0), # 1*14 + 2 = 16
("𓎇", 12.0), # 12
("𓍢.𓍢", 1 + 1/14), # 1.1 in base 14 = 1 + 1/14 ≈ 1.071428571
("𓍣.𓍤", 2 + 3/14), # 2.3 in base 14 = 2 + 3/14 ≈ 2.214285714
("𓍢𓍢.𓍢𓍣", 15 + 1/14 + 2/196), # 15 + 1/14 + 2/196 ≈ 15.081632653
]
print("Testing hieroglyph parsing:")
all_passed = True
for hieroglyph, expected in test_cases:
try:
result = parse_hieroglyph_number(hieroglyph)
if float_equals(result, expected):
print(f"✓ {hieroglyph} = {result} (expected {expected})")
else:
print(f"✗ {hieroglyph} = {result} (expected {expected}) - FAILED")
all_passed = False
except ValueError as e:
print(f"✗ {hieroglyph} -> Error: {e} - FAILED")
all_passed = False
print(f"\nParsing tests: {'ALL PASSED' if all_passed else 'SOME FAILED'}")
# Test decimal to hieroglyph conversion
print("\nTesting decimal to hieroglyph conversion:")
decimal_tests = [
(0.0, None), # Will show what 0 looks like
(1.0, None), # Will show what 1 looks like
(2.0, None), # Will show what 2 looks like
(15.0, None), # Will show what 15 looks like
(16.0, None), # Will show what 16 looks like
(12.0, None), # Will show what 12 looks like
]
conversion_passed = True
for num, expected_hieroglyph in decimal_tests:
try:
hieroglyph = decimal_to_hieroglyph(num)
# Test round-trip conversion
back_to_decimal = parse_hieroglyph_number(hieroglyph)
if float_equals(back_to_decimal, num):
print(f"✓ {num} -> {hieroglyph} -> {back_to_decimal}")
else:
print(f"✗ {num} -> {hieroglyph} -> {back_to_decimal} - ROUND-TRIP FAILED")
conversion_passed = False
except ValueError as e:
print(f"✗ {num} -> Error: {e} - FAILED")
conversion_passed = False
print(f"\nConversion tests: {'ALL PASSED' if conversion_passed else 'SOME FAILED'}")
# Show the complete hieroglyph mapping
print(f"\nGenerated hieroglyph mapping for base-14:")
hieroglyph_map = {}
base_hieroglyph_map = {
'𓍢': 1, '𓍣': 2, '𓍤': 3, '𓍥': 4, '𓎇': 12
}
for char, value in base_hieroglyph_map.items():
hieroglyph_map[char] = value
base_codepoint = ord('𓍢')
missing_values = [0, 5, 6, 7, 8, 9, 10, 11, 13]
used_codepoints = {ord(char) for char in base_hieroglyph_map.keys()}
current_codepoint = base_codepoint
for value in missing_values:
while current_codepoint in used_codepoints:
current_codepoint += 1
char = chr(current_codepoint)
hieroglyph_map[char] = value
used_codepoints.add(current_codepoint)
current_codepoint += 1
for value in range(14):
for char, char_value in hieroglyph_map.items():
if char_value == value:
print(f"{char} = {value}")
break