Jump to content

Duvidas em exercicios de Listas em Haskell


Recommended Posts

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.


Main> sumListsPlus [[1,2,3]]


Main> sumListsPlus [[],[]]


Main> sumListsPlus [[2,5],[3,0],[1,4]]


Exercise 3.2

Write a function merge that, given two ordered lists, computes the ordered merge list. Please see the examples.


Main> merge [] [1,2]


Main> merge [0,2,4] [1,3,5]


Main> merge [(-5)..0] [0..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.


Main> insert 5 [0..4]


Main> insert 3 [1,3,6]


Main> insert (-1) []


Main> insert 6 [3,5,7]


Exercise 3.4

Program a function dup that replaces each element of a list by two occurrences of that element. 


Main> dup []


Main> dup [3,5,2]


Exercise 3.5

Program a function oddsBefore that put all odd elements before all even elements in a list of integers.


Main> oddsBefore [2]


Main> oddsBefore [4,2,3,1]


Main> oddsBefore [10..20]


Obrigado e Bom Ano

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.