Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions source/npm/qsharp/ux/histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,23 @@ function getDefaultMenuSelection(
return selection;
}

const reKetResult = /^\[(?:(Zero|One|Loss), *)*(Zero|One|Loss)\]$/;
const reKetResult =
/^\[(?:(Zero|One|Loss|0|1|2|-), *)*(Zero|One|Loss|0|1|2|-)\]$/;
function resultToKet(result: string): string {
if (typeof result !== "string") return "ERROR";

if (reKetResult.test(result)) {
// The result is a simple array of Zero and One
// The below will return an array of "Zero" or "One" in the order found
const matches = result.match(/(One|Zero|Loss)/g);
// The result fits our expected pattern, so we can convert it to a ket. If not, just return the raw result.
const matches = result.match(/(One|Zero|Loss|0|1|2|-)/g);
let ket = "|";
matches?.forEach(
(digit) => (ket += digit == "One" ? "1" : digit == "Zero" ? "0" : "-"),
(digit) =>
(ket +=
digit == "One" || digit == "1"
? "1"
: digit == "Zero" || digit == "0"
? "0"
: "-"),
);
ket += "⟩";
return ket;
Expand Down
Loading