usually i'd write something like

Code: Select all

`def foo(a, b, c, y)`

x = a**b mod c

if x == y or (x*y mod 2) == 0 or x == 1

goo(x+1, x-1)

else

goo(x+2, x-2)

but in haskell, i can't declare x as a variable (or at least i don't think that's proper functional programming?) so i have to substitute everything in the code, which makes for a lot of repetition.

Code: Select all

`foo a b c y = if (a**b mod c) == y or ((a**b mod c)*y mod 2) == 0 or (a**b mod c) == 1`

then goo((a**b mod c)+1,(a**b mod c)-1)

else

goo((a**b mod c)+2,(a**b mod c)-2)

i thought breaking it up might help

Code: Select all

`hoo a b c y = if (a**b mod c) == y or ((a**b mod c)*y mod 2) == 0 or (a**b mod c) == 1`

then True

else

False

foo a b c y = if hoo a b c y

then goo((a**b mod c)+1,(a**b mod c)-1)

else

goo((a**b mod c)+2,(a**b mod c)-2)

but that only moves the repetition into another function

what's the right way to do this?