Skip to content

Commit 2248e6f

Browse files
committed
Update bits
1 parent b44dced commit 2248e6f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

quantum/qubit/qubit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ func (q *Qubit) State(idx ...[]int) []State {
724724

725725
var binary []string
726726
for _, j := range idx {
727-
binary = append(binary, take(n, i, j))
727+
binary = append(binary, bits(n, i, j))
728728
}
729729

730730
state = append(state, NewState(amp, binary...))
@@ -751,18 +751,18 @@ func round(a complex128, tol ...float64) (complex128, bool) {
751751
return a, false
752752
}
753753

754-
func take(n, i int, idx []int) string {
755-
var sb strings.Builder
756-
for _, j := range idx {
754+
func bits(n, i int, idx []int) string {
755+
bytes := make([]byte, len(idx))
756+
for k, j := range idx {
757757
if (i & (1 << (n - 1 - j))) == 0 {
758-
sb.WriteByte('0')
758+
bytes[k] = '0'
759759
continue
760760
}
761761

762-
sb.WriteByte('1')
762+
bytes[k] = '1'
763763
}
764764

765-
return sb.String()
765+
return string(bytes)
766766
}
767767

768768
func TensorProduct(qb ...*Qubit) *Qubit {

0 commit comments

Comments
 (0)