Appendix: Hexagram Divination Code
Pseudo code that simulates the manual yarrow stalk divination process
# Abstract base class for divination methods
class DivinationMethod:
def generate_line(self):
raise NotImplementedError("Subclasses must implement generate_line()")
def cast_reading(self):
raise NotImplementedError("Subclasses must implement cast_reading()")
# Example implementation with key methods abstracted
class YarrowStalkDivination(DivinationMethod):
def __init__(self, total_stalks=49):
self.total_stalks = total_stalks
self.valid_outcomes = {
"OLD_YIN": 6,
"YOUNG_YANG": 7,
"YOUNG_YIN": 8,
"OLD_YANG": 9
}
def divide_stalks(self):
"""
Abstract method for dividing stalks
Returns: tuple of (pile1, pile2)
"""
pass
def count_remainder(self, pile):
"""
Abstract method for counting remainders
Returns: integer remainder
"""
pass
def calculate_line_value(self, divisions):
"""
Abstract method for calculating line value
Returns: integer (6, 7, 8, or 9)
"""
pass
def generate_line(self):
"""
Public interface for generating a single line
Returns the numerical value of the line (6-9)
"""
divisions = []
stalks = self.total_stalks
# Perform the three divisions
for _ in range(3):
pile1, pile2 = self.divide_stalks()
remainder = self.count_remainder(pile1 + pile2)
divisions.append(remainder)
stalks -= remainder
return self.calculate_line_value(divisions)
def cast_reading(self):
"""
Generates a complete hexagram reading
Returns: list of 6 integers representing the lines
"""
return [self.generate_line() for _ in range(6)]
# Example usage and extension point
class CustomYarrowMethod(YarrowStalkDivination):
def divide_stalks(self):
# Implement your proprietary division method here
pass
def count_remainder(self, pile):
# Implement your proprietary counting method here
pass
def calculate_line_value(self, divisions):
# Implement your proprietary calculation method here
pass
# Example interface for generating readings
def perform_divination():
method = CustomYarrowMethod()
hexagram = method.cast_reading()
return hexagramPreviousAppendix: The Evolution of the I Ching: A Chronological OverviewNextAppendix: Terence McKenna Timewave Zero + I-Ching
Last updated