Kaderudo Posted January 5, 2010 at 11:09 AM Report Share #304187 Posted January 5, 2010 at 11:09 AM Um colega meu encontrou um óptimo site com exercícios em haskell, mas quando cheguei à parte das listas parei xD Preciso de ajuda neste cinco exercicios, vou por tal igual como ta no site: Exercise 3.1 Write a function sumListsPlus that, given a list of integer lists all having the same length, computes the sum list resulting of adding all elements of the same position. Examples: Main> sumListsPlus [[1,2,3]] [1,2,3] Main> sumListsPlus [[],[]] [] Main> sumListsPlus [[2,5],[3,0],[1,4]] [6,9] Exercise 3.2 Write a function merge that, given two ordered lists, computes the ordered merge list. Please see the examples. Examples: Main> merge [] [1,2] [1,2] Main> merge [0,2,4] [1,3,5] [0,1,2,3,4,5] Main> merge [(-5)..0] [0..5] [-5,-4,-3,-2,-1,0,0,1,2,3,4,5] Exercise 3.3 Write a function insert that, given an integer and an ordered list, computes the ordered list resulting of inserting the integer in the given list in the first position that keeps the list ordered. Examples: Main> insert 5 [0..4] [0,1,2,3,4,5] Main> insert 3 [1,3,6] [1,3,3,6] Main> insert (-1) [] [-1] Main> insert 6 [3,5,7] [3,5,6,7] Exercise 3.4 Program a function dup that replaces each element of a list by two occurrences of that element. Examples: Main> dup [] [] Main> dup [3,5,2] [3,3,5,5,2,2] Exercise 3.5 Program a function oddsBefore that put all odd elements before all even elements in a list of integers. Examples: Main> oddsBefore [2] [2] Main> oddsBefore [4,2,3,1] [3,1,4,2] Main> oddsBefore [10..20] [11,13,15,17,19,10,12,14,16,18,20] Obrigado e Bom Ano Link to comment Share on other sites More sharing options...
luchhozito Posted January 5, 2010 at 02:21 PM Report Share #304219 Posted January 5, 2010 at 02:21 PM põe o código que já fizes-te Link to comment Share on other sites More sharing options...
Kaderudo Posted January 9, 2010 at 03:29 AM Author Report Share #304945 Posted January 9, 2010 at 03:29 AM não o fiz porque ainda não consigui fazer Link to comment Share on other sites More sharing options...
estrelusca Posted January 10, 2010 at 09:59 PM Report Share #305292 Posted January 10, 2010 at 09:59 PM insert :: Int-> [int] -> [int] insert x xs | null xs = x : [] |x <= head xs = x : xs |otherwise = (head xs) : insert x (tail xs) Link to comment Share on other sites More sharing options...
estrelusca Posted January 10, 2010 at 10:00 PM Report Share #305293 Posted January 10, 2010 at 10:00 PM merge::[int]->[int]->[int] merge xs ys |null xs = [] |otherwise = qsort (xs ++ ys) so consegui fazer estes dois Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now