Very quick question, I am trying to implement SAT solving in Q# using Grover's Algorithm. I want to take every second element from an array starting at the second element, represented with a range element : 1..2..Length(array)
. I am not very experienced and I am trying to find a nice and clean way to do so, without too much unnecessary for loop. Could someone help ?
1 Answer
You can create an array with every second element starting from the second one using the expression array[1..2...]
.
-
$\begingroup$ So if I understand correctly, you input the range type directly and the array methods implicitly convert from the range element to an int array ? $\endgroup$ Feb 9, 2021 at 21:31
-
2$\begingroup$ Yes; from docs.microsoft.com/en-us/azure/quantum/user-guide/language/…: "If the expression inside the brackets is fo type Range then the new expression will contain an array of all items indexed by the specified Range." $\endgroup$ Feb 10, 2021 at 15:42
RangeAsIntArray
from the Microsoft.Quantum.Convert library will do the trick $\endgroup$