This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER in your comment with the same courtesy that I will give you. Its very hard to reply intelligibly without some background of the correspondent. Thanks,gold
gold Here is some eTCL starter code for General Tianji' Horse Race Strategy from China in calculator shell. Additional console programs below are used to check or improve subroutines in calculator shell.
Both the King and General Tianji have sets of 3 horses. Each set has low grade horse, middle grade horse and best grade horse. General Sun Bin advised that the General Tianji run the General's low grade horse against the king's best grade horse, the General's middle grade horse against the king's low grade horse, and the General's best grade horse against the king's middle grade horse. The result was that all the General Tianji 's horses won that day circa 500 BCE. Each round of the horse race won 200 silver dollars. General Tianji and Sun Bin's share of the winnings was a bag of silver, worth expr(3*$200) or 600 silver dollars. Not sure an elegant proof can be drummed up, but we have the many random horses in eTCL. This racehorse problem can be loaded into the eTCL calculator shell and each horse of three can be simulated with a random race score. The eTCL calculator from the Random Walk Equation offers some analogies.
# using pseudocode # possible problem instances, initialize algorithm_result = 1. check algorithm f(solution) =? initial product B. combined work norm equals 1/(1/norm1 +1/norm2 +1/norm3) B. alternate combined work norm equals 1/(1/norm1 +1/norm2 +1/norm3) modern formula for harmonic mean equals n/(1/norm1 +1/norm2 +1/norm3 ... 1/nth term) for n terms check_sum = a+b+c+d+e set answers and printout with resulting values pseudocode: need test cases > small,medium, giant pseudocode: need testcases within range of expected operation. pseudocode: are there any cases too small or large to be solved?
In planning any software, it is advisable to gather a number of testcases to check the results of the program. The math for the testcases can be checked by pasting statements in the TCL console. Aside from the TCL calculator display, when one presses the report button on the calculator, one will have console show access to the capacity functions (subroutines).
# real vaporware here # incomplete, still gathering references & testcases for # General Tianji' Chinese Horse Race # pretty print from autoindent and ased editor # General Tianji' Chinese Horse Race Strategy Calculator # written on Windows XP on eTCL # working under TCL version 8.5.6 and 1.0.1 # gold on TCL WIKI, 25feb2017 package require Tk package require math::numtheory namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory } set tcl_precision 17 frame .frame -relief flat -bg aquamarine4 pack .frame -side top -fill y -anchor center set names {{} { low grade horse handicap (a) :} } lappend names { low grade horse score (a) :} lappend names { middle grade horse handicap (b) : } lappend names { middle grade horse score (b) : } lappend names { high grade horse handicap (c) :} lappend names { high grade horse score (c) : } lappend names { optional: number of horses, usually 3 } lappend names { answers: highest score (max fx) :} foreach i {1 2 3 4 5 6 7 8} { label .frame.label$i -text [lindex $names $i] -anchor e entry .frame.entry$i -width 35 -textvariable side$i grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1 } proc about {} { set msg "Calculator for General Tianji's Chinese Horse Race Strategy from TCL WIKI, written on eTCL " tk_messageBox -title "About" -message $msg } proc random_horses_3 { xx1 } { global side1 side2 side3 global side4 side5 side6 side7 side8 set term1 0 set term2 0 set term3 0 set current 0 set tothorses $xx1 set chance1 [expr {1./$side2 }] set tothorses [expr {int($side7) }] for {set i 0;} {$i<$tothorses} {incr i} { if { [ expr { rand() } ] <= $side2 } {set term1 1 } if { [ expr { rand() } ] <= $side4 } {set term2 1 } if { [ expr { rand() } ] <= $side6 } {set term3 1 } set current [ expr { ($current*1.) +.01*$side1*$term1+.01*$side3*$term2+.01*$side5*$term3+.00000000001 } ] } set side7 $tothorses set side8 [expr {($current*1.)/$tothorses }] if { [ expr { abs($side8) } ] <= .0001 } {set side8 0 } return $side8 } proc calculate { } { global answer2 global side1 side2 side3 side4 side5 global side6 side7 side8 global a_score b_score c_score average_score global testcase_number incr testcase_number set side1 [* $side1 1. ] set side2 [* $side2 1. ] set side3 [* $side3 1. ] set side4 [* $side4 1. ] set side5 [* $side5 1. ] set side6 [* $side6 1. ] set side7 [* $side7 1. ] set side8 [* $side8 1. ] # initialize placeholder answer set maximum_score_rating 1. set score_rating 0.5 set score_rating $side7 set a_score [+ [* $score_rating $side1 ] [* $score_rating $side2 ] ] set b_score [+ [* $score_rating $side3 ] [* $score_rating $side4 ] ] set c_score [+ [* $score_rating $side5 ] [* $score_rating $side6 ] ] set average_score [/ [+ $a_score $b_score $c_score ] 3. ] set maximum_score_rating [max $a_score $b_score $c_score ] #set answer2 $maximum_score_rating set answer2 [ random_horses_3 3 ] set side8 $answer2 } proc fillup {aa bb cc dd ee ff gg hh} { .frame.entry1 insert 0 "$aa" .frame.entry2 insert 0 "$bb" .frame.entry3 insert 0 "$cc" .frame.entry4 insert 0 "$dd" .frame.entry5 insert 0 "$ee" .frame.entry6 insert 0 "$ff" .frame.entry7 insert 0 "$gg" .frame.entry8 insert 0 "$hh" } proc clearx {} { foreach i {1 2 3 4 5 6 7 8 } { .frame.entry$i delete 0 end } } proc reportx {} { global side1 side2 side3 side4 side5 global side6 side7 side8 global a_score b_score c_score average_score global testcase_number console show; puts "%|table $testcase_number|printed in| tcl wiki format|% " puts "&| quantity| value| comment, if any|& " puts "&| $testcase_number:|testcase_number | |& " puts "&| $side1 :|low grade horse handicap (a) | |&" puts "&| $side2 :|low grade horse score (a)| |& " puts "&| $side3 :|middle grade horse handicap (b) | |& " puts "&| $side4 :|middle grade horse score (b)| |&" puts "&| $side5 :|high grade horse handicap (c) | |&" puts "&| $side6 :|high grade horse score (c) | |&" puts "&| $side7 :|optional: number of horses, usually 3. | |&" puts "&| $a_score :|score (a) | |&" puts "&| $b_score :|score (b) | |&" puts "&| $c_score :|score (c) | |&" puts "&| $average_score :|average score per item (a+b+c)/3 | |&" puts "&| $side8 :|answer: highest score (max fx) | |&" } frame .buttons -bg aquamarine4 ::ttk::button .calculator -text "Solve" -command { calculate } ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 5. .3 6. .3 7. .3 3. .10} ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 5. .3 6. .3 7. .3 3. .20 } ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 5. .3 6. .3 7. .3 3. .15 } ::ttk::button .clearallx -text clear -command {clearx } ::ttk::button .about -text about -command {about} ::ttk::button .cons -text report -command { reportx } ::ttk::button .exit -text exit -command {exit} pack .calculator -in .buttons -side top -padx 10 -pady 5 pack .clearallx .cons .about .exit .test4 .test3 .test2 -side bottom -in .buttons grid .frame .buttons -sticky ns -pady {0 10} . configure -background aquamarine4 -highlightcolor brown -relief raised -border 30 wm title . "General Tianji' Chinese Horse Race Strategy Calculator"
For the push buttons, the recommended procedure is push testcase and fill frame, change first three entries etc, push solve, and then push report. Report allows copy and paste from console.
For testcases in a computer session, the eTCL calculator increments a new testcase number internally, eg. TC(1), TC(2) , TC(3) , TC(N). The testcase number is internal to the calculator and will not be printed until the report button is pushed for the current result numbers. The current result numbers will be cleared on the next solve button. The command { calculate; reportx } or { calculate ; reportx; clearx } can be added or changed to report automatically. Another wrinkle would be to print out the current text, delimiters, and numbers in a TCL wiki style table as
puts " %| testcase $testcase_number | value| units |comment |%" puts " &| volume| $volume| cubic meters |based on length $side1 and width $side2 |&"
# pretty print from autoindent and ased editor # harmonic_mean for math::stats? package # working under TCL version 8.5.6 and eTCL 1.0.1 # console program written on Windows XP on eTCL # gold on TCL WIKI, 2Mar2017 package require Tk console show package require math::numtheory namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory } set tcl_precision 17 # adapted from tcl-wiki Stats 2011-05-22, arithmetic mean [RLE] # # ::math::harmonic_mean -- # # Return the harmonic mean of two or more values # # Arguments: # val first value # args other values # # Results: # mean harmonic_mean value proc ::math::harmonic_mean {val args} { set sum [ expr { 1./$val } ] set N [ expr { [ llength $args ] + 1 } ] foreach val $args { set sum [ expr { $sum+1./$val } ] } set harmonic_mean [ expr { $N/$sum } ] set harmonic_mean } puts " ::math::harmonic_mean ( 1 2 3 4 5 6 7 8 9 10 ) answer 3.4141715214740551 " puts " [ ::math::harmonic_mean 1 2 3 4 5 6 7 8 9 10 ] 3.4141715214740551 "
# pretty print from autoindent and ased editor # initial console program, Chinese horse race problem # comma delimited spreadsheet for number of horse races # written on Windows XP on eTCL # working under TCL version 8.5.6 and eTCL 1.0.1 # gold on TCL WIKI, 10feb2017 package require Tk package require math::numtheory namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory } set tcl_precision 17 console show set i 2000 set horse_race_days 1 puts "horse race number , trial heat, winner, wins of particular horse, cum. probability, loser,loser, horse_a , horse_b , horse_c , last place " while {$i>0} { if { $horse_race_days > 180 } { break } set horse_a [ expr { rand() } ] set horse_b [ expr { rand() } ] set horse_c [ expr { rand() } ] set trial [ expr { rand() } ] if { $trial > 0 && $trial < .2 } { set winner_name "horse_a" ; set loser_name "horse_b,horse_c" } if { $trial > .2 && $trial < .5 } { set winner_name "horse_b" ; set loser_name "horse_a,horse_c" } if { $trial > .5 && $trial < 1. } { set winner_name "horse_c" ; set loser_name "horse_a,horse_b" } set winner [max $horse_a $horse_b $horse_c] set last [min $horse_a $horse_b $horse_c] lappend winner_list $winner_name lappend loser_list $loser_name #set number_wins [ lsearch -all $winner_list $winner_name ] set ee [ llength $winner_list ] set kk [ llength [ lsearch -all $winner_list $winner_name ] ] set prob [ expr { ($kk*1.) / $ee } ] if {$winner_name == "horse_c" } { puts "$horse_race_days ,$trial ,$winner_name,$kk,$prob,$loser_name,$trial, $winner, $horse_a , $horse_b , $horse_c , $last "} incr horse_race_days incr i -1 } #end of deck
# cvs output
# pretty print from autoindent and ased editor # subroutine for tianji horse race and combined unequal probability # working under TCL version 8.5.6 and eTCL 1.0.1 # console program written on Windows XP on eTCL # written on Windows XP on eTCL # working under TCL version 8.5.6 and eTCL 1.0.1 # gold on TCL WIKI, 2mar2017 package require Tk package require math::numtheory namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory } set tcl_precision 17 console show proc tianji_horse_race { xxx1 } { set i 2000 set horse_race 1 set trial 1. set trialx 1. set tianji_low 1. set tianji_middle 1. set tianji_high 1. set king_low 1. set king_middle 1. set king_high 1. set program_result {} set winner_list1 {} set winner_list2 {} while {$i>0} { if { $horse_race > 10 } { break } set trial [ expr { rand() } ] set counter 1 if { $trial > 0.0 && $trial < 0.2 } { set tianji_low $trial } set trialx [ expr { rand() } ] if { $trial > .5 && $trial < 1.} { set king_high $trialx } # { $trial > 0.0 && $trial < 0.2 } = low_grade # { $trial > 0.2 && $trial < 0.5 } = medium_grade # { $trial > 0.5 && $trial < 1.0 } = high_grade if { [max $tianji_low $king_high ] == $tianji_low } { lappend winner_list2 " horse_race$horse_race heat$counter " tianji_low } if { [max $tianji_low $king_high ] == $king_high } { lappend winner_list2 " horse_race$horse_race heat$counter " king_high } incr counter set trial [ expr { rand() } ] if { $trial > 0.0 && $trial < 0.2 } { set tianji_middle $trial } set trialx [ expr { rand() } ] if { $trial > .5 && $trial < 1.} { set king_low $trialx } if { [max $tianji_middle $king_low ] == $tianji_middle } { lappend winner_list2 " horse_race$horse_race heat$counter " tianji_middle } if { [max $tianji_middle $king_low ] == $king_low } { lappend winner_list2 " horse_race$horse_race heat$counter " king_low } incr counter set trial [ expr { rand() } ] if { $trial > 0.5 && $trial < 1.0 } { set tianji_high $trial } set trialx [ expr { rand() } ] if { $trial > .3 && $trial < 5.} { set king_middle $trialx } if { [max $tianji_high $king_middle ] == $tianji_high } { lappend winner_list2 " horse_race$horse_race heat$counter " tianji_high } if { [max $tianji_high $king_middle ] == $king_middle } { lappend winner_list2 " horse_race$horse_race heat$counter " king_middle } incr horse_race incr i -1 } return $winner_list2 } set program_result [ tianji_horse_race 3 ] puts " list of winners = $program_result " #end of deck
#output follows
list of winners = { horse_race1 heat1 } tianji_low { horse_race1 heat1 } king_high { horse_race1 heat2 } tianji_middle { horse_race1 heat3 } tianji_high { horse_race1 heat3 } king_middle { horse_race2 heat1 } tianji_low { horse_race2 heat2 } tianji_middle { horse_race2 heat3 } tianji_high { horse_race2 heat3 } king_middle { horse_race3 heat1 } tianji_low { horse_race3 heat2 } tianji_middle { horse_race3 heat3 } tianji_high { horse_race3 heat3 } king_middle { horse_race4 heat1 } tianji_low { horse_race4 heat2 } tianji_middle { horse_race4 heat3 } tianji_high { horse_race4 heat3 } king_middle { horse_race5 heat1 } tianji_low { horse_race5 heat2 } tianji_middle { horse_race5 heat3 } king_middle { horse_race6 heat1 } tianji_low { horse_race6 heat2 } tianji_middle { horse_race6 heat3 } tianji_high { horse_race7 heat1 } king_high { horse_race7 heat2 } tianji_middle { horse_race7 heat3 } tianji_high { horse_race8 heat1 } king_high { horse_race8 heat2 } tianji_middle { horse_race8 heat3 } tianji_high { horse_race9 heat1 } king_high { horse_race9 heat2 } tianji_middle { horse_race9 heat3 } tianji_high { horse_race10 heat1 } king_high { horse_race10 heat2 } tianji_middle { horse_race10 heat3 } tianji_high
gold This page is copyrighted under the TCL/TK license terms, this license .
Please place any comments here, Thanks.
Category Numerical Analysis | Category Toys | Category Calculator | Category Mathematics | Category Example | Toys and Games | Category Games | Category Application | Category GUI |