#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    4
    Rep Power
    0

    Haskell help - beginer need help


    Can someone write me the program for this: insert' 111 2 1 [[2..4],[3..5],[7..9]] = [[2, 3, 4],[3, 4, 111],[7, 8, 9]]

    And a program for rotating the list for i places. Positive i rotates left for i places and negative rotates right for i places. Don't use Data.Bits

    And also this: And also a function that is inserting an element on a i position in list , counting from 0, so that it replaces the existing element in the position i. If i is negative then the counting starts from the end of the list. The result must look like this:

    insert2' "fine" 2 ["I","am","great"] = ["I","am","fine"] insert2i 3 (-7) [1..4] = [1,3,3,4]

    these last one i tried to do like this:

    insert2' :: a -> Int -> [a] -> [a]
    insert2' x n [] = []
    insert2' x n xs = f ++ [x] ++ drop (length xs - n) xs
    where f = (take (length xs - n) xs)
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    Originally Posted by boba22
    Can someone write me the program for this:
    No. We don't do your homework, we don't help people cheat, and we don't drag students through highschool.

    We can help you sort your thougths and fix bugs, but if you expect others to do the work while you take a rest, this won't work out.

    OK, so you already tried something. What's the problem with that? Is there an error? An unexpected result?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    4
    Rep Power
    0
    This one work :

    insert' x n xs = first ++ [x] ++ drop 1 rest where (first, rest) = splitAt n xs

    i only have problem with starting from the 0 position, how can i do that?

    and in the first one, how can i set up list in list, i tryed like this:

    insert' xs ys = [[x y | x <- xs] | y <- ys]
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    You should do the tasks one at a time.

    Originally Posted by boba22
    insert' x n xs = first ++ [x] ++ drop 1 rest where (first, rest) = splitAt n xs

    i only have problem with starting from the 0 position, how can i do that?
    What problem? And what do you mean by "starting from the 0 position"? That the list index starts at 0? Doesn't it do that already?

    Also, please, please start to use [ CODE ] tags. Haskell is whitespace-sensitive, which means the formatting of the code is actually relevant.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo