When we showed an earlier version of www.pexforfun.com to our long-term collaborator Tao Xie, Associate Professor at NCSU, he wondered whether the website could be more interactive, by making the user figure out and type in an entire implementation of an algorithm, instead of just guessing which values are interesting for a given implementation. And now we have done just that!
A Coding Duel is an interactive puzzle. In a Coding Duel, your task is to implement the
Puzzle method to have exactly the same behavior as another, hidden,
Puzzle method. (This is different from “simple puzzles”, where your task is to simply guess what a given
Puzzle method does, by studying the code of the
Puzzle method.) Every time you Ask Pex! you will get feedback whether your current version of the
Puzzle method behaves differently for some values. You then have to adapt the program text of your
Puzzle method, until it behaves exactly the same as the secret, hidden implementation. When they behave in the same way, you win the Coding Duel!
Built-in Coding Duels
Click on any of the following links to start a built-in coding duel. Can you stand up to the challenge? The Coding Duels are listed roughly in order of difficulty.
Creating new Coding Duels
You can create a new Coding Duel as follows. Implement a
Puzzle method, so that it compiles, and then Ask Pex! to analyze it. When Pex has finished, you will find a new button Turn This Puzzle Into A Coding Duel. When clicking the button, Pex will take your current puzzle program text, and turn it into the secret implementation. The program text shown to the user will be replaced by a dummy implementation, which they will have to refine to match the secret implementation. You can edit the dummy implementation. Finally, you can create a Permalink for a new Coding Duel created as described above, and share with other people.
Current Restrictions: Coding Duels can only be created for C# and F#. The Puzzle method must have a non-void return type. All its parameter and argument types must be basic types (from mscorlib), or arrays of basic types. When you create a Coding Duel, please make sure that your implementation does not mutate the parameters; this is not currently supported, and would lead to strange results. Also, in this release, do not use Code Contracts in Coding Duels.
You can post your own Coding Duel via a Permalink on our MSDN Forums for Pex, to share and discuss it with other people.
Note: At this time, Pex for fun does not store custom Coding Duels in the cloud. Instead, the generated URL itself encodes the language and program text in a compressed form. As a result, the URLs might be quite long, depending on the size of the program text. This is normal.
This update of the website comes with a few other changes: Permalinks are no longer read-only by default. Also, while you are working on a puzzle or Coding Duel, Pex will show some statistics at the very end of the page: There will be one entry for every time you clicked on Ask Pex!