Last active
August 6, 2017 03:50
-
-
Save kunigami/e715a80869f324c2cbf1f42e6cd7a859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nextState rotationStep = | |
match rotationStep with | |
| Reversing ({ | |
validCount; | |
front = firstElem :: restFront; | |
frontReversed; | |
rear = lastElem :: restRear; | |
rearReversed; | |
}) -> Reversing ({ | |
validCount = validCount + 1; | |
front = restFront; | |
frontReversed = firstElem :: frontReversed; | |
rear = restRear; | |
rearReversed = lastElem :: rearReversed; | |
}) | |
| Reversing ({ | |
validCount; | |
front = []; | |
frontReversed; | |
(* Invariant: restRear must be empty *) | |
rear = lastElem :: restRear; | |
rearReversed; | |
}) -> Appending ({ | |
validCount; | |
front = frontReversed; | |
rear = lastElem :: rearReversed; | |
}) | |
| Appending ({validCount = 0; front; rear}) -> Done rear | |
(* Transfer one element of front to rear *) | |
| Appending ({validCount; front = elem :: restFront; rear}) -> | |
Appending ({ | |
validCount = validCount - 1; | |
front = restFront; | |
rear = elem :: rear; | |
}) | |
| rotationStep -> rotationStep (* No-op *) | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment