We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Alexandrian Ordinator

From Esolang
Jump to navigation Jump to search

An Alexandrian Ordinator is a machine which takes a string as input and returns its Alexandrian ordinance.

machine

import math

# -----------------------------
# S-FUNCTION
# -----------------------------
def S_orig(c):
    i = ord(c) - 65
    if i < 1:
        return (i, i+1)
    return (1, 9999)

# -----------------------------
# INTERVAL REFINEMENT
# -----------------------------
def refine(word, radix):
    lo, hi = 0.0, float(radix)
    for c in word:
        a, b = S_orig(c)
        w = hi - lo
        lo = lo + w * (a / 9999)
        hi = lo + w * ((b - a) / 9999)
    return lo, hi

# -----------------------------
# HEPTAVINTIMAL ENCODER
# -----------------------------
HEPT = "0ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def to_heptavintimal(n):
    n = abs(n) % 19683
    if n == 0:
        return "0"
    digits = []
    while n > 0:
        n, r = divmod(n, 27)
        digits.append(HEPT[r])
    return "".join(reversed(digits))

# -----------------------------
# OCTAL ADDRESS
# -----------------------------
def to_octal(n):
    return oct(abs(n) % 19683)[2:]

# -----------------------------
# HEPT → INT (for proper numeric sort)
# -----------------------------
def hept_to_int(h):
    value = 0
    for ch in h:
        value = value * 27 + HEPT.index(ch)
    return value

# -----------------------------
# ABSOLUTE RADICAL SWEEP + REGISTRY + SORT
# -----------------------------
def analyze(word):
    print("WORD:", word)
    print()

    last_hept = None
    seen_octal = set()
    registry = []   # (radix, hept, octal)

    # positive sweep: 19683 → 0
    for r in range(19683, -1, -1):
        lo, hi = refine(word, r)
        n = int(abs(lo))

        # octal doubling with cap
        octal = to_octal(n)
        attempts = 0
        while octal in seen_octal and attempts < 64:
            n *= 2
            octal = to_octal(n)
            attempts += 1
        seen_octal.add(octal)

        hept = to_heptavintimal(n)

        if hept != last_hept:
            registry.append((r, hept, octal))
            last_hept = hept

    # negative sweep: -1 → -8575
    for r in range(-1, -8575, -1):
        lo, hi = refine(word, r)
        n = int(abs(lo))

        octal = to_octal(n)
        attempts = 0
        while octal in seen_octal and attempts < 64:
            n *= 2
            octal = to_octal(n)
            attempts += 1
        seen_octal.add(octal)

        hept = to_heptavintimal(n)

        if hept != last_hept:
            registry.append((r, hept, octal))
            last_hept = hept

    # -----------------------------
    # BUILD HEX REGISTRY (full address)
    # -----------------------------
    hex_registry = []
    seq = 0

    for radix, hept, octal in registry:
        pad = "0" * 15
        radix_hex = format(radix & 0xFFFFFF, "06X")
        seq_hex = format(seq, "03X")
        full_addr = f"0x{pad}{radix_hex}{seq_hex}"
        hex_registry.append((hept, full_addr))
        seq += 1

    # -----------------------------
    # SORT BY TRUE HEPT NUMERIC VALUE
    # -----------------------------
    hex_registry.sort(key=lambda x: hept_to_int(x[0]))

    # -----------------------------
    # OUTPUT FORMAT:
    # index:[last9hex]HEPT
    # -----------------------------
    for idx, (hept, full_addr) in enumerate(hex_registry):
        last9 = full_addr[-9:]
        print(f"{idx}:[{last9}]{hept}")

# -----------------------------
# RUN IT
# -----------------------------
analyze("!")

example

WORD: J


0:[00270E041]0
1:[004CE3000]A
2:[004CE2001]B
3:[004CE1002]D
4:[004CE0003]H
5:[004CDF004]P
6:[004CDE005]AE
7:[004CDD006]BJ
8:[004CDC007]DT
9:[004CDB008]IM
10:[004CDA009]RZ
11:[004CD900A]AJY
12:[004CCD016]BMP
13:[004CA603D]BST
14:[004CD800B]BUW
15:[004CB802B]BWT
16:[004CBF024]CEA
17:[004CCC017]E0E
18:[004CAA039]EFH
19:[004CAE035]EJN
20:[004CA503E]ELM
21:[004CD700C]EPS
22:[004CB702C]ETM
23:[004CBE025]FJB
24:[004CCF014]GJD
25:[004CB0033]HBQ
26:[004CD1012]HPA
27:[004CD3010]HXG
28:[004CCB018]J0J
29:[004CA903A]JLP
30:[004CAD036]JUA
31:[004CA403F]JXZ
32:[004CB3030]KCS
33:[004CD600D]KFK
34:[004CB602D]KMZ
35:[004CBD026]LTD
36:[004CC401F]LTK
37:[004CC901A]MAM
38:[004CCE015]NTH
39:[004CA703C]NWJ
40:[004CB902A]NYJ
41:[004CC0023]OBN
42:[004CAB038]PCD
43:[004CAF034]PEG
44:[004CD0013]QEB
45:[004CB1032]QNV
46:[004CD2011]QUN
47:[004CD400F]QYQ
48:[004CB402F]SAW
49:[004CC501E]SWS
50:[004CCA019]T0T
51:[004CA803B]TYE
52:[004CBA029]TZE
53:[004CC1022]UAG
54:[004CAC037]UOB
55:[004CA3040]UVY
56:[004CB2031]VGK
57:[004CD500E]VLV
58:[004CB502E]W0Y
59:[004CC601D]WKW
60:[004CBB028]WZP
61:[004CC2021]X0Q
62:[004CC701C]YEY
63:[004CBC027]YMH
64:[004CC3020]YMV
65:[004CC801B]ZBZ

See also