new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
21
Task/Best-shuffle/Tcl/best-shuffle-1.tcl
Normal file
21
Task/Best-shuffle/Tcl/best-shuffle-1.tcl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package require Tcl 8.5
|
||||
package require struct::list
|
||||
|
||||
# Simple metric function; assumes non-empty lists
|
||||
proc count {l1 l2} {
|
||||
foreach a $l1 b $l2 {incr total [string equal $a $b]}
|
||||
return $total
|
||||
}
|
||||
# Find the best shuffling of the string
|
||||
proc bestshuffle {str} {
|
||||
set origin [split $str ""]
|
||||
set best $origin
|
||||
set score [llength $origin]
|
||||
struct::list foreachperm p $origin {
|
||||
if {$score > [set score [tcl::mathfunc::min $score [count $origin $p]]]} {
|
||||
set best $p
|
||||
}
|
||||
}
|
||||
set best [join $best ""]
|
||||
return "$str,$best,($score)"
|
||||
}
|
||||
3
Task/Best-shuffle/Tcl/best-shuffle-2.tcl
Normal file
3
Task/Best-shuffle/Tcl/best-shuffle-2.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foreach sample {abracadabra seesaw elk grrrrrr up a} {
|
||||
puts [bestshuffle $sample]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue