Please help!!!

View: New views
4 Messages — Rating Filter:   Alert me  

Please help!!!

by AVG :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What's wrong??

greatest common divisor from one list

code:



mdc :: Int-> Int -> Int
mdc _ 1 = 1
mdc 1 _ = 1
mdc x y
|x > y = mdc (x-y) y
|y > x = mdc (y-x) x
|x==y = x

mdcl :: [Int]-> [Int]
mdcl []=[]
mdcl l = mdcl ([mdc (tira(take 1 l)) (tira(take 1 (drop 1 l)))]++ drop 2 l)

gcdl :: [Int] -> Int
gcdl l = tira l

tira :: [Int] -> Int
tira []=0
tira [x]=x

Re: Please help!!!

by Stefan O'Rear :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Jun 09, 2007 at 12:22:02PM -0700, AVG wrote:

>
> What's wrong??
>
> greatest common divisor
>
> code:
>
>
>
> mdc :: Int-> Int -> Int
> mdc _ 1 = 1
> mdc 1 _ = 1
> mdc x y
> |x > y = mdc (x-y) y
> |y > x = mdc (y-x) x
> |x==y = x
>
> mdcl :: [Int]-> [Int]
> mdcl []=[]
> mdcl l = mdcl ([mdc (tira(take 1 l)) (tira(take 1 (drop 1 l)))]++ drop 2 l)
>
> gcdl :: [Int] -> Int
> gcdl l = tira l
>
> tira :: [Int] -> Int
> tira []=0
> tira [x]=x

http://haskell.org/haskellwiki/Homework_help

99% of people who ask with such urgency are looking for homework
answers.  Hint re your actual code: whitespace matters.

Stefan
_______________________________________________
Haskell mailing list
Haskell@...
http://www.haskell.org/mailman/listinfo/haskell

Re: Please help!!!

by AVG :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

But i tried and i don't know waht is wrong.

Re: Please help!!!

by Stefan O'Rear :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Jun 09, 2007 at 12:22:02PM -0700, AVG wrote:

>
> What's wrong??
>
> greatest common divisor
>
> code:
>
>
>
> mdc :: Int-> Int -> Int
> mdc _ 1 = 1
> mdc 1 _ = 1
> mdc x y
> |x > y = mdc (x-y) y
> |y > x = mdc (y-x) x
> |x==y = x

Since the three lines starting with | are a continuation of the
preceding line, they must be indented more.

> mdcl :: [Int]-> [Int]
> mdcl []=[]
> mdcl l = mdcl ([mdc (tira(take 1 l)) (tira(take 1 (drop 1 l)))]++ drop 2 l)
>
> gcdl :: [Int] -> Int
> gcdl l = tira l
>
> tira :: [Int] -> Int
> tira []=0
> tira [x]=x

Spelling out names like 'mdcl' and 'tira' will make it easier for us to
help you.  gcd isn't a problem because it is well established
mathematical notation, but the others are opaque to me.

Stefan
_______________________________________________
Haskell mailing list
Haskell@...
http://www.haskell.org/mailman/listinfo/haskell