Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

recursive --> iteration

Name: Anonymous 2012-01-31 21:11

hello /prog/, yes this is basically homework help...

I have a C function that computes the eth power of a number x, modulo another number m, where e is very large. The function uses recursion to do so. I need to implement the program using iteration. I've attempted it and i'm really stuck here, i provided both functions in this paste: http://pastebin.com/ayb87BBr

can someone please point out my stupid mistakes?

Name: Anonymous 2012-02-01 1:32


powmod2 :: Integral -> Integral -> Integral -> Integral
powmod2 _ 0 _ = 1
powmod2 x e m =
    if e `mod` 2 == 0 then
        powmod2 xsqrm (e / 2) m
    else
        x * $ powmod2 xsqrm (--e)/2 m % m;
    where xsqrm = (x*x)%m;

So, why doesn't everyone use Haskell?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List