I interepret
Moving the input list, if the element i ᵗʰ is in the position of the pair, add True i times to Output to the output; if the element i is is odd, add False i times to the Output list.
I see two ways to interpret this. "For all elements, if the i-th element is even, return True I times. Otherwise, return false I times" or "For all elements, the i-th element containing (v :: Int) should return True v times if I am equal to or False v times if I am odd. " The second one already has a satisfactory answer, so I will give one for the first.
Some people like to reference indexes, but in this case you don't need to worry about pointers. You can determine how many Bool does not count how many items you have passed.
accum f (x:[]) = [x] accum f (x:xs) = (x):(map f (accum f xs))
This function takes a function f and a list. It applies f to every item except the first, then makes a recursive call to the tail of the list, which again applies f to every remaining item, etc. The result is the following:
accum (+1) [1,1,1,1,1] [2,3,4,5,6]
The +1 function is applied twice to the second element, three times to the second, etc. Now, how does this help us ask? Ok, we can do this:
accum (\x -> [head x] ++ x) $ map (\x -> [x]) [2, 4, 1, 1, 2] [[2],[4,4],[1,1,1],[1,1,1,1],[2,2,2,2,2]]
First we convert each item to a list with one item. We are accum with the lambda that you see above, which combines the head into a list. Now we can directly convert to Bool without further manipulation.
(map . map) odd $ accum (\x -> [head x] ++ x) $ map (\x -> [x]) [2, 4, 1, 1, 2] [[False],[False,False],[True,True,True],[True,True,True,True],[False,False,False,False,False]]
You want [Bool] , not [[Bool]] so concat . Note that you can concat first and then map instead of map . map map . map :
map odd $ concat $ accum (\x -> [head x] ++ x) $ map (\x -> [x]) [2, 4, 1, 1, 2]