Skip to content

Instantly share code, notes, and snippets.

View liang456's full-sized avatar

James liang456

  • SJTU
  • Shanghai, China
View GitHub Profile
;; This is the missionaries & cannibals problem solved in Scheme.
;; The code is not as elegant as it could have been
;; (lacking recursion, in the spirit of Scheme, in many places).
;; It is also not very generic. Also does no optimization and
;; will apply search paths back and forth.
;; It works however, and should be relatively readable.
;; "https://class.coursera.org/aiplan-001/forum/thread?thread_id=164"
(use srfi-1)
@liang456
liang456 / dabblet.css
Created February 1, 2013 23:15
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@liang456
liang456 / dabblet.css
Created February 1, 2013 23:14
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@liang456
liang456 / sinaWeibo.py
Created October 31, 2012 22:15
This is the client code accessing the Sina weibo
This is the client code accessing the Sina weibo
http://inventwithpython.com/pygame/chapter3.html
@liang456
liang456 / reversi.py
Created October 31, 2012 13:52
This is a Reversi game from http://inventwithpython.com/chapter15.html, I have revised it so you can run it under python 2.7
# Reversi
# This is a Reversi game from http://inventwithpython.com/chapter15.html, I have revised it so you can run it under python 2.7.
# Enjoy it
import random
import sys
def drawBoard(board):
# This function prints out the board that it was passed. Returns None.
HLINE = ' +---+---+---+---+---+---+---+---+'
@liang456
liang456 / Bagels.py
Created October 31, 2012 12:28
This is a guess number game Bagels from http://inventwithpython.com/chapter11.html
import random
def getSecretNum(numDigits):
# Returns a string that is numDigits long, made up of unique random digits.
numbers = list(range(10))
random.shuffle(numbers)
secretNum = ''
for i in range(numDigits):
secretNum += str(numbers[i])
return secretNum
# Tic Tac Toe
import random
def drawBoard(board):
# This function prints out the board that it was passed.
# "board" is a list of 10 strings representing the board (ignore index 0)
print(' | |')
print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])
import random
HANGMANPICS = ['''
+---+
| |
|
|
|
|
=========''', '''
@liang456
liang456 / PermandComp.py
Created October 29, 2012 20:31
Permutation and Composition Algorithm using Iterator in Python
def PermutationEnumerator(items, n=None):
if n is None:
n = len(items)
for i in range(len(items)):
v = items[i:i+1]
if n == 1:
yield v
else:
rest = items[:i] + items[i+1:]
for p in PermutationEnumerator(rest, n-1):