You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be good to add functions for rotating a matrix by 90 degrees. Here are possible implementations of the functions:
rotateLeft : List (List a) -> List (List a)
rotateLeft =
List.reverse << transpose
rotateRight : List (List a) -> List (List a)
rotateRight listOfLists =
List.foldl (List.map2 (::)) (List.repeat (rowsLength listOfLists) []) listOfLists
I omitted the helpers here for brevity, but made an Ellie with the full implementations and tests https://ellie-app.com/cyQ6L4kgta1/2. (Note that transpose and rowsLength are functions that I wrote that are already part of List.Extra.)
As for my use case, I was making a Tic-Tac-Toe game last night for fun and it turns out that having either of these functions make checking for a win very easy. Check it out! https://ellie-app.com/3zjbyv2y6a1/2 (scroll down to the checkStatus function).
One other thing worth discussing is the names. I do not think that the current ones make it clear that we are working with matrices and not 1-dimensional lists. For example, rotateRight [1, 2, 3, 4] might be misunderstood to be [4, 1, 2, 3] (which might also be a helpful function?).
The text was updated successfully, but these errors were encountered:
I think it would be good to add functions for rotating a matrix by 90 degrees. Here are possible implementations of the functions:
I omitted the helpers here for brevity, but made an Ellie with the full implementations and tests https://ellie-app.com/cyQ6L4kgta1/2. (Note that
transpose
androwsLength
are functions that I wrote that are already part ofList.Extra
.)As for my use case, I was making a Tic-Tac-Toe game last night for fun and it turns out that having either of these functions make checking for a win very easy. Check it out! https://ellie-app.com/3zjbyv2y6a1/2 (scroll down to the
checkStatus
function).One other thing worth discussing is the names. I do not think that the current ones make it clear that we are working with matrices and not 1-dimensional lists. For example,
rotateRight [1, 2, 3, 4]
might be misunderstood to be[4, 1, 2, 3]
(which might also be a helpful function?).The text was updated successfully, but these errors were encountered: