Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge is essentially similar to either thisthis or thisthis.

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge is essentially similar to either this or this.

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge is essentially similar to either this or this.

Mod Removes Wiki by Martin EnderMod
Post Made Community Wiki by Martin EnderMod
edited body
Source Link
Zgarb
  • 42.8k
  • 1
  • 22
  • 26

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge itis essentially similar to either this or this.

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge it essentially similar to either this or this.

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge is essentially similar to either this or this.

Source Link
Zgarb
  • 42.8k
  • 1
  • 22
  • 26

Generate a Random Boolean Expression

In this challenge, you generate a random Boolean expression -- and then evaluate it.

Input

Nothing, or a random seed if your program requires one.

Output

A random Boolean expression and its value, formatted as a string

<expr> = <value>

The expression should be generated according to the following BNF grammar:

<expr> ::= "0" | "1"
         | "(" <expr> "^" <expr> ")"
         | "(" <expr> "v" <expr> ")"
         | "(" <expr> ">" <expr> ")"
         | "~" <expr>

Here, ^ stands for binary AND, v for binary OR, > for implication, and ~ for NOT. Whitespace is not significant. The correct value for the expression should be self-explanatory. Some correct outputs include

0 = 0
~ (~1 ^ 1) = 1
((1v1) ^ ~(0 >(1 ^ ~~~0))) = 0

Detailed Rules

Assuming a perfect random number generator, your program must be able to generate any valid Boolean expression with nonzero probability (discounting whitespace). You must use you language's standard RNG, or one of higher quality.

You can write either a function or a full program, and a function can either return its result or print it to STDOUT. The fewest bytes wins, and standard loopholes are disallowed.


I'd like some input on whether this challenge it essentially similar to either this or this.