1
$\begingroup$

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 ?

$\endgroup$
1
  • $\begingroup$ For people looking to for a specific function to do the trick : the RangeAsIntArray from the Microsoft.Quantum.Convert library will do the trick $\endgroup$ Feb 18, 2021 at 21:28

1 Answer 1

5
$\begingroup$

You can create an array with every second element starting from the second one using the expression array[1..2...].

$\endgroup$
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.