Last active
August 31, 2016 23:32
-
-
Save viraltux/f655566258c748576eb9 to your computer and use it in GitHub Desktop.
R function returning six Yin Yang elements coded from 6 to 9 following the traditional method to obtain I Ching hexagrams as explained by Richard Whilhem book. http://aleadeum.com/2013/07/12/the-i-ching-random-numbers-and-why-you-are-doing-it-wrong
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
IChing = function(N=6){ | |
set = NULL | |
for(i in 1:N){ | |
sign = 0 | |
hand = 0 | |
for(j in 1:3){ | |
left = sample(1:(48-hand),1) | |
right = 49-hand-left | |
pinky = 1 ; right = right - 1 | |
anular = ifelse(left%%4==0,4,left%%4); | |
middle = ifelse(right%%4==0,4,right%%4); | |
fingers = pinky + anular + middle | |
hand = hand + fingers | |
sign = sign + ifelse(fingers==9 || fingers==8,2,3); | |
} | |
set = c(set,sign) | |
} | |
return(set) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment