Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created August 6, 2017 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/85602af663ca5c1d504fa578e7d8fd90 to your computer and use it in GitHub Desktop.
Save kunigami/85602af663ca5c1d504fa578e7d8fd90 to your computer and use it in GitHub Desktop.
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