Skip to content

Instantly share code, notes, and snippets.

View cshjin's full-sized avatar

Hongwei Jin cshjin

View GitHub Profile
#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;
@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
@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 / 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 / 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 / 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 / minimum_scalar_product.py
Created February 23, 2015 21:07
Code Jam Practice - Round 1A 2008
N = int(raw_input())
with open('outfile.txt', 'w') as outfile:
for test in range(N):
size = int(raw_input())
v1 = sorted(map(int, raw_input().split(" ")), reverse=True)
v2 = sorted(map(int, raw_input().split(" ")))
pro = 0
for i in range(size):
pro += v1[i] * v2[i]
outfile.write("Case #{}: ".format(test + 1) + str(pro) + "\n")
@cshjin
cshjin / Makefile
Created March 18, 2015 22:26
C Based Server TCP demo
all: webserver
webserver: webserver.o tcp.o request.o
gcc webserver.o tcp.o request.o -o webserver -g -lpthread
webserver.o: webserver.c
g cc -Wall -g -c webserver.c -o webserver.o
tcp.o: tcp.c tcp.h
gcc -Wall -g -c tcp.c -o tcp.o
@cshjin
cshjin / farmer_concrete.py
Created June 26, 2015 01:31
An example of using Coopr (Pymo) and PySP with ConcreteModel
# _________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2014 Sandia Corporation.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
# This software is distributed under the BSD License.
# _________________________________________________________________________
#
# Farmer: rent out version has a scalar root node var
@cshjin
cshjin / farmer_lp.py
Last active August 29, 2015 14:24
Pyomo solving Farmer's problem step by step improvement
# -*- coding: utf-8
"""
A deterministic model of farmer's problem:
"""
try:
from pyomo.core import *
from pyomo import *
from pyomo.opt import *
from pyomo.core.base import *