Page 1 of 1

Categorize Solutions for Different Languages

Posted: Tue Feb 16, 2010 8:49 am
by kataruna
Hey. When we find the answer to a problem we are allowed to see the forum for that particular problem where programmers have their solutions submitted in different programming languages. So, as you see the solutions are very untidy. When somebody wants to see other programmers' solutions in one particular programming language he has to search all over the posts. Why don't we categorize these solution posts for different programming languages with a drop down list for example, so when someone wants to see solutions in Delphi he can choose Delphi from the list and see solutions only in Delphi. What about that?

Re: Categorize Solutions for Different Languages

Posted: Wed Feb 17, 2010 10:15 am
by wrongrook
This sounds almost like a Project Euler challenge in itself :)

Here's my Python attempt (it's a bit dodgy as it won't always produce correctly formatted html):

Code: Select all

def forum(problem_id, username, password, lang):
    params = urllib.urlencode({'username': username, 'password': password, 'login':'Login'})
    page = urllib.urlopen('http://projecteuler.net/index.php?section=forum&id=%d&page=1' %problem_id, params).read()
    B = re.split('(<div class="forum_box)',page)
    fd=open('out.html','w')
    fd.write(B[0])
    for p in range(1,len(B),2):
        if re.search(lang,B[p+1]):
            fd.write(B[p]+B[p+1])
    fd.close()
If you run
forum(200,'myusername','mypassword','Python')
then it should save out an HTML file containing all the responses that include the word Python for problem 200 for the first forum page.

Note, of course, that you need to substitute your own name and password.