Skip to content

Instantly share code, notes, and snippets.

@viraltux
Last active August 31, 2016 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viraltux/f655566258c748576eb9 to your computer and use it in GitHub Desktop.
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
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