Hiya,
I really need help ASAP on the one. I have a list (_,Index) where the index's are '2, 4,6, 7, 9, 10, 13,' and I need to return all the index's that are consecutive.There is no way to loop properly in haskell and I cant think of a way. Ie 6 7,9 and 10 are consecutive so I want to return (_,6),(_7),(_,9),(_10). .
Thanks
2 replies to this topic
#1
Posted 14 December 2011 - 02:26 PM
|
|
|
#2
Posted 14 December 2011 - 04:01 PM
You'll have to use a recursive solution, where you return the current portion along with whatever the next recursive call returns.
#3
Posted 20 December 2011 - 01:13 PM
List comprehension is pretty easy in haskell unless I'm misunderstanding your question
ghci> let indexs = [2, 4, 6, 7, 9, 10, 13] ghci> [(x, y) | x <- indexs, y <- tail indexs, (x + 1) == y] [(6,7),(9,10)]
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top










