Last active
August 29, 2015 14:23
-
-
Save jinhwanlazy/ef9e5c352e54769c4d43 to your computer and use it in GitHub Desktop.
filter problems solved with python but not by me from algospot.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup as bs | |
from itertools import chain, filterfalse | |
langs = {'python': ['(py)', '(pypy)', '(py3)'], | |
'ruby': ['(rb)']} | |
def get_pids(maxpage=17): | |
""" gatter problem ids and return it one by one """ | |
baseurl = 'https://algospot.com/judge/problem/list/%d' | |
for pagenum in range(1, maxpage+1): | |
page = requests.get(baseurl % pagenum, timeout=None) | |
soup = bs(page.text) | |
tds = soup.find_all('td', class_='id') | |
for p in tds: | |
yield p.find('a').text.strip() | |
def solved_with(lang): | |
""" return a filter that checks if provided problem is ever solved with the | |
language or not | |
""" | |
if lang not in langs: | |
raise | |
target = langs[lang] | |
baseurl = 'https://algospot.com/judge/problem/stat/%(pid)s/%(page)d/' | |
def f(pid): | |
firstpage = requests.get(baseurl % {'pid': pid, 'page': 1}) | |
soup = bs(firstpage.text) | |
maxpage = soup.find('span', class_='step-links').find_all('a')[-1].text | |
for pagenum in range(1, int(maxpage)+1): | |
page = requests.get(baseurl % {'pid': pid, 'page': pagenum}) | |
soup = bs(page.text) | |
tds = chain(soup.find_all('td', class_='fastest'), | |
soup.find_all('td', class_='shortest')) | |
ans = ''.join(td.text for td in tds) | |
if any(t in ans for t in target): | |
return True | |
return False | |
return f | |
def solved_by(uid): | |
""" return a filter that checks if provided problem is ever solved by the | |
user or not. user is specified by user id, shown in his profile page url. | |
for example user fleo0917(https://algospot.com/user/profile/13227)'s user | |
id is '13227' | |
""" | |
solved = set() | |
baseurl = 'https://algospot.com/judge/problem/list/%(page)d?verdict=solved&user_tried=%(uid)s' | |
firstpage = requests.get(baseurl % {'uid': uid, 'page': 1}) | |
soup = bs(firstpage.text) | |
maxpage = soup.find('span', class_='step-links').find_all('a')[-1].text | |
for pagenum in range(1, int(maxpage)+1): | |
page = requests.get(baseurl % {'uid': uid, 'page': pagenum}) | |
soup = bs(page.text) | |
tds = soup.find_all('td', class_='id') | |
for p in tds: | |
solved.add(p.find('a').text.strip()) | |
def f(pid): | |
return pid in solved | |
return f | |
def gen_url(pid): | |
""" return problem definition url """ | |
return 'https://algospot.com/judge/problem/read/%s' % pid | |
if __name__ == '__main__': | |
probs = get_pids() | |
probs = filter(solved_with('python'), probs) | |
probs = filterfalse(solved_by('13227'), probs) | |
for p in probs: | |
print('[%s](%s)' % (p, gen_url(p))) |
ANOTHERRPS
AUTOPRODUCTION
BADUK
BALLPAINTING
BASEBALL
BILLS
BOOKSTORE
BRACKETS
BST
CCR
CIV5
CODERS
CONCERT
DECUAL
DIAMOND
DICT
DICTIONARY
DIVIS
ELECT
FLAPPY
GALLERY
GREEDYAINTA
GRIDISLANDS
JAEHACHERRY
KAKAO24K
KAKURO1
LAN
LOTTERYGAMES
MAXTACK
MINE
MONKEY
MVP
NECKLACE
NORMDIST
NPOLY
OCR
ORDERING
ORIVIRUS
PASS486
PCOMPLETE
PROGRAMPAINTER
RECAPTCHA
REPEATLESS
SHISENSHO
SOLONG
SORTGAME
TRIANGLE2
UBW
WORDCHAIN
XORNECKLACE
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ALLERGY
ANNIETIBBER
ANOTHERRPS
ARCTIC
AUTOPRODUCTION
BADUK
BALLPAINTING
BASEBALL
BILLS
BOOKSTORE
BRACKETS
BRAVEDUCK
BST
CCR
CHRISTMAS
CIV5
CODERS
CONCERT
DARPA
DECODE
DIAMOND
DICT
DICTIONARY
DIVIS
DOMINO
ELECT
ENCODING
FLAPPY
FORTRESS
GALLERY
GGGCCCDDD
GOODSET
GREEDYAINTA
GRID
GRIDISLANDS
INSERTION
JAEHACHERRY
JEONGLIBE
JOSEPHUS
KAKAO24K
KAKURO1
KOOGLE
KWPATTERN
LOAN
LOTTERYGAMES
LUCKYNUM
MAGICPOWER
MAXTACK
MINE
MONKEY
MOON
MVP
NECKLACE
NORMDIST
NOTE
NPOLY
NQUEEN
OCR
ORDERING
ORIVIRUS
PALINDROMIZE
PASS486
PCOMPLETE
PDNA
PINBALL
POPOWERWER
POTION
PROGRAMPAINTER
RECAPTCHA
REPEATLESS
SHISENSHO
SOLONG
SORTGAME
TRAVERSAL
TREASURE
TRIANGLE2
UBW
WITHDRAWAL
WORDCHAIN
XORNECKLACE