Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Different factorial implementations
# factorial, recursive proc fact1 n {expr {$n<2?1:$n*[fact1 [incr n -1]]}} # factorial, loop proc fact2 n {for {set f 1} {1<$n} {incr n -1} {set f [expr {$f*$n}]}; set f} # factorial, custom multiplication implementation proc mul {a b} {expr {($b&1?$a:0)+($b?[mul [expr {$a<<1}] [expr {$b>>1}]]:0)}} proc fact3 n {for {set f 1} {1<$n} {incr n -1} {set f [mul $f $n]}; set f} # test output for {set i 1} {$i<10} {incr i} { puts $i:\t[fact1 $i]\t[fact2 $i]\t[fact3 $i]}
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
NISP - Wheel Movements 0.1
Trying bin mul floating point
XorShift On Tcl
Perfect decimal to binary add
mysrc.tcl
Bin mul float
tcl to python list test
1
Perfect bin mul eo float
3
stackse - search stackoverflow differently
Please log in to post a comment.