Created
January 2, 2025 09:39
-
-
Save FradSer/58b071f97804708c3d9d5424dbc6fe4a to your computer and use it in GitHub Desktop.
Generates a Nuclear Hexagram (互卦 / Hu Gua) from the provided original hexagram.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates a Nuclear Hexagram (互卦 / Hu Gua) from the provided original hexagram. | |
* | |
* The Nuclear Hexagram is a combination of two trigrams, | |
* the Upper Trigram (上卦 / Shang Gua) and the Lower Trigram (下卦 / Xia Gua): | |
* - The Upper Trigram is formed by extracting the third, fourth, | |
* and fifth lines from the original hexagram. | |
* - Conversely, the Lower Trigram is formed by extracting the second, third, | |
* and fourth lines from the original hexagram. | |
* | |
* This combination reflects the internal interactions of the situation being | |
* inquired about, representing the development process of the event, | |
* including potential risks and gains. | |
* | |
* The Nuclear Hexagram embodies both subjective and objective factors: | |
* - The lower trigram (inner hexagram) represents subjective influences. | |
* - The upper trigram (outer hexagram) represents objective factors. | |
* | |
* Understanding the Nuclear Hexagram can provide insights into | |
* the complex relationships within the event, indicating that | |
* every event has its causes, some of which may be obscure. | |
* Observing these interactions is crucial for predicting | |
* the potential changes and outcomes of the situation. | |
* | |
* The original hexagram is derived from the original hexagram's lines as follows: | |
* - originalHexagram[0] - Shang Yao (上爻 / the Uppermost Line) | |
* - originalHexagram[1] - Wu Yao (五爻 / the Fifth Line) | |
* - originalHexagram[2] - Si Yao (四爻 / the Forth Line) | |
* - originalHexagram[3] - San Yao (三爻 / the third Line) | |
* - originalHexagram[4] - Er Yao (二爻 / the second Line) | |
* - originalHexagram[5] - Chu Yao (初爻 / the Initial Line) | |
* | |
* @param originalHexagram - An array of 6 numbers representing the original hexagram lines | |
* @returns A new array of 6 numbers representing the nuclear hexagram | |
* @throws {Error} If the input array does not contain exactly 6 trigrams | |
* | |
* @example | |
* const originalHexagram = [0, 1, 0, 1, 0, 0]; | |
* const nuclearHexagram = createNuclearHexagram(originalHexagram); | |
* // Returns: [1, 0, 1, 0, 1, 0] | |
*/ | |
export function createNuclearHexagram(originalHexagram: number[]): number[] { | |
// Validate the input to ensure it has exactly 6 lines | |
if (originalHexagram.length !== 6) { | |
throw new Error("Hexagram must have exactly 6 lines."); | |
} | |
// Initialize arrays for upper and lower trigrams | |
const upperInnerTrigram: number[] = [ | |
originalHexagram[1], // 5th line | |
originalHexagram[2], // 4th line | |
originalHexagram[3], // 3rd line | |
]; | |
const lowerInnerTrigram: number[] = [ | |
originalHexagram[2], // 4th line | |
originalHexagram[3], // 3rd line | |
originalHexagram[4], // 2nd line | |
]; | |
// Combine upper and lower trigrams to form the nuclear hexagram | |
const nuclearHexagram = [...upperInnerTrigram, ...lowerInnerTrigram]; | |
return nuclearHexagram; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment