module Lp_informal_computations = struct

let take n = fst o chop_list n;;
let drop n = snd o chop_list n;;

let rec rotateL i xs = 
  if i=0 then xs 
  else match xs with
    | x::xss -> rotateL ((i-1) mod length xs) (xss @ [x])
    | [] -> [];;

let rotateR i = rotateL (-i);;

let list_pairs list =
  let h = hd list in
  let rec pairs list =
    match list with
      | [] -> []
      | [h1] -> [h1, h]
      | h1 :: h2 :: t -> (h1,h2) :: pairs (h2 :: t) in
    pairs list;;


let split_list list dart =
  let split_face f =
    if length f <= 3 then
      [f]
    else
      let t3, _ = chop_list 3 f in
      let _, d2 = chop_list 2 f in
	[t3; hd t3 :: d2] in

  let rec split list = 
    match list with
      | [] -> []
      | f :: t -> 
	  let pairs = list_pairs f in
	    if mem dart pairs then
	      let i = index dart pairs in
		split_face (rotateR 1 (rotateL i f)) @ t
	    else
	      f :: split t in
    split list;;

end;;