go_iching icon indicating copy to clipboard operation
go_iching copied to clipboard

An I Ching oracle written in Go.

This is a simple experiment with Go: an I Ching library.

Install with go get:

go get -u github.com/abrookins/go_iching 

Import like so:

import "github.com/abrookins/go_iching"

Then run iching.GetReading():

question := "Is this a bubble?"
reading := iching.GetReading(question)

iching.GetReading() takes a question (a string) and returns an iching.Reading object. iching.GetReading() simulates the traditional three-coin method of building six lines that form a hexagram. Once it has the lines, it finds an iching.Hexagram object that matches the arrangement of the lines and, if the lines are "changing" (per the I Ching divination rules), it calculates the next hexagram.

These values are included in the iching.Reading object (Question, Lines, Hexagram and NextHexagram).

// Obviously, import "fmt" first ...
fmt.Println(reading.Question)
fmt.Println(reading.Lines) 

iching.Hexagram objects include the (boolean) lines, the unicode representation of the hexagram and external links to a couple of well-known translations of the hexagram.

fmt.Println(reading.Hexagram.Character)
fmt.Println(reading.Hexagram.Num)
fmt.Println(reading.Hexagram.Name)
// etc.

I'm working on a JSON API to wrap this library.