-1
\$\begingroup\$

Background

Have you ever dream of quantum state? If that's true for you, you are probably weird...

Anyway, I came up with an idea: what if we make a quantum in code?

Task

Create a data type, function, or class, anything that can be put in a condition.

You can redefine anything as long as it’s infront of the other code( or the testcase I mean)

or you can make another file, and take the code as input, output the run result, but that will count as compiler/transpiler

What should it do:

(def your thing here, I'll name it "X" for now, you can also 
redefine “if”, or anything else, as long as it’s in this part of 
code and it doesn’t change the text of code(which count as transpiler i suppose))

if X:
  part a
else:
  part b

part a and b should both be executed, although the chance of which being first should be 50/50.


if X:
  a=5
else:
  a=10
  b=5

a should have 50% chance to be 5, 50% 10, but b will always be 5

x can be different everytime mention, or always the same on parallel universe

if X:
  part a
else if X:
  part b
else:
  part c

Could be:

execute a,b,c with a 50% being first execute,b,c 25% each.(second X and first X both being quantum)

In this case a will never be the second one executed.

possible case:

a,b,c
a,c,b
b,c,a
c,b,a
     / a True 50%
init           / b True 25%
     \ a False 
               \ b False - c 25%
     First X     Second X

Or:

X True for a

X False for c

b will never be executed.

     / X True - a
init 
     \ X False - c

you code should not work on non-quantum condition.

if True:
  if X:
    part a
  else:
    part b
else:
  part c

c should never be executed no matter what

Example

X as your submit

if X: # or X()
  print(1)
else:
  print(2)

return

1
2

or

2
1

the X can even just be a marker for your function to indicate where it need to rerun or change. as long as you specify your variable name( please don't inject whole code into it)

Extra

You can specific to always have else after if, since doing nothing in else will make it identical to normal if.

A whole compiler/transpiler (changing code to fit in quantum state) is allowed, but will compete on it's own(with other compiler style anwser).

Rule

  • Standard rules.

Goal

golf your quantum as smaller as possible!

\$\endgroup\$
4
  • 4
    \$\begingroup\$ Are you aware of any languages in which this is actually possible? \$\endgroup\$ Nov 26 at 2:23
  • 1
    \$\begingroup\$ @Unmitigated Mathematica. Try it online! \$\endgroup\$
    – alephalpha
    Nov 26 at 7:33
  • 2
    \$\begingroup\$ @alephalpha That just defines a new if, which is doable in most any language but isn't the challenge. This is however possible in some logical programming languages like curry that already allow superpositions (e.g. True?False in curry), the only hitch is that they need to be random. \$\endgroup\$
    – Grain Ghost
    Nov 26 at 9:36
  • 1
    \$\begingroup\$ @GrainGhost The Mathematica code does not define a new if, but defines a value x such that If has a special definition for it. I don't think this is doable in many other languages. \$\endgroup\$
    – alephalpha
    Nov 28 at 23:55