Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion challenges/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def write_contests(contests, contest_type):
click.secho("%-3s" % str(index+1), nl=False, bold=True)
click.secho(" %-50s" %
contest_name, nl=False, fg=colors().CONTEST_NAME, bold=True)
click.secho(" %-20s" % time_diff_string, nl=False, fg=colors().TIME_TO_START, bold=True)
if 'start' in contest:
click.secho(" %-20s" % time_diff_string, nl=False, fg=colors().TIME_TO_START, bold=True)
else:
click.secho(" %-20s" % time_diff_string, nl=False, fg=colors().TIME_LEFT, bold=True)
click.secho(" %-11s" %
str(contest["duration"]), nl=False, bold=True)
click.secho(" %-15s" % contest["host_name"], fg=colors().HOST, bold=True)
Expand Down
37 changes: 37 additions & 0 deletions codechef/Codes/DOMSOL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*All submissions for this problem are available. In Domino Solitaire, you have a grid with two rows and N columns. Each square in the grid contains an integer A. You are given a supply of rectangular 2 × 1 tiles, each of which exactly covers two adjacent squares of the grid. You have to place tiles to cover all the squares in the grid such that each tile covers two squares and no pair of tiles overlap. The score for a tile is the difference between the bigger and the smaller number that are covered by the tile. The aim of the game is to maximize the sum of the scores of all the tiles.  Here is an example of a grid, along with two different tilings and their scores.The score for Tiling 1 is 12 = (9 − 8) + (6 − 2) + (7 − 1) + (3 − 2) while the score for Tiling 2 is 6 = (8 − 6) + (9 − 7) + (3 − 2) + (2 − 1). There are other tilings possible for this grid, but you can check that Tiling 1 has the maximum score among all tilings. Your task is to read the grid of numbers and compute the maximum score that can be achieved by any tiling of the grid. Your task is to read the grid of numbers and compute the maximum score that can be achieved by any tiling of the grid. Input The first line contains one integer N, the number of columns in the grid. This is followed by 2 lines describing the grid. Each of these lines consists of N integers, separated by blanks.   Output A single integer indicating the maximum score that can be achieved by any tiling of the given grid. Constraints 1 ≤ N ≤ 10 5 1 ≤ A ≤ 10 4   Example Input: 4 8 6 2 3 9 7 1 2 Output: 12 */
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main()
{
return 0;
}
42 changes: 42 additions & 0 deletions codechef/Template/default.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline void inp(auto &n){n=0; char x; while((x=getchar_unlocked())>='0' && x <= '9') n = 10*n + x - '0'; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main()
{
long n=12;
int a=11;
inp(n);
inp(a);
printf("\n%ld\n%d\n",n,a);
return 0;
}
189 changes: 189 additions & 0 deletions codechef/codechef-cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
from robobrowser import RoboBrowser
from bs4 import BeautifulSoup
import getpass,os,click
from operator import itemgetter
import HTMLParser
h= HTMLParser.HTMLParser()

login_url = 'http://codechef.com'



def inPre(s):
try:
s = s.split('<pre>')[1].split('</pre>')[0]
except:
s = s.split('<b>')[1].split('</b>')[0]
return s
def getQuesFromList(directory):
browser.open(login_url+directory)
#probs = browser.find_all(class_='problemname')
z=1
#print type(browser.find_all(class_='problemname', href=True))
subAccRMS = 0
probs = browser.find_all(class_='problemrow')
sm = 0
formattedProbs = []

for i in probs:
s=getInner(str(i))
s.append(float(s[2])*float(s[3]))
formattedProbs.append(s)

formattedProbs = sorted(formattedProbs, key=itemgetter(4),)

click.secho("%-5s" % ("#") ,nl=False, bold=True)
click.secho("%-20s" % ("Code") ,nl=False, bold=True)
click.secho("%-55s" % ("Name"), nl=False, bold=True)
click.secho("%-30s" % ("Successful Submissions"), nl=False, bold=True)
click.secho("%-20s" % ("Accuracy"), nl=False ,bold=True)
click.secho("%-20s" % ("Accuracy X Successful Submissions"), fg="white" ,bold=True)
click.echo()
n = len(formattedProbs)
for i in formattedProbs:
name,short,submissions,accuracy,subAcc = i
color = 'red'
# if float(accuracy) * float(submissions) > subAccMedian:
# color = 'yellow'
# if float(accuracy) * float(submissions) > subAccMedian/2:
# color = 'green'
click.secho("%-5s" % (n) ,nl=False, bold=True)
click.secho("%-20s" % (short) ,nl=False, bold=True)
click.secho("%-55s" % (name), nl=False, bold=True)
click.secho("%-30s" % (submissions), nl=False, bold=True)
click.secho("%-20s" % (accuracy), nl=False ,bold=True)
click.secho("%-20s" % (subAcc), fg=color ,bold=True)
n-=1
return formattedProbs


def getQues(ques,tries):
if(tries==2):
return ""
browser.open("https://www.codechef.com/problems/" + ques)
z = browser.find_all(class_="content")
if(len(z)>=3):
return str(browser.parsed)," ".join(getInner(str(z[3]))).replace("&lt;","<").replace("&gt;",">")
else:
return getQues(ques,tries+1)

def openShell():
os.system("bash")
def getTemplate():
f = open('Template/default.cpp','r')
return f.read()

def getInner(s):
a=[]
x=""
i=0
flag=0
while i<len(s):
if s[i] == '<':
if x!="" and x!="\n":
a.append(x)
x=""
flag+=1
elif s[i] == '>':
flag-=1
elif flag==0 and s[i]!="\n":
x+=s[i]
i+=1
if x!="" and x!="\n":
a.append(x)
return a

practiceLink = {}

practiceLink[1] = "/problems/school"
practiceLink[2] = "/problems/easy"
practiceLink[3] = "/problems/medium"
practiceLink[4] = "/problems/hard"

def getPractice():
while(1):
print "1. Beginner"
print "2. Easy"
print "3. Medium"
print "4. Hard"
print "5. Shell"
print "99. Back"
option = input()
if option != 99:
qarr = getQuesFromList(practiceLink[int(option)])
while 1:
print "To select question, enter ques code to view '99' to go back or '#' to go to shell, 'vi filename' to load in vim"
option = raw_input()
if(option=='99'):
break
elif(option=='#'):
os.system('bash')
elif(option.split()[0]=='vi'):
raw,quesStr = getQues(option.split('.')[0].split()[1],0)
os.system("echo \"/*" + quesStr + "*/ \\n" + getTemplate() +"\" > Codes/" + option.split()[1])
try:
os.system("echo \"" + inPre(raw.split('Input')[1].split('Output')[0]) + "\" > Codes/" + option.split()[1].split('.')[0] + ".in")
os.system("echo \"" + inPre(raw.split('Output')[1].split('Author:')[0]) + "\" > Codes/" + option.split()[1].split('.')[0] + ".out")
except:
pass
os.system('vi Codes/' + option.split()[1])
elif(option.split()[0]=="run"):
os.system("echo Sample Input : ")
os.system("cat "+option.split()[1]+".in")
os.system("echo Sample Output : ")
os.system("cat "+option.split()[1]+".out")
os.system("g++ -o "+option.split()[1]+" option.split()[1]"+".cpp")
os.system("./"+option.split()[1])
try:
qu = getQues(option,0)
click.secho(qu,bold=True)
except:
pass
elif(option==2):
pass
elif(option==3):
pass
elif(option==4):
pass
elif(option==5):
openShell()
else:
return

browser = RoboBrowser(parser="lxml")
browser.open(login_url)



form = browser.get_form(id='new-login-form')

x = raw_input("Login? (y/n)")
if(x=='y'):
form['name'].value = raw_input("Please enter username : ")
form['pass'].value = getpass.getpass("Please enter password : ")
browser.submit_form(form)
#Logged in

user = browser.find(class_='right')

print " ".join(user.text.split('Account')[0].replace('\n','').split())

while 1:
print "1. Practice"
print "2. Contests"
print "3. Shell"
print "4. Show question from question code"
print "99. Logout"
option = input()
if(option==1):
getPractice()
elif(option==2):
getContests()
elif(option==3):
openShell()
elif(option==4):
getQues(raw_input("Input question code"))
else:
exit()