순환오류

2026년 7월 22일 09:30분

사사기 2장에서 이스라엘은 우상숭배→심판→부르짖음→구원의 패턴을 세대마다 반복합니다. 나는 이 순환 구조를 상태 전환 열거형으로 모델링했습니다.

package com.jesusbornd.judges;

public class Judges_02_Chapter_Lv1 {
    enum State { 평화, 우상숭배, 심판, 부르짖음, 구원 }

    static State next(State s) {
        State[] v = State.values();
        return v[(s.ordinal() + 1) % v.length];
    }

    public static void main(String[] args) {
        State s = State.평화;
        for (int cycle = 1; cycle <= 3; cycle++) {
            System.out.printf("=== %d세대 ===%n", cycle);
            for (int i = 0; i < 5; i++) {
                System.out.println("  " + s);
                s = next(s);
            }
        }
    }
}

from enum import Enum, auto

class State(Enum):
    평화 = auto(); 우상숭배 = auto(); 심판 = auto(); 부르짖음 = auto(); 구원 = auto()

def next_state(s):
    order = list(State)
    return order[(order.index(s) + 1) % len(order)]

if __name__ == "__main__":
    s = State.평화
    for cycle in range(1, 4):
        print(f"=== {cycle}세대 ===")
        for _ in range(5):
            print(f"  {s.name}")
            s = next_state(s)

Comments

Avatar
 2026년 7월 22일 12:00분

상태 머신으로 표현하면 순환 패턴의 탈출 조건을 명확하게 정의할 수 있네요.



Search

← 목록으로