haskell is imho quite nice too: calcValue x = calcValue' ("00"++x) where calcValue' (a:b:x:xs) = if x == 'x' then (calcValue' (a:b:xs))+read([a])+read([b]) else (calcValue' (b:x:xs))+read([x]) calcValue' _ = 0 I'm quite new to haskell, so this solution is probably far from perfect... ;) (o...