Contents

Suggest a Problem

If you feel you know some funny problem and you want it to be added to our site - welcome :)

Here are general consideration and then follow some advanced technical details (for those who want to contribute data generator / checker code).

  1. Even problem idea could be enough - it is not necessary to provide precise problem statement, checking code or example of solution. We can do it for you (if we understand the problem, of course).
  2. Your Authorship - we would be glad to place a link to your personal page, site or facebook profile along with the problem statement so that users know who is the author - so don't forget to tell how to introduce you.
  3. Supplying problem statement - if you really want - feel free to provide the problem statement yourself so we use it with as least changes as possible. You even may use Markdown format (in which statements are stored) - but it is easier to leave formatting to us.
  4. Problem types - different types of problems are welcome. You see one of them are for real beginners, others could be about geometry of physics, third could be of puzzle kind. Also you can invent problems for Challenges, i.e. not expecting some exact answer.
  5. Technical limitations - every problem has a piece of secret code we call "checker" for simplicity - it is responsible for generating input data and expected answer (or check proposed answer if alternatives are possible). This mainly is done in PHP but additionally could be done in Python and Perl. If you would like to participate in writing this, check the details below.
  6. Additional features - to help people understand your problem or to attract attention to it we can try adding small enhancements to it:
    • small drawings in SVG format or small raster images hosted outside (though SVG is preferred);
    • small javascript demos - the code is embedded into the problem statement so here are few technical limitations;
    • additional wiki articles - if your problem statement requires some lengthy explanation.

Generally it is best to start with small forum post outlining your suggestion so we discuss feasibility of the idea and what is to be done.

On writing "checkers"

Oldest way the "checkers" for problems work is that when the page is loaded by user, the code for the task is executed and gives two values as output:

There are some obvious limitations - code should not run more than about 1 second (and be sure, server is probably not as fast as your personal computer). Also most probably there is some memory limitation but usually we don't hit it.

Currently supported languages are:

With Python and Perl your code should simply produce output (e.g. with prints) of which all lines except last are considered input data for the problem and the last is the expected answer. For example:

#python3

import random

n = random.randint(4, 9)
print(n) # number of testcases
ans = []
while len(ans) != n:
  a = random.randint(100, 999)
  b = random.randint(100, 999)
  ans.append(str(a + b))
  print(a, b) # next testcase
print(' '.join(ans))

Note the comment in the first line - website uses it to choose the language.

With PHP compose a function which returns array of two string values (input and answer). If the code is large, feel free to add some class with a fancy name and hide any necessary internals inside it.

function checker() {
    $n = rand(20, 30);
    $q = array($n);
    $r = array();
    for ($i = 0; $i < $n; $i++) {
        $a = rand(-9999999, 9999999);
        $b = rand(-9999999, 9999999);
        array_push($q, "$a $b");
        array_push($r, min($a, $b));
    }
    return array(implode("\n", $q) , implode(' ', $r));
}

If the problem has possible alternative answers, just ask for additional instructions :)

Extended "checkers" functionality

In some cases it doesn't work to simply compare the submitted answer with precalculated one. For example, problem could have several valid answers and we need to verify validity with some algorithm. Or we may want to check that answer is submitted within specific amount of time.

For such cases there is quite versatile approach. If the checker produces answer starting with #pyx (5 characters, including space), then answer verification is done with calling the same code, but providing it with two additional global variables:

The code should print out the single string in response to this. If the string is ok then problem is accepted. Otherwise string is regarded as error message and is shown to user with failed attempt.

Here is code example to demonstrate the approach:

#python3

# suppose the task is to print square of single number given as input
# but within about 1 minute limit

from random import randrange
import time

#=== this part is used when checking the answer really
if "expected" in vars():
    parts = expected.split(" ", 2)
    if answer != parts[2]:
        print("Answer does not match, expected: " + parts[2]); quit()
    t0 = int(parts[1])
    if time.time() - t0 > 65:
        print("Sorry, answer should be submitted within 1 minute limit"); quit()
    print("ok")
    quit()

#=== below normal data "generator" follows
q = randrange(10, 100)
ans = q * q
t0 = int(time.time())
print(q)
print("#pyx %s %s" % (t0, ans))