Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Executable-library/Tcl/executable-library-1.tcl
Normal file
25
Task/Executable-library/Tcl/executable-library-1.tcl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
### In the file hailstone.tcl ###
|
||||
package provide hailstone 1.0
|
||||
|
||||
proc hailstone n {
|
||||
while 1 {
|
||||
lappend seq $n
|
||||
if {$n == 1} {return $seq}
|
||||
set n [expr {$n & 1 ? $n*3+1 : $n/2}]
|
||||
}
|
||||
}
|
||||
|
||||
# If directly executed, run demo code
|
||||
if {[info script] eq $::argv0} {
|
||||
set h27 [hailstone 27]
|
||||
puts "h27 len=[llength $h27]"
|
||||
puts "head4 = [lrange $h27 0 3]"
|
||||
puts "tail4 = [lrange $h27 end-3 end]"
|
||||
|
||||
set maxlen [set max 0]
|
||||
for {set i 1} {$i<100000} {incr i} {
|
||||
set l [llength [hailstone $i]]
|
||||
if {$l>$maxlen} {set maxlen $l;set max $i}
|
||||
}
|
||||
puts "max is $max, with length $maxlen"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue