Source

wd_pys60 / baiduExam.py

Full commit
# -*- coding: utf-8 -*-
__author__="weakdancer@gmail.com"

import sys
sys.setdefaultencoding("utf8")

NUM=15
def apply(li):
    res=0
    for i in li:
        res+=i
    return res

answer=[]
for i in range(1,NUM):
    res=0
    for j in range(i,NUM):
        res+=j
        if res==NUM:
            answer.append(range(i,j+1))
        elif res>NUM:
            break
#print answer
for a in answer:
    print "+".join([str(s) for s in a]),"=",apply(a)