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.

User:Miui/oiji.py

From Esolang
Jump to navigation Jump to search
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""오이지 (Oiji) 1.29295 — 참조 구현 / reference implementation."""

import sys

기르다 = "\U0001F952"   # 🥒  grow
깎다   = "\U0001F52A"   # 🔪  peel
절이다 = "\U0001FAD9"   # 🫙  pickle


def 절이자(원본: str) -> str:
    길이 = 0        # length of the cucumber in hand
    마지막 = 0      # length of the last cucumber put in the jar
    판정 = False    # verdict flag
    항아리 = []
    i = 0
    while i < len(원본):
        c = 원본[i]
        if c == 기르다:
            길이 += 1
        elif c == 깎다:
            길이 -= 1
        elif c == 절이다:
            항아리.append(chr(길이 % 0x110000))
            마지막 = 길이
        elif c == ">":                 # 집게: is this one longer?
            판정 = 길이 > 마지막
        elif c == "<":                 # 역집게: is this one shorter?
            판정 = 길이 < 마지막
        elif c == "?":                 # 판정: skip next command unless 판정
            if not 판정:
                i += 2
                continue
        elif c == "!":
            길이 = 0
        i += 1
    return "".join(항아리)


if __name__ == "__main__":
    src = open(sys.argv[1], encoding="utf-8").read() if len(sys.argv) > 1 else sys.stdin.read()
    sys.stdout.write(절이자(src))