Git Product home page Git Product logo

gettc's Introduction

Download a TopCoder problem, parse the examples and system tests, then finally generate a naive solution for the following languages:

  • C++
  • Haskell
  • Java
  • Python 3
  • Go

And support for more languages is just around the corner.

You write the function definition and the generated solution will take care of running it against the downloaded input and output files.

TopCoder is a heaven for programmers. Solving algorithmic problems is a great way to embrace the passion for programming. There are problems for all levels. A strong academic background is not required to enjoy it. If you like Project Euler, you will probably love TopCoder.

However, the TopCoder online arena is quite inconvenient and supports only a few languages. Gettc's goal is to make the practice of solving algorithmic problems convenient and fun, and in your desired language.

At a glance

$ [sudo] gem install gettc
$ gettc 11127

Note that 11127 is the ID that TopCoder gives to the problem named DigitHoles. You can find the ID for any problem if you look at the URL for that problem's statement (you need to have a TopCoder account). Output:

You have given ID = 11127
Downloading problem to raw HTML ... Done
Parsing problem from raw HTML ... Done
Generating problem diectory for DigitHoles ... Done

Now:

$ cd DigitHoles/solve/cpp
$ make demo

Output:

Check 0 ... 0m0.328s
Failed
    Input: <42>
    Expected: <1>
    Received: <0>
Check 1 ... 0m0.015s
Failed
    Input: <669>
    Expected: <3>
    Received: <0>
Check 2 ... 0m0.016s
Failed
    Input: <688>
    Expected: <5>
    Received: <0>
Check 3 ... 0m0.015s
Passed
Check 4 ... 0m0.016s
Failed
    Input: <456>
    Expected: <2>
    Received: <0>
Check 5 ... 0m0.016s
Failed
    Input: <789>
    Expected: <3>
    Received: <0>
6 cases checked, 5 failed, 0 errored
Failed cases: 0 1 2 4 5

As you can see, the generated solution actually managed to solve 1 test case. Gettc is pretty smart after all. Anyway, you still need to do the hard work. Open the file DigitHoles.cpp in your favourite editor and enter the following content:

int numHoles(int number) {
    static int holes[] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1};
    int ret = 0;
    while (number > 0) {
        ret += holes[number % 10];
        number /= 10;
    }
    return ret;
}

And then try again:

$ make demo

You should see:

Check 0 ... 0m0.141s
Passed
Check 1 ... 0m0.015s
Passed
Check 2 ... 0m0.016s
Passed
Check 3 ... 0m0.015s
Passed
Check 4 ... 0m0.016s
Passed
Check 5 ... 0m0.015s
Passed
6 cases checked, 0 failed, 0 errored

Good. We have passed all the example tests. Why not challenge the system tests while we are it?

$ make sys

Output:

131 cases checked, 0 failed, 0 errored

Congratulations! You have solved a TopCoder problem like a boss!

Installation

The following packages are hard dependencies:

  • Ruby: The Ruby installer is recommend for Windows users.
  • RubyGems: Many Ruby installations already bundle RubyGems.
  • The standard GCC toolset: Most Unix systems have it bundled. Windows users may use MinGW or Cygwin.

With those in place, we are aready to go:

$ [sudo] gem install gettc

Once that is done, you should be able to run gettc on the command line. After a solution directory is generated, the standard procedure is:

$ cd ProblemName/solve/your_language
$ make

Now there are a couple things you need to get depending on your desired language.

Tips

  • Provide your own username/password in ~/.gettc/config.yml if download fails.
  • Use make sysv to display failed cases when challenging the system tests.
  • You may rm -rf build after you're done solving to save some disk space.
  • You can play with the contents of the directory ~/.gettc to, say, remove things you don't want to be generated. If you mess up, you can safely delete the whole directory ~/.gettc. The next time gettc runs, it will notice that there is no ~/.gettc and regenerate that.
  • You can bring the solutions generated by gettc to another computer to run. Such system doesn't need to have gettc, or even ruby, but it will need the standard gcc toolchain, and of course the compiler for your desired language (if it isn't C++). You will also need to copy ~/.gettc to that system.

This document is for new users. Existing users can find details about updating by reading the change log.

gettc's People

Contributors

seri avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.