G TTT
G TTT

Reputation: 37

recursion over tuples list in haskell

Is there a recursion way to do somethings like below?

    updateOs2 :: [(Rotor, Int)] -> [(Rotor, Int)]
    updateOs2 [(a,x),(b,y),(c,z)]
        | x == 25 && y == 25 && z == 25 = [(a,0),(b,0),(c,0)]
        | x == 25 && y == 25            = [(a,0),(b,0),(c,z+1)]
        | x == 25                       = [(a,0),(b,y+1),(c,z)]
        | otherwise                     = [(a,x+1),(b,y),(c,z)]

I have tried to do recursion, but quite confused. Because once the last element z is passed the list comes to empty, can not go back to x anymore.

Upvotes: 1

Views: 109

Answers (1)

Yogendra
Yogendra

Reputation: 382

I think this should work

updateOs2 [] = []
updateOs2 ((a,x):xs)
    | x == 25 = (a,0): (updateOs2 xs)
    | otherwise =  (a,x+1):xs

Upvotes: 3

Related Questions