Tcl Library Source Code

Attachment Details
Login
Overview

Artifact ID: fd7d85baf1755c08ab3767987fc2d6f7fc1807a6800a374ec51d80af7935061e
Ticket: e6b26853885c35d26243793e917107fa6f47206d
Date: 2018-08-06 23:23:10
User: anonymous
Artifact Attached: b087f00ae427309afe2a9b3d7e653ad0cf78079eace85813095c4ac95bb804d8
Filename:proportional_weighted_shares_good_diagnostic_version_submit_TCLLIB_math_stats.txt
Description:
Content Appended
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
console show
proc quantity_into_ratios {quantity args} {
if { $quantity <= 0 } {
return -code error "The quantity must be larger than 0"
}

if { [ llength $args ] < 2 } {
return -code error "The number of args must be 2 or more"
}


      set sum 0
     foreach val $args {
    set sum [ expr { $sum + $val } ]
    puts " $quantity $args $sum $val "
  }
puts " quantity_into_ratios: sum of args equals $sum "
if { $sum <= 0 } {
return -code error "The sum of args must be more than zero"
}

if {[ llength $args ] == 0} {
return 0
}

set answer ""
   set sum2 0
foreach val $args {
lappend answer [ expr { $quantity * ((1.*$val)/(1.*$sum)) } ]
    set sum2 [ expr { $sum2 +  ($quantity * ((1.*$val)/(1.*$sum)))  } ]
}
   puts " sum of shares  $sum2 "
set answer
}
        puts "  quantity_into_ratios ( 84 1 2 4  )  answer 12.0 24.0 48.0    "
        puts " [ quantity_into_ratios 84 1 2 4  ]  " 
        puts "  quantity_into_ratios ( 14 1 2 4  )  answer   2.0 4.0 8.0    "
        puts " [ quantity_into_ratios 14 1 2 4  ]  " 
        puts "  quantity_into_ratios ( 10 2 3   )  answer    4.0 6.0     "
        puts " [ quantity_into_ratios 10 2 3   ]  " 
        puts "  quantity_into_ratios ( 11 2 3   )  answer   4.40 6.59     "
        puts " [ quantity_into_ratios 11 2 3   ]  "
        puts "  quantity_into_ratios ( 9 1 1 1  )  answer   3.0 3.0 3.0   "
        puts " [ quantity_into_ratios 9 1 1 1  ]  " 
        puts "  quantity_into_ratios ( 10 1 1 1 1 1 1 1 1 1 1  )  answer    1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0    "
        puts " [ quantity_into_ratios 10 1 1 1 1 1 1 1 1 1 1   ]  " 
        puts "  quantity_into_ratios ( 0.10 1 1 1 1 1 1 1 1 1 1  )  answer    0.01  0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01"
        puts " [ quantity_into_ratios 0.10 1 1 1 1 1 1 1 1 1 1   ]  " 
        puts "  quantity_into_ratios ( 0.10 .1 .1 .1 .1 .1 .1 .1 .1 .1 .1  )  answer    0.01  0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01"
        puts " [ quantity_into_ratios 0.10 .1 .1 .1 .1 .1 .1 .1 .1 .1 .1    ]  " 
        #puts "  quantity_into_ratios ( 10 1   )  answer   returns error    "
        #puts " [ quantity_into_ratios 10 1   ]  " 
        #puts " [ quantity_into_ratios 84 1 ] for (quantity_into_ratios 84 0) returns error "
        #puts " [ quantity_into_ratios 84 ] for (quantity_into_ratios 84 0) returns error "
        #puts " [ quantity_into_ratios -2 1 2 3 ] for (quantity_into_ratios -2 1 2 3) returns error "