I've done it in C# before but thought that a functional language would be a good fit for this kind of thing.
From this ascending list of integers:
I had to calculate the difference between two consecutive numbers and group them while the result doesn't change. The final output must be a
string like this:
"(group.length x difference)+(next group.length + next diff)+.."
Note that a same difference can appear multiple times in the sequence if it's not consecutive.
For this sample:
import Data.List countDelta :: [[a]] -> [(Int,a)] countDelta  =  countDelta [] =  countDelta ( (y:zs) : (bs) ) = (length zs + 1, y) : countDelta bs groupByDelta :: [Int] -> [(Int,Int)] groupByDelta (xs) = countDelta ( group [b-a | (a:b:_) <- tails xs] ) printTuples :: [(Int, Int)] -> String printTuples  = "" printTuples [(x,y)] = show x ++ "x" ++ show y printTuples (x:xs) = printTuples [x] ++ "+" ++ printTuples xs getSequenceLogic :: [Int] -> String getSequenceLogic  = "" getSequenceLogic [x] = printTuples [(1,0)] getSequenceLogic (xs) = printTuples (groupByDelta xs)
I get the expected result but is there any obvious error?