This is a series of Java puzzles that put your Java skills to the test, in a challenging and fun way!
A puzzle consists of some given Java code with a line in it that seems to be impossible to reach. It’s up to you to find the hole in it, abuse a subtle behavior of Java to make execution reach that line anyways.
Short version: You must run the program with
java -Djava.security.manager the.MainClass. Any cheating in the content of your .java file is allowed; it is the whole point of the puzzle. Cheating the (compiler or runtime) environment from outside your code is not allowed.
If that’s clear, then start puzzling now and forget about the rest. But if that still leaves you in doubt:
- The goal of each puzzle is to reach a certain line in the exact given class. Reaching the line in a modified copy of the given classes does not count.
- You can use any unmodified Java compiler and runtime. Puzzles are not intended to be version-specific so I recommend you just use something recent like JDK
6 or7 or 8.
- No extra arguments to the compiler or runtime except for the
-Djava.security.managerare allowed. The security manager option is there to prevent things such as setAccessible that would spoil the fun. If you like to work from within your IDE, add that option to the JVM arguments of the run configuration. If you don’t change any other funky settings you’re good to go.
- The solution consists of just the content of the one
.javafile. Other files may not be modified, and if any extra steps or tweaks are needed to be able to make it work, it’s not a valid solution.
- Within that code everything is allowed, except exploiting known security holes in Java itself. You can write ugly things that would not be acceptable in any decent program. If you really feel like it and can pull it off, you can make a classloader subclass dance naked on a reflective error. But it’s unlikely to help you get closer to the solution.
Puzzles published so far:
|Clowns||(solution)||How can you fit 20 clowns into a Volkswagen?|
|Dreams||(solution)||Am I still dreaming?|
|Car||(part 2, solution)||Vroom!|
|Liquid (includes solution)||Program your way past airport security|
|Chicken||(solution)||Which was first, the chicken or the egg?|
|Cookies||(solution)||Learn how to count down with Count von Count and Cookie Monster|
|Square Root||(solution)||Find the square root of a huge number, without even looking at it|