# Fuzz puzzles

Are you ready to test your skills as a human fuzzer? Here’s a collection of puzzles where the objective is to find an input that leads to the execution of what appears to be dead code.

## JavaScript

### Puzzle 1: Cyclic ordering

``````function f(a, b, c) {
if (a < b && b < c && c < a) {
throw Error();
}
}
``````

Goal: Find values for `a`, `b` and `c` such that `f(a,b,c)` throws an error.

Constraint: All input values should be of primitive type (i.e. not objects or arrays).

### Puzzle 2: And but not Or

``````function f(a, b) {
if (a > b || a == b) {
return true;
} else if (a >= b) {
throw Error();
} else {
return false;
}
}
``````

Goal: Find values for `a` and `b` such that `f(a, b)` throws an error.

Constraint: All input values should be of primitive type (i.e. not objects or arrays).

### Puzzle 3: Sort descending by default

``````function f(a, b) {
var min = a <= b ? a : b;
var max = a >= b ? a : b;
var [first, second] = [a, b].sort();

if (a != b && first === max && second === min) {
throw Error();
}
}
``````

Goal: Find values for `a` and `b` such that `f(a, b)` throws an error.

Constraint: All input values should be of primitive type (i.e. not objects or arrays).

## Python

### Puzzle 4: To be and not to be

``````def h(x, y):
return x is y+1

def g(x):
return h(x, x-1)

def f(x):
if g(x) and not g(x+1):
raise Exception()
``````

Goal: Find a value for `x` such that `f(x)` raises an exception.

Constraint: The input value is of a primitive type (i.e. it is a number). Use the reference implementation of Python (aka CPython).

Hint: No solutions exist on some other implementations of Python such as PyPy.

Credit to Kevin Laeufer for introducing me to this phenemenon.

Written on November 18, 2017 by Rohan Padhye