TopCoder offline arena supporting multiple languages
Gettc 2.0 has shipped with a fix for the authentication bug. Enjoy!
Download a TopCoder problem, parse the examples and system tests, then finally generate a naive solution for the following languages:
And support for more languages is just around the corner.
You can email me to request support for your favourite language. I will prioritize development on the most requested ones.
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.
$ [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:
DigitHoles was used for Single Round Match 483 Round 1 - Division II, Level One.
All done. Start solving with:
$ cd DigitHoles/solve/<your_language>
$ make demo
Now:
$ cd DigitHoles/solve/cpp
$ make demo
Output:
[gettc] Compile solver
[gettc] Compile checker
[gettc] Run test cases
Case 0 ... 2ms Failed
Input: <42>
Expected: <1>
Received: <0>
Case 1 ... 1ms Failed
Input: <669>
Expected: <3>
Received: <0>
Case 2 ... 1ms Failed
Input: <688>
Expected: <5>
Received: <0>
Case 3 ... 1ms Passed
Case 4 ... 1ms Failed
Input: <456>
Expected: <2>
Received: <0>
Case 5 ... 1ms Failed
Input: <789>
Expected: <3>
Received: <0>
[gettc] Summary
6 cases checked, 5 failures, 0 errors
Failures: 0, 1, 2, 4, 5
Total time taken: 7 ms
Average time taken: 1 ms
Slowest running case: 2 ms (case 0)
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:
class DigitHoles {
public:
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:
[gettc] Compile solver
[gettc] Compile checker
[gettc] Run test cases
Case 0 ... 2ms Passed
Case 1 ... 1ms Passed
Case 2 ... 1ms Passed
Case 3 ... 1ms Passed
Case 4 ... 1ms Passed
Case 5 ... 2ms Passed
[gettc] Summary
6 cases checked, 0 failures, 0 errors
Total time taken: 8 ms
Average time taken: 1 ms
Slowest running case: 2 ms (case 0)
Good. We have passed all the example tests. Why not challenge the system tests while we are it?
$ make sys
Output:
[gettc] Compile solver
[gettc] Compile checker
[gettc] Run test cases
[gettc] Summary
131 cases checked, 0 failures, 0 errors
Total time taken: 233 ms
Average time taken: 1 ms
Slowest running case: 7 ms (case 2)
Congratulations! You have solved a TopCoder problem like a boss!
Gettc works on most operating systems, including Linux, Windows, and Mac OS.
The following packages are hard dependencies:
If you have problems installing on Windows, this may help: https://www.quora.com/How-do-I-install-gettc-for-downloading-TopCoder-problems/answer/Rajneesh-Chauhan
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. Just run this for a help message:
$ gettc
Now there are a couple things you need to get depending on your desired language.
If you encounter a "too many requests" error, consider changing to a new account
in ~/.gettc/config.yml
.
I remember having encountered a problem where gettc failed to download the system tests while it is in fact possible to get the system tests. However, I forgot the problem ID. If you meet such problems, please file an issue so I can fix this.
There are a few problems that allow multiple answers (such as CorruptedMessage). Gettc cannot deal with this because it can only extract the single answer that TopCoder shows. If you meet such problems, a good guess is to always return the smallest possible value.
~/.gettc/config.yml
.rm -rf build
after you're done solving to save some disk space.~/.gettc
to, say, remove things
you don't want to be generated. If you mess up, run gettc reset
.~/.gettc
to that system.This document is for new users. Existing users can find details about updating by reading the change log.