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

Pages: 1-

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-01-31 22:27

Asking for homework help on /prog/

Name: Anonymous 2012-01-31 23:45

wow this is bad

Name: Anonymous 2012-02-01 1:04

...i'll just say do the modulo(s)  inside the power func, rather than calculating a huge number then stripping it down with a big modulo... [inb4 small modulo of a big number // yeh.. exactly]

=)

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?

Name: Anonymous 2012-02-01 1:33

>>5
s/x * $/(* x) $/

s/%/`mod`/

Name: Anonymous 2012-02-01 1:52

>>5
2deep4them.

Name: Anonymous 2012-02-01 8:44

long int powermod(int x, int e, int m){
int _x = x;
--e;
while(--e)
x *= _x;
return x % m;
}

Name: Anonymous 2012-02-01 9:57

>>8
Enjoy your slow unoptimized iterative shit that performs worse than Ops recursion.

Name: Anonymous 2012-02-01 9:58

>>5
Because Haskell is a piece of shit which is only fit for use in small toy programs.

Name: Anonymous 2012-02-01 10:34

>>5
powmod2 :: Integral -> Integral -> Integral -> Integral
So, why doesn't everyone use Haskell?
Haskell's type system is shit.

Name: Anonymous 2012-02-01 10:37

>>1
not

Name: translate it from russian 2012-02-01 10:38

в етом ИТТ треде мы выяснили что новомодные анальные игрушки для быдляков ПИСТОН и ХАЧКЕЛЬ
сосут у олдфажных мега языков на все времена C-шки и perl-а все время
---
лучий вариант на ПИСТОНЕ: http://ideone.com/udDJ9
(императивный понос)
2 варианта на ХАЧКЕЛЕ
1.ебаный пиздец во всех смыслах и имеперативное гавнище: http://ideone.com/M42su
(сосет у C-шки)
2. деклашотивное петушение http://ideone.com/0e3qE
(сосет у декларотивного петушения на perl)
---
для сравнения
perl: http://ideone.com/i0ob4 http://ideone.com/olq5B
C: http://ideone.com/ap43H
LUA: http://ideone.com/DVdhr http://ideone.com/Xkj4D
---
http://ideone.com/6cZYq лисп как и ожидалось сонул, ну и возможно ответ неправильный
(какието черезжопные варианты с 33 кратной вложеностю скобок быле побыстрее но натая хуйне никому не сдалась когда есть простое и самое быстрое решение на C-шке)

Name: Anonymous 2012-02-01 10:49

>>5
Haskell isn't Turing complete. Even sed and vi are Turing complete.

Name: Anonymous 2012-02-01 14:58

>>5
dude Integral is a Typeclass, not a datatype

Name: Anonymous 2012-02-01 14:59

>>14
ninja, are you subzerious?

Name: Anonymous 2012-02-01 15:10

>>14
that vi is turing complete is not something they should be proud of

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