Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 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"
|
||||
}
|
||||
1
Task/Executable-library/Tcl/executable-library-2.tcl
Normal file
1
Task/Executable-library/Tcl/executable-library-2.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
pkg_mkIndex .
|
||||
16
Task/Executable-library/Tcl/executable-library-3.tcl
Normal file
16
Task/Executable-library/Tcl/executable-library-3.tcl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/tclsh8.6
|
||||
package require Tcl 8.6 ;# For [lsort -stride] option
|
||||
lappend auto_path . ;# Or wherever it is located
|
||||
package require hailstone 1.0
|
||||
|
||||
# Construct a histogram of length frequencies
|
||||
set histogram {}
|
||||
for {set n 1} {$n < 100000} {incr n} {
|
||||
dict incr histogram [llength [hailstone $n]]
|
||||
}
|
||||
|
||||
# Identify the most common length by sorting...
|
||||
set sortedHist [lsort -decreasing -stride 2 -index 1 $histogram]
|
||||
lassign $sortedHist mostCommonLength freq
|
||||
|
||||
puts "most common length is $mostCommonLength, with frequency $freq"
|
||||
Loading…
Add table
Add a link
Reference in a new issue