Posted to tcl by Cecil Westerhof at Sun Jun 16 11:13:46 GMT 2019view raw
- #!/usr/bin/env tclsh
- # For variable names longer as 3 charachters I use braces.
- # For example I use: $i, $fd, $arg and ${type}
- proc doCalculate {start {end ""}} {
- if {$end == ""} {
- set end ${start}
- }
- set factorial 1
- set n 1
- set power [set base ${start}]
- giveMsg "Start loop."
- while {True} {
- if {${factorial} > ${power}} {
- giveMsg "${base} -> $n"
- incr base
- if {${base} > $end} {
- break
- }
- set power [expr {${base} ** $n}]
- }
- incr n
- set power [expr {${power} * ${base}}]
- set factorial [expr {${factorial} * $n}]
- }
- }
- proc giveMsg {msg} {
- puts "[clock format [clock seconds] -format %H:%M:%S]: $msg"
- }
- switch ${argc} {
- 1 -
- 2 {
- doCalculate {*}${argv}
- }
- default {
- puts "Usage: [file tail ${::argv0}] start ?end?"
- exit 1
- }
- }
Comments
Posted by CecilWesterhof at Sun Jun 16 11:17:46 GMT 2019 [text] [code]
This is my take on calculating the values for: a(n) = smallest m>0 such that n^m < m! Later I want to implement the log algoritm as suggested by kbk.