Skip to content

Instantly share code, notes, and snippets.

@mralfarrakhan
Created June 6, 2023 15:58
Show Gist options
  • Select an option

  • Save mralfarrakhan/4461eeae91b5c8d56f75ff72b9d7cd7f to your computer and use it in GitHub Desktop.

Select an option

Save mralfarrakhan/4461eeae91b5c8d56f75ff72b9d7cd7f to your computer and use it in GitHub Desktop.
doubling rotate or something
(* input *)
let q = ['A'; 'B'; 'C'; 'D'; 'E'];;
let pos = 20;;
let rec list_print queue =
match queue with
| [] -> ()
| h :: t ->
Printf.printf "%c " h;
list_print t;;
let rec doubling queue n =
match n with
| 0 -> queue
| _ ->
let r =
match queue with
| h :: t -> t @ [h; h]
| _ -> queue
in
doubling r (n - 1);;
let () =
let v =
doubling q (pos - 1)
in
list_print v;;
let () =
Printf.printf "\n";;
let () =
let v =
doubling q (pos - 1)
in
let head =
match v with
| h :: t -> h
| [] -> ' '
in Printf.printf "#%d in queue: %c" pos head;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment