Posted to tcl by Cecil Westerhof at Sun Jun 16 11:13:46 GMT 2019view raw

  1. #!/usr/bin/env tclsh
  2.  
  3. # For variable names longer as 3 charachters I use braces.
  4. # For example I use: $i, $fd, $arg and ${type}
  5.  
  6.  
  7. proc doCalculate {start {end ""}} {
  8. if {$end == ""} {
  9. set end ${start}
  10. }
  11. set factorial 1
  12. set n 1
  13. set power [set base ${start}]
  14. giveMsg "Start loop."
  15. while {True} {
  16. if {${factorial} > ${power}} {
  17. giveMsg "${base} -> $n"
  18. incr base
  19. if {${base} > $end} {
  20. break
  21. }
  22. set power [expr {${base} ** $n}]
  23. }
  24. incr n
  25. set power [expr {${power} * ${base}}]
  26. set factorial [expr {${factorial} * $n}]
  27. }
  28. }
  29.  
  30. proc giveMsg {msg} {
  31. puts "[clock format [clock seconds] -format %H:%M:%S]: $msg"
  32. }
  33.  
  34.  
  35. switch ${argc} {
  36. 1 -
  37. 2 {
  38. doCalculate {*}${argv}
  39. }
  40. default {
  41. puts "Usage: [file tail ${::argv0}] start ?end?"
  42. exit 1
  43. }
  44. }

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.