My goal is the following:
They give me a list of Char, for example:
["++++.++++.++."]
What I want to achieve is to separate that list into small lists (put together a matrix) of Whole numbers, where each positive number will represent the sum of '+' and the negative number -1 the '.' '
Following the example of the list I gave, the matrix should be like this:
[[4],[-1],[4],[-1],[2],[-1]]
Use GHCi, version 8.2.1
For now I have:
compararChar :: (Char, Char) -> Bool
compararChar (c1, c2) = if c1==c2 then True else False
contarCaracteresHastaElPunto :: [Char] -> Int
contarCaracteresHastaElPunto [] = 0
contarCaracteresHastaElPunto (x:y) = if (compararChar(x, '.') /= True) then 1 + contarCaracteresHastaElPunto(y) else contarCaracteresHastaElPunto(y)
-- *Main> contarCaracteresHastaElPunto ("+++..")
-- 3
The function countCharactersAndThePoint I did it to see if it returned at least the first sum of '+' to find the first point '.'
Unfortunately, even that did not work out for me. Since if it happened:
("+++ ..") returns me the number 3, that's fine, but if I pass it for example ("+++. ++"), it will return 5, that is, it adds all the characters of the chain instead of adding the first 3.
I calculate that the problem is in else
of if
, but I do not know how to leave it empty.
If some haskell guru can give me a hand with all this mambo, I would be very grateful!