Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
package require Tcl 8.5
|
||||
# Some simple helper procedures
|
||||
proc flip {nlist n} {
|
||||
concat [lreverse [lrange $nlist 0 $n]] [lrange $nlist $n+1 end]
|
||||
}
|
||||
proc findmax {nlist limit} {
|
||||
lsearch -exact $nlist [tcl::mathfunc::max {*}[lrange $nlist 0 $limit]]
|
||||
}
|
||||
|
||||
# Simple-minded pancake sort algorithm
|
||||
proc pancakeSort {nlist {debug ""}} {
|
||||
for {set i [llength $nlist]} {[incr i -1] > 0} {} {
|
||||
set j [findmax $nlist $i]
|
||||
if {$i != $j} {
|
||||
if {$j} {
|
||||
set nlist [flip $nlist $j]
|
||||
if {$debug eq "debug"} {puts [incr flips]>>$nlist}
|
||||
}
|
||||
set nlist [flip $nlist $i]
|
||||
if {$debug eq "debug"} {puts [incr flips]>>$nlist}
|
||||
}
|
||||
}
|
||||
return $nlist
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
puts [pancakeSort {27916 5928 23535 14711 32184 14621 21093 14422 29844 11093} debug]
|
||||
Loading…
Add table
Add a link
Reference in a new issue