Created
August 6, 2017 03:56
-
-
Save kunigami/85602af663ca5c1d504fa578e7d8fd90 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 processStateFromQueue {frontSize; front; rearSize; rear; rotation} = | |
let newState = (nextState (nextState rotation)) in match newState with | |
| Done newFront -> | |
{frontSize; front = newFront; rearSize; rear; rotation = Idle} | |
| _ -> {frontSize; front; rearSize; rear; rotation = newState} | |
;; | |
let check queue = match queue with | |
{frontSize; front; rearSize; rear; rotation} -> | |
if rearSize <= frontSize then processStateFromQueue queue | |
else | |
(* Initiate the rotation process. *) | |
let newState = Reversing ({ | |
validCount = 0; | |
front; | |
frontReversed = []; | |
rear; | |
rearReversed = []; | |
}) | |
in processStateFromQueue { | |
frontSize = frontSize + rearSize; | |
front; | |
rearSize = 0; | |
rear = []; | |
rotation = newState; | |
} | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment