@githg22_gitlab: Taking a hint from the problem statement itself, I'd suggest that the last sentence is especially relevant here.
"This operation can be implemented using just the X gate and its controlled variants."
!
register!
using()
using
block. As you note, you can't use measurement to do that in an adjointable operation; given that resetting is a special case of measurement, the Reset
operation will also fail to preserve adjointability. The trick is that you need to coherently reset the qubit to |0⟩ without measurement. You can do that because you know exactly what state it's in at the end of the using
, and can unprepare it using only unitary operations. The within
/apply
feature of Q# or the ApplyWithCA
operation will be very handy here.
By the way, @crazy4pi314 will be streaming with @bettinaheim about the Q# compiler today in a little under three hours if anyone is interested to join at https://twitch.tv/crazy4pi314. More details at https://twitter.com/crazy4pi314/status/1271837229221101569.
'T
and that returns an output of type 'U
is written as 'T => 'U
; thus, unitary : (Qubit = > Unit is Adj + Ctl)
indicates that unitary takes a Qubit
input and returns Unit
. The is Adj + Ctl
tells you that unitary
is adjointable and controllable (very important for some of the contest problems!). In this case, we can read the signature of Solve
as telling us that it takes an adjointable and controllable single-qubit operation, and returns an Int
.