The Iching is the ancient fortune telling book of China. The Iching literature mentions various methods for casting fortune patterns of Iching. The various methods include hot ironing of turtle shells (-t.), manipulations of yarrow sticks, flipping coins, throwing shaman bones, and dice. One analogy from North America is a shaman throwing or shuffling stick dice. ---- I made three stick dice for Iching by cutting a dowel of square cross section into three sticks. For the three stick dice, the flat sides are marked or burned with 2 or 3 holes alternately. Two sticks are marked with {3 2 3 2} dots on the sides. One stick is marked with {3 3 3 2} dots on the sides. In casting such three dice, the possible sums are 6,7,8, or 9. Further, the stick dice are cast six times to obtain whole lines or broken lines in a pattern or set of six lines. A set of six Iching lines is called a gua in the orient or a hexagram in some translations of the Chinese. ---- In the Iching interpretations, casts of 6 and 8 are broken or yin (female) lines, while casts of 7 and 9 are whole or yang (male) lines. The casts are recorded by pencil with the first line at bottom and marking up the column. It is possible to record the numbers from the casts with tally sticks or Chinese counting rods, which are somewhat reminiscent of the Iching patterns themselves. After marking the original pattern or hexagram, sometimes a second follow-up hexagram is developed by swapping throws of 6 for a 7 and throws of 9 for a 6. These swaps effectively trade a broken line(6) for a whole line(7) and a whole line(9) for a broken line(6). The throws for the changing lines (6&9) may not always be come out in the first hexagram or its component lines, so the followup hexagram may not exist {under consistent rules}. If the first hexagram is interpreted on a line by line basis, any changing lines(6&9) or second hexagram offers some modification or discount on the interpretation of the first hexagram. ---- In developing a computer program or application, it is helpful to develop analogs for the individual tasks of the application. An Iching application would have to compose, beg, or borrow TCL procedures for random casts, tallies of scores, accounting files, display hexagram lines on a screen, swapping changing lines, hexagram pattern recognition and ranking interpretations. In fact, some TCL one liner procedures and text swapping routines might be useful as utilities in a starter application program, since unruly text strings are expected in the Iching. Casting the sticks or bones for each Iching line is analog for random lpick subroutine below. Adding the top sides of three sticks and throwing six times is analog for the "for 6 times" statement in the bonereadxx procedure below. In the West, Leibniz etc recognised that the whole and broken lines in the hexagram patterns could be counted as ones and zeros, respectively in a binary number system. For example, a cast or TCL list of { 6,7,8,9,6,7 } could be expressed as a binary number, 010101. The binary numbers are the analogs for the binaryexchange subroutine below. For computer procedures, the patterns are effectively a horizontal bar code of 6 lines. ---- In the process of designing the basic subroutine tasks, we could throw in some switches, logic chains, or daisy chains that break the outset rules given above. For example, TCL is so good at swapping lines (6&9) for the second hexagram, that it would be easy to put a switch that generates or swaps all hexagram lines (6,7,8,&9) for their opposites. Also from some scripts of the Chinese Chou dynasty, different Iching fortune methods of yarrow sticks or coins would generate different probabilities of obtaining each hexagram line. Might be interesting to have a back door in the program to check (or adapt} the different probabilities of stick or coin throws. Several authors have pointed out that a few of the hexagrams look similar to Chinese characters or even Mayan calendar notation. Without wading too deep into alternate realities, the Iching hexagrams could be used as numerals, script alphabet, game tokens, symbol recognition code, or maybe a programing language (like Greek letters for APL operators). Such rule breaking helps keep the finished program more flexible. ---- #!/usr/bin/env wish #start of deck #Iching_Fortunes # or Itching For Tunes [%>} # 6Feb2007, [gold] # working on XP starter code package require Tk global bookvalue bookvalue2 set colorground bisque set wow "bone number" proc xlistlistbox {} { .labellabel delete 0 end foreach filefile [glob .* *] { if [file isdirectory $filefile] { set filefile "$filefile/" } .labellabel insert end $filefile; } } proc xskipskipdirectory {dir} { cd $dir .realcommand configure -text [pwd] xlistlistbox } proc clickclicklistbox {} { set index [lindex [.labellabel curselection] 0] set filename [.labellabel get $index] if [file isdirectory $filename] { xskipskipdirectory $filename } } wm title . "File Starter" frame .labelframe pack .labelframe -expand no -fill x label .labellabel1 -text "Directory:" label .realcommand -text "" \ -relief groove pack .labellabel1 -in .labelframe \ -side left -expand no -fill x pack .realcommand -in .labelframe \ -side left -expand yes -fill x -anchor w frame .listlistbox pack .listlistbox -expand yes -fill both listbox .labellabel \ -width 25 -height 3 \ -xscrollcommand ".xxxxaxis set" \ -yscrollcommand ".yyyyaxis set" \ -bg $colorground scrollbar .yyyyaxis \ -command ".labellabel yview" \ -orient v scrollbar .xxxxaxis \ -command ".labellabel xview" \ -orient h pack .xxxxaxis -in .listlistbox -side bottom -fill x -expand no pack .yyyyaxis -in .listlistbox -side right -fill y -expand no pack .labellabel -in .listlistbox -side top -fill both -expand yes frame .buttonbuttonx pack .buttonbuttonx -fill x button .caster -text Cast_Bones -command {bonereadxx;castfortune;} button .done -text Exit -command exit pack .caster .done -in .buttonbuttonx \ -side top -fill x bind .labellabel clickclicklistbox pack [ label .ww -text "Iching holding tank " -bg $colorground] pack [ text .wxxccc -width 80 -height 3 -bg beige ] focus .wxxccc ;# allow keyboard input .wxxccc insert end "xxx starter xxx "; scrollbar .scr -orient vertical -command ".can yview" canvas .can -yscrollcommand ".scr set" -width 240 -bg $colorground pack .can -fill both -expand 1 -side left pack .scr -fill y -expand 0 -side left set width 50 set height 50 set w ".can" set x 100 set y 100 set dx 50 set dy 30 set colors {white black } set color 0 #suchenwirth_subroutine;} proc lpick L {lindex $L [expr {int(rand()*[llength $L])} ];} # utilities proc plainsub {text item replacewith} { set text [string map [list $item $replacewith] $text] } proc %+ {a } {return [string toupper $a]; #%+ tree >TREE } proc %- {a } {return [string tolower $a]; #%+ Tree >tree } proc %++ {a b} {return $a$b;#%+* tree root >treeroot } proc %-- {a b} {regsub $b $a "" a; return $a;#%-- 5 7>5 } proc %% {a b} {regsub -all $b $a "";#%% tree root >tree } proc %1 {a b} {regsub $b $a "" a; return $a;#%1 tree root>tree } proc %2 {a b} {regsub $b $a "" a;regsub $b $a "" a; return $a;#%2 tree root>tree } proc %3 {a b} {regsub $b $a "" a;regsub $b $a "" a;regsub $b $a "" a; return $a;#%3 tree root>tree} proc %2x {a} {return $a$a;#%2x tree>treetree} proc %3x {a} {return $a$a$a;#%3x tree>treetreetree} proc %4x {a} {return "$a,$a,$a";#%5x tree>tree,tree,tree } proc %5x {a} {return "$a $a $a";#%5x tree>tree tree tree } proc repeat {n body} {while {$n} {incr n -1; uplevel $body}} proc random n {expr {round($n*rand())}} proc whitelist {a} {return [lreplace $a 0 -1];#take string,return list without blanks} set k [split {abcdefghijklmnopqrstuvwxyz} {}] proc average L {expr ([join $L +])/[llength $L].} proc srevert s { set l [string length $s] set res "" while {$l} {append res [string index $s [incr l -1]]} set res };# RS, proc lreverse L { set res {} set i [llength $L] #while {[incr i -1]>=0} {lappend res [lindex $L $i]} while {$i} {lappend res [lindex $L [incr i -1]]} ;# rmax set res } ;# RS, tuned 10% faster by [rmax] proc sumoflist L {expr [join [split $L ""] +]+0} ;# RS proc convertbase2to10 {jip} { set l [split $jip ""] set t 0; set e 0; foreach n $l { set exp [ expr int(pow(2,$e))]; incr t [ expr $n * $exp ] ; incr e; } return $t} proc kvsearch {kvlist item} { set pos [lsearch $kvlist $item] if {$pos != -1} { lindex $kvlist [expr {$pos+1-2*($pos%2)}] } } ;# RS # end utilities #start iching data set bookvalue [ list 1 63 43 62 14 61 34 60 9 59 5 58 26 57 11 56 10 55 58 54 38 53 54 52 61 51 60 50 41 49 19 48 13 47 49 46 30 45 55 44 37 43 63 42 22 41 36 40 25 39 17 38 21 37 51 36 42 35 3 34 27 33 24 32 44 31 28 30 50 29 32 28 57 27 48 26 18 25 46 24 6 23 47 22 64 21 40 20 59 19 29 18 4 17 7 16 33 15 31 14 56 13 62 12 53 11 39 10 52 9 15 31 14 56 13 62 12 53 11 39 10 52 9 15 8 12 7 45 6 35 5 16 4 20 3 23 1 2 0 8 2 ] set bookvalue2 [ list 9999 1 63 43 62 14 61 34 60 9 59 5 58 26 57 11 56 10 55 58 54 38 53 54 52 61 51 60 50 41 49 19 48 13 47 49 46 30 45 55 44 37 43 63 42 22 41 36 40 25 39 17 38 21 37 51 36 42 35 3 34 27 33 24 32 44 31 28 30 50 29 32 28 57 27 48 26 18 25 46 24 6 23 47 22 64 21 40 20 59 19 29 18 4 17 7 16 33 15 31 14 56 13 62 12 53 11 39 10 52 9 15 31 14 56 13 62 12 53 11 39 10 52 9 15 8 12 7 45 6 35 5 16 4 20 3 23 1 2 0 8 2 ] if 0 { iching hexagrams and trigrams } if 0 { Little API style database } if 0 { + hexagram_1 : pinyin Qian wade Ch'ien english {The Creative } + hexagram_2 : pinyin Kun wade K'un english {The Receptive} + hexagram_3 : pinyin Zhun wade Chun english { Difficulty at the Beginning } + hexagram_4 : pinyin Meng wade Mêng english {Youthful Folly } + hexagram_5 : pinyin Xu wade Hsü english {Waiting } + hexagram_6 : pinyin Song wade Sung english {Conflict } + hexagram_7 : pinyin Shi wade Shih english {The Army } + hexagram_8 : pinyin Bi wade Pi english {Holding Together} + hexagram_9 : pinyin Xiaoxu wade Hsiao Ch'u english {The Taming Power of the Small} + hexagram_10 : pinyin Lü wade Lü english {Treading} + hexagram_11 : pinyin Tai wade T'ai english {Peace } + hexagram_12 : pinyin Pi wade P'i english {Standstill } + hexagram_13 : pinyin Tongren wade {T'ung Jên} english {Fellowship with Men } + hexagram_14 : pinyin Dayou wade { Ta Yu } english {Possession in Great Measure } + hexagram_15 : pinyin Qian wade Ch'ien english {Modesty } + hexagram_16 : pinyin Yu wade Yü english {Enthusiasm } + hexagram_17 : pinyin Sui wade Sui english {Following } + hexagram_18 : pinyin Gu wade Ku english {Work on What Has Been Spoiled } + hexagram_19 : pinyin Lin wade Lin english {Approach } + hexagram_20 : pinyin Guan wade Kuan english {Contemplation } + hexagram_21 : pinyin Shike wade {Shih Ho } english {Biting Through } + hexagram_22 : pinyin Bi wade Pi english {Grace } + hexagram_23 : pinyin Bo wade Po english {Splitting Apart } + hexagram_24 : pinyin Fu wade Fu english {Return } + hexagram_25 : pinyin Wuwang wade { Wu Wang }english {Innocence } + hexagram_26 : pinyin Daxu wade { Ta Ch'u } english {The Taming Power of the Great } + hexagram_27 : pinyin Yi wade I english {The Corners of the Mouth } + hexagram_28 : pinyin Daguo wade { Ta Kuo } english {Preponderance of the Great } + hexagram_29 : pinyin Kan wade K'an english {The Abysmal } + hexagram_30 : pinyin Li wade Li english {The Clinging } + hexagram_31 : pinyin Xian wade Hsien english {Influence } + hexagram_32 : pinyin Heng wade Hêng english {Duration} + hexagram_33 : pinyin Dun wade Tun english {Retreat } + hexagram_34 : pinyin Dazhuang wade { Ta Chuang } english {The Power of the Great } + hexagram_35 : pinyin Jin wade Chin english {Progress} + hexagram_36 : pinyin Mingyi wade { Ming I } english {Darkening of the Light } + hexagram_37 : pinyin Jiaren wade Chia Jên english { The Family} + hexagram_38 : pinyin Kui wade K'uei english {Opposition } + hexagram_39 : pinyin Jian wade Chien english {Obstruction} + hexagram_40 : pinyin Xie wade Hsieh english {Deliverance} + hexagram_41 : pinyin Sun wade Sun english {Decrease } + hexagram_42 : pinyin Yi wade I english {Increase } + hexagram_43 : pinyin Guai wade Kuai english {Break-through} + hexagram_44 : pinyin Gou wade Kou english {Coming to Meet} + hexagram_45 : pinyin Cui wade Ts'ui english {Gathering Together } + hexagram_46 : pinyin Sheng wade Shêng english {Pushing Upward } + hexagram_47 : pinyin Kun wade K'un english {Oppression } + hexagram_48 : pinyin Jing wade Ching english {The Well } + hexagram_49 : pinyin Ge wade Ko english {Revolution} + hexagram_50 : pinyin Ding wade Ting english {The Caldron } + hexagram_51 : pinyin Zhen wade Chên english {The Arousing } + hexagram_52 : pinyin Gen wade Kên english {Keeping Still } + hexagram_53 : pinyin Jian wade Chien english {Development } + hexagram_54 : pinyin Guimei wade {Kuei Mei} english {The Marrying Maiden } + hexagram_55 : pinyin Feng wade Fêng english {Abundance } + hexagram_56 : pinyin Lü wade Lü english {The Wanderer } + hexagram_57 : pinyin Xun wade Sun english {The Gentle } + hexagram_58 : pinyin Dui wade Tui english {The Joyous } + hexagram_59 : pinyin Huan wade Huan english { Dispersion } + hexagram_60 : pinyin Jie wade Chieh english {Limitation } + hexagram_61 : pinyin Zhongfu wade {Chung Fu} english {InnerTruth } + hexagram_62 : pinyin Xiaoguo wade { Hsiao Kuo} english {Preponderance of the Small } + hexagram_63 : pinyin Jiji wade { Chi Chi } english {After Completion} + hexagram_64 : pinyin Weiji wade { Wei Chi } english {Before Completion } } #end iching data proc binaryexchange {gualisting} { # converts gualisting as a list # to binary & decimal numbers. global dx dy colors color global guabinary guadecimal guatransform set guabinary [ whitelist $gualisting ]; set guabinary [ join [ split $guabinary " "]]; set guabinary [ plainsub $guabinary 6 0 ]; set guabinary [ plainsub $guabinary 7 1 ]; set guabinary [ plainsub $guabinary 8 0 ]; set guabinary [ plainsub $guabinary 9 1 ]; set guabinary [ plainsub $guabinary " " "" ]; return $guabinary; } proc second_hexagram_compute {gualisting } { # subroutine under test global bookvalue second_hexagram #set gualisting [ lreverse $gualisting]; set second_hexagram [ list ]; set second_hexagram [ join $gualisting ] ; set second_hexagram [ plainsub $second_hexagram 6 7 ]; set second_hexagram [ plainsub $second_hexagram 9 6 ]; set guabinary [ binaryexchange $second_hexagram ]; set decimalout [ convertbase2to10 $guabinary ]; set bookgua [ kvsearch $bookvalue $decimalout ]; return $bookgua; } proc bonereadxx {} { global dx dy colors color gualisting global bookvalue bookvalue2 second_hexagram set dj 1; set gualisting [list ]; for {set j 0} {$j<6} {incr j $dj} { set bone1 [lpick {3 3 3 2}] set bone2 [lpick {3 3 2 2}] set bone3 [lpick {3 3 2 2}] set bonereading [expr $bone1 + $bone2 + $bone3 ] set wow [expr $bone1 + $bone2 + $bone3 ] lappend gualisting $wow; } #set guabinary [ list 1 0 1 1 1 si tiene problema ] set gualisting [ lreverse $gualisting]; # reading hexagram lines top down, # opposed to reverse(down top) # give different binary values # set guabinary [ binaryexchange $gualisting ]; set decimalout [ convertbase2to10 $guabinary ]; set bookgua [ kvsearch $bookvalue2 $decimalout ]; set second_hexa [ second_hexagram_compute $gualisting ]; .wxxccc delete 1.0 end; set outoutfoulspirit " last bone is $wow .gua listing is $gualisting && binary $guabinary && decimal $decimalout &&Iching_gua_# $bookgua && test 2nd hex. $second_hexagram && 2nd h. test $second_hexa && $second_hexagram " .wxxccc insert end $outoutfoulspirit } proc castfortune {} { global dx dy colors color gualisting second_hexagram set colorx black; for {set i 0; set y 0} {$i<6} {incr i; incr y $dy} { set colorx brown; for {set j 0; set x 0} {$j<3} {incr j; incr x $dx} { set colorx brown; if { $j == 1} { if { [lindex $gualisting $i ] == 6} {set colorx white} if { [lindex $gualisting $i ] == 7} {set colorx brown} if { [lindex $gualisting $i ] == 8} {set colorx white} if { [lindex $gualisting $i ] == 9} {set colorx brown} } .can create rectangle $x $y [expr {$x+$dx}] [expr {$y+$dy}] \ -fill $colorx }} set dx 50 set dy 30 set colorx blue; for {set i 0; set y 0} {$i<6} {incr i; incr y $dy} { set colorx blue; for {set j 0; set x 0} {$j<3} {incr j; incr x $dx} { set colorx blue; if { $j == 1} { if { [lindex $second_hexagram $i ] == 6} {set colorx white} if { [lindex $second_hexagram $i ] == 7} {set colorx blue} if { [lindex $second_hexagram $i ] == 8} {set colorx white} if { [lindex $second_hexagram $i ] == 9} {set colorx blue} } .can create rectangle [expr $x + 180] $y [expr {[expr $x +180 ]+$dx}] [expr {$y+$dy}] \ -fill $colorx }} } xskipskipdirectory $env(HOME) #endofdeck #endofdeck ---- [gold] Change:Redundant procedure ? deleted. [LV] slightly reformatted code to some level of consistency, added a few braces around expr arguments, and removed a redundant proc definition. [gold] Change 13Mar2007:omitted **(exp) in expr for base2, TCL8.5&>. ---- References: * http://en.wikipedia.org/wiki/I_Ching * http://www.kheper.net/topics/I_Ching/hexagrams.htm * http://www.peaceloveandme.com/images/trigrams.gif * http://www.anton-heyboer.org/i_ching/choose.htm * Search on google.com for "site:www.sipp.org ching hexagrams" * http://www.beatrice.com/TAO.txt * http://members.aol.com/IChing1/index.html * http://www.sacred-texts.com/ich/index.htm * http://www.meritbadge.com/mb/notes/064.htm * http://home.hccnet.nl/vd.heijdt/sub-division.htm * Search on google.com for "Navaho game stick dice" * Search on google.com for "native america stick dice" * http://hearstmuseum.berkeley.edu/../gallery_3_5_5.html * http://www.biroco.com/yijing/stick.htm * http://mathcentral.uregina.ca/.../treptau1/game3.html * Search on google.com for "counting rods" * Search on google.com for "Limyran Lycia oracle Astrampsych Maltomini" * Search on Wikipedia for "Bagua ching trigram hexagram" * http://www.math.sfu.ca/histmath/China/Beginning/Rod.html * http://mathforum.org/library/drmath/view/52557.html * http://members.iimetro.com.au/~lofting/myweb/icmaths.html * http://www.research.att.com/~njas/sequences/A116586 * http://www.circadianacupuncture.com/CAT/iching.html * Dirk Gently's Holistic I-ching Calculator [http://www.thateden.co.uk/dirk/] * http://www.bodhitree.com/booklists/i-ching.html * http://hexadecimal.uoregon.edu/ching/ching.html * c# based program as http://hexadecimal.uoregon.edu/ching/src.html * [Base conversion] * Syntax or sin tax:[I love foreach] [use while to iterate over a list] * [additional list functions], [string reverse], * [split], [list] * [recursive list searching] ---- Appendix Tables if 0 { iching hexagrams and trigrams } if 0 { 1. Qian Ch'ien, The Creative 2. Kun K'un, The Receptive 3. Zhun Chun, Difficulty at the Beginning 4. Meng Mêng, Youthful Folly 5. Xu Hsü, Waiting 6. Song Sung, Conflict 7. Shi Shih, The Army 8. Bi Pi, Holding Together 9. Xiaoxu Hsiao Ch'u, The Taming Power of the Small 10. Lü Lü, Treading 11. Tai T'ai, Peace 12. Pi P'i, Standstill 13. Tongren T'ung Jên, Fellowship with Men 14. Dayou Ta Yu, Possession in Great Measure 15. Qian Ch'ien, Modesty 16. Yu Yü, Enthusiasm 17. Sui Sui, Following 18. Gu Ku, Work on What Has Been Spoiled 19. Lin Lin, Approach 20. Guan Kuan, Contemplation 21. Shike Shih Ho, Biting Through 22. Bi Pi, Grace 23. Bo Po, Splitting Apart 24. Fu Fu, Return 25. Wuwang Wu Wang, Innocence 26. Daxu Ta Ch'u, The Taming Power of the Great 27. Yi I, The Corners of the Mouth 28. Daguo Ta Kuo, Preponderance of the Great 29. Kan K'an, The Abysmal 30. Li Li, The Clinging 31. Xian Hsien, Influence 32. Heng Hêng, Duration 33. Dun Tun, Retreat 34. Dazhuang Ta Chuang, The Power of the Great 35. Jin Chin, Progress 36. Mingyi Ming I, Darkening of the Light 37. Jiaren Chia Jên, The Family 38. Kui K'uei, Opposition 39. Jian Chien, Obstruction 40. Xie Hsieh, Deliverance 41. Sun Sun, Decrease 42. Yi I, Increase 43. Guai Kuai, Break-through 44. Gou Kou, Coming to Meet 45. Cui Ts'ui, Gathering Together 46. Sheng Shêng, Pushing Upward 47. Kun K'un, Oppression 48. Jing Ching, The Well 49. Ge Ko, Revolution 50. Ding Ting, The Caldron 51. Zhen Chên, The Arousing 52. Gen Kên, Keeping Still 53. Jian Chien, Development 54. Guimei Kuei Mei, The Marrying Maiden 55. Feng Fêng, Abundance 56. Lü Lü, The Wanderer 57. Xun Sun, The Gentle 58. Dui Tui, The Joyous 59. Huan Huan, Dispersion 60. Jie Chieh, Limitation 61. Zhongfu Chung Fu, Inner Truth 62. Xiaoguo Hsiao Kuo, Preponderance of the Small 63. Jiji Chi Chi, After Completion 64. Weiji Wei Chi, Before Completion The names of the trigrams I Ching Trigram Name Translations Pinyin Wade-Giles (Wilhelm/Baynes) associations 1. Qian Ch'ien the creative, heaven, Father,northwest,head,lungs 2. Kun K'un the receptive, earth,Mother,southwest,abdomen,reproductive_organs 3. Zhen Chên the arousing, thunder,Eldest_Son,east,throat 4. Kan K'an the abysmal, water,Middle_Son,north,liver,kidneys,inner_ear 5. Gen Kên keeping still, mountain, Youngest_Son,northeast,hands,spine,bones 6. Xun Sun the gentle, wind, Eldest Daughter,southeast,hips,buttocks 7. Li Li the clinging, flame,Middle_Daughter,south,eyes,heart 8. Dui Tui the joyous, lake,Youngest_Daughter,west,mouth } ---- [Category Toys]