Is there any way to swap items in a list of lists based on the index of one item? I've found a solution on how to implement swap onto a single list:
swap :: Int -> Int -> [a] -> [a]
swap i j list = let elemI = list !! i
elemJ = list !! j
left = take i list
middle = take (j - i - 1) (drop (i + 1) list)
right = drop (j + 1) xs
in left ++ [elemJ] ++ middle ++ [elemI] ++ right
From here I've tried to implement my own solution using a tuple as input for an index:
swapUp :: [(Int, Int)] -> [[Int]] -> [[Int]]
swapUp [(i,j)] puz = let emptyTile = puz !! [(i,j)]
tile = puz !! [(i+1,j)]
beg = take [(i,j)] puz
middle = take [(i+1,j-1)] (drop [(i,j+1)] puz)
end = drop [(i+1,j)] puz
in beg ++ tile ++ middle ++ emptyTile ++ end
The basic idea for my function is that it takes in the index of 0 in a list of lists and returns that list of lists with 0 and the number below swapped. I'm not sure if I can technically use the take, drop, and !! syntax since they take in ints but any advice on this would be beneficial.