Challenge D2
Generate generalized W-state
4 other teams have completed this challenge.
Your task is to create a generalized W state on n qubits where n = 2^k (1 ≤ k ≤ 4) from zero |0..0⟩ state.
The classic W-state is defined as |W⟩ = 1/√3 (|100⟩ + |010⟩ + |001⟩) for n = 3, which is a helpful reference but is not itself a valid input for this challenge since 3 is not a power of 2.
The generalized W-state you need to implement is defined as |W⟩ = 1/√n (|10..0⟩ + |01..0⟩ + ... + |00..1⟩), where n is always a power of 2 in the range n = 2^k (1 ≤ k ≤ 4), i.e. n ∈ {2, 4, 8, 16}.
You have to implement the Solve operation which takes an array of n qubits in state |0..0⟩ and you need to create the W-state on them.
The operation should have the following signature: