Quantcast
Viewing all articles
Browse latest Browse all 18

Answer by Johannes Kuhn for Implement division using only addition

Tcl, 0 additions.

Well, I had to find a way that does not use other data structures but is still not what you want:

# coroutine counter.proc ccnt {} {yield [info level]; ccnt}# add implementation without add.proc cadd {a b} {    set last 2    coroutine cadda ccnt    coroutine caddb ccnt    while {[cadda]<=$a} {}    while {[caddb]<=$b} {set last [cadda]}    rename cadda {}    rename caddb {}    return $last}proc divide {a b {c 0}} {    if {$c == 0} {set c $b} {set c [cadd $b $c]}    if {$c>$a} {tailcall info level}    divide $a $b $c}

Uses the current stack size of different green threads.


Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>