mutable results = new (Int, Results)[Length(qubits)]; should have type Result as the second tuple element.
The second loop (the one that measures the qubits) should either iterate from 0 to Length - 1 or use index - 1 as qubit index in the array, otherwise it throws ArgumentOutOfRangeException.
Not a bug per se, but it looks weird to allocate an empty array of the right size and then append new elements to it; it seems more common either to allocate an array of size 0 and append to it or to allocate an empty array of the right size and then overwrite its elements with measurement results.
mutable results = new (Int, Results)[Length(qubits)];
should have typeResult
as the second tuple element.Length - 1
or useindex - 1
as qubit index in the array, otherwise it throwsArgumentOutOfRangeException
.