I have a function that produces list of integers to which I would like to apply mod so that no element in the list is greater than 25. For example, the list [6,8,18,28,14,25] should return as [6,8,18,2,14,25]. The code so far is as follows.
let charIntList = zip ['a'..'z'] [0..25]
let getIntFromList (x:xs) a = if fst x == a then snd x else getIntFromList xs a
charToInt :: Char -> Int
let charToInt a = getIntFromList charIntList a
zipWithPosition :: [Char] -> [(Char, Int)]
let zipWithPosition m = zip m [0..length m]
position :: [(Char, Int)] -> [Int]
let position m = map snd (zipWithPosition m)
messToInt :: [Char] -> [Int]
let messToInt m = map charToInt m
almostVig :: [Int] [Int] -> [Int]
let almostVig m = zipWith (+) (messToInt m) (position m)
adjust :: [Int] -> [Int]
let adjust m = (mod (almostVig m) 26)
This code fails to apply mod to every element in the list generated by almostVig. I have tried using zipWith in adjust
as let adjust m = zipWith (mod (almostVig m) 26)
, but that also failed. How can I apply mod
to every element in a list to produce a new list in which no element is greater than 25?