Is Infinite Process

Description


Given integers a and b, determine whether the following pseudocode results in an infinite loop

while a is not equal to b do
  increase a by 1
  decrease b by 1

Assume that the program is executed on a virtual machine which can store arbitrary long numbers and execute forever.

Example

  • For a = 2 and b = 6, the output should be isInfiniteProcess(a, b) = false;
  • For a = 2 and b = 3, the output should be isInfiniteProcess(a, b) = true.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] integer a

    Guaranteed constraints:
    0 \leq a \leq 20.

  • [input] integer b

    Guaranteed constraints:
    0 \leq b \leq 20.

  • [output] boolean

    • true if the pseudocode will never stop, false otherwise.

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
function isInfiniteProcess(a, b) {
	return a % 2 != b % 2 || a > b
}