Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Averages-Mode/Tcl/averages-mode.tcl
Normal file
18
Task/Averages-Mode/Tcl/averages-mode.tcl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Can find the modal value of any vector of values
|
||||
proc mode {n args} {
|
||||
foreach n [list $n {*}$args] {
|
||||
dict incr counter $n
|
||||
}
|
||||
set counts [lsort -stride 2 -index 1 -decreasing $counter]
|
||||
set best {}
|
||||
foreach {n count} $counts {
|
||||
if {[lindex $counts 1] == $count} {
|
||||
lappend best $n
|
||||
} else break
|
||||
}
|
||||
return $best
|
||||
}
|
||||
|
||||
# Testing
|
||||
puts [mode 1 3 6 6 6 6 7 7 12 12 17]; # --> 6
|
||||
puts [mode 1 1 2 4 4]; # --> 1 4
|
||||
Loading…
Add table
Add a link
Reference in a new issue