Okay, so yesterday I got this wild idea to mess around with I Ching, you know, that ancient Chinese thing. I’ve always been curious, but never actually did it. I called it “i ching 1”. And today, I wanted to build on that, hence “i ching 2”.
So, first, I grabbed the code I wrote yesterday. It was pretty basic – just generating a single hexagram using the three-coin method. I wanted to make it a bit more… involved. I thought, “What if I could get the changing lines and the resulting hexagram, too?” That’s the whole point, right? To see how things might evolve.
Getting the Changing Lines
This was a bit trickier. I remembered that changing lines happen when you get three heads (yang, changing to yin) or three tails (yin, changing to yang). So, I modified my coin flip function to keep track of that.

- Each coin flip is still random (0 or 1, for tails or heads).
- I added a counter for each line.
- If I get three of the same result, I mark that line as changing.
Then, I needed a way to represent this. I decided to use a simple list. If a line is changing, I put a “1” in the list, if it’s not, I put a “0”. Simple enough.
Creating the Second Hexagram
This was the cool part. I took my original hexagram (a list of six numbers, 6 to 9) and applied the changing lines. The rules are pretty straightforward:
- If a line is yang (9) and changing, it becomes yin (6).
- If a line is yin (6) and changing, it becomes yang (9).
- Otherwise, the line stays the same.
I just looped through the original hexagram and the changing lines list, and created a new list – the second hexagram. It felt like actual magic, watching the lines transform!
Putting It All Together
Finally, I combined everything into one function. Now, I can just call this function, and it spits out:
- The original hexagram.
- A list showing which lines are changing.
- The resulting hexagram.
It’s still pretty rough, no fancy interpretations or anything, but it’s a solid foundation. It felt good to take something I started and build it into something more complete. I’m gonna work to use this new function to get the interpretations, that’s next!
