Wednesday, December 21, 2011

How to download Topcoder problems for offline viewing

If you just want to download one single problem at a time for practice, the tool gettc is perfect for that. It takes the problem ID as input and can automatically download problem description and generate C++/Java templates. You can even run demo/system tests from within the terminal.

If you want to download multiple problems

  1. Install gettc

  2. Select your desired subset of problems from here and download the html files.

  3. Say list*.html saves the list of problems. The following steps extract the problem ID's from the html files.

    1. grep -o 'pm=[0-9]*' list*.html > tmp.txt 

    2. Edit tmp.txt using vim and keep only the problem ID's.

    3. cat tmp.txt | sort -u > list.txt 

    Now the file list.txt contains unique problem ID's.

  4. Download the problems from Topcoder using the following command.

  5. for num in `cat list.txt`; do gettc $num; done



To create an ebook for reading in Kindle

  1. Create a dir called 'tmp'

  2. Run the following command

  3. for dir in `ls`; do mkdir tmp/$dir; cp -a $dir/prob tmp/$dir/; done

  4. Change to tmp, and generate index.html using the following scripts
    echo "<ul>" > index.html
    find . | grep html | sort > tmplist.txt
    for file in `cat tmplist.txt`; do
      name=`echo $file | awk -F/ '{print $2}'`
      echo "<li><a href=\"$file\">$name</a></li>" >> index.html
    done
    echo "</ul>" >> index.html
    rm tmplist.txt

  5. Zip the directory 'tmp' and feed it to Calibre.

1 comment:

Vishal said...

Can u please tell this for windows also.

Visitors