title: Creating list from array elements, making sequence of numbers
body: <p>Here's the problem:
  I've got numbers like (for example) 3333 222 111. I need to write a program to check if it is possible to make sequence where same numbers are not each others neighbors. Only condition is that first and last elements are known. In this example lets make it 2 and 3. Correct sequence could be 2 32132131 3. </p>
  
  <p>My idea was to put count of middle elements into an array [|3;2;3|], create list via while loop (one method for ascending and another for descending), add first and last element and then check if sequence is correct. There would be a few options in main method - descengind, ascending, reverted etc</p>
  
  <p>Heres some code </p>
  
  <pre><code>let makeUp b e arr k= 
    let l = ref [] in
    let i = ref 0 in
    while (List.length !l&lt;k) do
      if arr.(!i) &gt; 0 then l := !i+1 :: !l ; arr.(!i) &lt;- arr.(!i) -1;
      i := (!i + 1) mod Array.length arr; 
    done;
    [b]@(List.rev !l)@[e];;
  
  let rec isCorrect lista =
    match lista with
      [] -&gt; true
    |h::[] -&gt; true
    |h::t -&gt; if (h = List.hd t)then false
      else isCorrect t;;
  </code></pre>
  
  <p>The problem is that I'm modyfing content of an array so I can make list of it only once. Something like this:</p>
  
  <pre><code>let find b e array length = 
    if isCorrect(makeUp b e array length) then makeUp b e array length
    else if isCorrect.....
    else [0]
  </code></pre>
  
  <p>simply won't work. I have no idea how to solve this task at all. </p>