Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Josephus-problem/Tcl/josephus-problem-1.tcl
Normal file
14
Task/Josephus-problem/Tcl/josephus-problem-1.tcl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
proc josephus {number step {survivors 1}} {
|
||||
for {set i 0} {$i<$number} {incr i} {lappend l $i}
|
||||
for {set i 1} {[llength $l]} {incr i} {
|
||||
# If the element is to be killed, append to the kill sequence
|
||||
if {$i%$step == 0} {
|
||||
lappend killseq [lindex $l 0]
|
||||
set l [lrange $l 1 end]
|
||||
} else {
|
||||
# Roll the list
|
||||
set l [concat [lrange $l 1 end] [list [lindex $l 0]]]
|
||||
}
|
||||
}
|
||||
return [lrange $killseq end-[expr {$survivors-1}] end]
|
||||
}
|
||||
2
Task/Josephus-problem/Tcl/josephus-problem-2.tcl
Normal file
2
Task/Josephus-problem/Tcl/josephus-problem-2.tcl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
puts "remaining: [josephus 41 3]"
|
||||
puts "remaining 4: [join [josephus 41 3 4] ,]"
|
||||
Loading…
Add table
Add a link
Reference in a new issue