Skip to content

Instantly share code, notes, and snippets.

View cshjin's full-sized avatar

Hongwei Jin cshjin

View GitHub Profile
@cshjin
cshjin / reverse_words.py
Last active August 29, 2015 14:16
Code Jam practice - Qualification Round Africa 2010
N = int(raw_input())
with open('outfile.txt', 'w') as outfile:
for test in range(N):
words = raw_input().strip().split(" ")
outfile.write("Case #{}: ".format(test + 1) + " ".join(words[::-1]) + "\n")
@cshjin
cshjin / clockdegree.py
Created January 28, 2015 21:18
Creaking the Coding Interview
def solution(h, m):
""" Return the degree bewteen hour hand and minute hand
"""
min_deg = float(m) / 60 * 360
hour_deg = float(h) / 12 * 360 + float(m) / 60 * 360 / 12
return min(abs(min_deg - hour_deg), 360 - abs(min_deg - hour_deg))
@cshjin
cshjin / rand7.py
Last active August 29, 2015 14:14
Temp solutions to theReq problems solving in Python
# If you have access to a function that returns a random integer from one to five,
# write another function which returns a random integer from one to seven.
import random
class Solution():
def rand5(self):
return random.randint(1, 5)
@cshjin
cshjin / IIT_ONLINE.py
Created August 5, 2014 23:22
This is the processing file to get online courses of IIT(Illinois Institution of Technology),
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 28 10:28:18 2013
@author: King
"""
import httplib
import urllib2
@cshjin
cshjin / farmer1.dat
Created April 18, 2014 17:15
AMPL learning
data;
set Crops := wheat corn beets;
param TotalArea:=500;
param BeetsQuota:=6000;
param Yield :=
wheat 2.5
corn 3.0
beets 20.0;
param MinRequirement :=
wheat 200
#include <stdio.h>
int main()
{
int a = 5, b = 7;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("a=%d b=%d", a, b);
return 0;