Skip to content

My solutions to µContest (defunct) programming challenges

Notifications You must be signed in to change notification settings

rdtsc/microcontest-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

µContest (Defunct) Solutions

As of early 2023, µContest has been shut down.

This repository houses my personal solutions to µContest's programming challenges.

The site is mostly written in French with some English translations here and there.

Some problem statements are either completely in French or have a mix of English and French content. In these cases, Google Translate is used to make sense of things. The results are not perfect, but mostly understandable.

Almost all API endpoints are implemented in French, so expect solutions to contain an awkward mix of variable names in English/French.

It is strongly encouraged that you do not view my solutions unless you've already solved the relevant problems yourself.

Development Notes

Local Environment

  • Linux
  • Docker ~v19
  • Node.js ~v12
  • Yarn ~v1
  • GCC ~v9

Initial Setup

$ git clone https://github.com/rdtsc/microcontest-solutions
$ cd microcontest-solutions
$ yarn
$ yarn mc setup

µContest Auth Token Setup
-------------------------
Username: user
Password: ********
Saved in /home/user/microcontest-solutions/auth.json

Workflow

To keep things consistent, the following tasks are provided for automating initial setup and solution boilerplate creation:

Task: mc setup

No longer applicable, µContest is gone.

The mc setup task is responsible for generating a µContest authentication token and should only be executed upon initial setup or when site account credentials change.

The generated token is stored in ./auth.json and is automatically removed from Git's working tree upon successful creation.

⚠️ Warning!

Note that as per the platform's specifications, part of the token contains a plain SHA-1 hash of the site's account password. µContest does not currently implement HTTPS so all communication is in plain-text!

Usage:

$ yarn mc setup

µContest Auth Token Setup
-------------------------
Username: user
Password: ********
Saved in /home/user/microcontest-solutions/auth.json

Subsequent invocations will result in a no-op:

$ yarn mc setup

µContest auth token already exists for "user".

If the authentication token needs to be regenerated, destroy the ./auth.json file and execute mc setup again.

Task: mc init

No longer applicable, µContest is gone.

The mc init task is responsible for creating solution boilerplate files and currently includes the following actions:

  • Solution directory creation in ./src based on the problem's ID.
  • Creation of an initial Markdown readme with the problem's HTML description and parsed I/O. (readme.md)
  • Mirroring of referenced images in the generated readme, if any. (extra/*)
  • Creation of the problem's metadata in YAML for future use. (meta.yaml)
  • Creation of a skeleton solution file with the required I/O arguments in JS. (solve.js)

This task requires a single command-line argument to be passed in the form of the problem's µContest ID. For example:

$ yarn mc init 20

Created /home/user/microcontest-solutions/src/20
Created /home/user/microcontest-solutions/src/20/meta.yaml
Created /home/user/microcontest-solutions/src/20/extra
Created /home/user/microcontest-solutions/src/20/extra/00.png
Created /home/user/microcontest-solutions/src/20/readme.md
Created /home/user/microcontest-solutions/src/20/solve.js
$ cat src/20/meta.yaml

id: 20
name: Optical Character Recognition I
category: AI
url: 'http://www.microcontest.com/contest.php?id=20&lang=en'
inputs:
  - name: img
    type: String
    cType: char*
    description: >-
      PNG image. Be careful : this buffer may contain null characters, use the
      provided length instead of the function strlen.
outputs:
  - name: text
    type: String
    cType: char*
    description: Text in the image
$ head src/20/readme.md | cut -c1-66

# Optical Character Recognition I

**AI – Problem #20**

`http://www.microcontest.com/contest.php?id=20&lang=en`


## Description

In this challenge, the goal is to recognise a word within an image...
$ cat src/20/solve.js

#!/usr/bin/env node

'use strict';

const {solve} = require('~/lib/mc');

solve(20, ({img}) =>
{
  const result =
  {
    text: null
  };

  // ...

  return result;
});

If a problem is down for maintenance or doesn't exist, the mc init task will fail:

$ yarn mc init 999999

Problem not available.

License and Copyright

All original code is released under the MIT license, unless otherwise specified.

All referenced/bundled dependencies, product names, trademarks, logos, and images are property of their respective owners.