[Hugs-users] School assignment help

Urmastaag urmastaag at hotmail.com
Wed Oct 24 16:37:42 EDT 2007


Hello!

Can anybody point me to a right way here?
I have those exercises in haskell that i cannot do, because haskell is so
much different from other languages that i use. I have read so much from
different manuals but i do not understand haskell enough yet.

First exercise:

I must find a shorter list.
Here's how i did that, but my teacher said that it is unefficient way to do
it.

getShorter :: [a] -> [a] -> [a]
getShorter xs ys | length xs <= length ys = xs
                       | otherwise                  = ys

How do i do it effective, so that i only check as many elements from lists
as many are in the shortest list?

Second exercise:

Second exercise also need an effective answer:

I have to remove any occurances of certain number from list and give the
number of how many times that number was removed.

Unefficient version: 
remCount :: Int -> [Int] -> (Int,[Int])
remCount n xs = (length xs - length ys, ys)
       where ys = [ x | x <- xs, x /= n]



Exercise three:

moneyBack :: Int -> [(Int,Int)]

I must print out all pairs of bank notes and (bank notes, how many) which
salesman would give me back when he/she has to give me like 456 back.

moneyBack 0        ==>   []
moneyBack 10      ==>   [(10,1)]
moneyBack 123     ==>   [(100,1),(10,2),(2,1),(1,1)]
moneyBack 5326   ==>   [(500,10),(100,3),(25,1),(1,1)]

If anybody could point me in a right direction that would be great. 
Haskell seems very cool because the code is usually really short, but i just
need a start. I need more examples than i can find from google (maybe i'm
not using the right keywords). 

Thanks.

-- 
View this message in context: http://www.nabble.com/School-assignment-help-tf4685176.html#a13388655
Sent from the Haskell - Hugs-Users mailing list archive at Nabble.com.



More information about the Hugs-Users mailing list