Chinaunix首页 | 论坛 | 博客
  • 博客访问: 155158
  • 博文数量: 26
  • 博客积分: 1723
  • 博客等级: 上尉
  • 技术积分: 329
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-04 14:06
文章分类

全部博文(26)

文章存档

2016年(1)

2013年(5)

2011年(3)

2009年(6)

2008年(11)

分类: Python/Ruby

2013-07-01 15:34:06

1-9数字填入 使横 竖 斜 方向的 数字相加都得15


点击(此处)折叠或打开

  1. #!/usr/bin/env pythgon
  2. # -*- coding:utf-8 -*-

  3. import itertools

  4. TEST_DATA = 15
  5. BIAOZHENG    = range(1,10,1)

  6. def check_line(line_num=0):
  7.     temp_data = ready_return_array[line_num*3+0]+ready_return_array[line_num*3+1]+ready_return_array[line_num*3+2]
  8.     if temp_data != TEST_DATA:
  9.         return False
  10.     return True    
  11. def check_all_lines():
  12.     if check_line(0) and check_line(1) and check_line(2):
  13.         return True
  14.     else:
  15.         return False    




  16. def check_raw(raw_num=0):

  17.     temp_data = ready_return_array[raw_num]+ready_return_array[raw_num+3]+ready_return_array[raw_num+6]
  18.     if temp_data != TEST_DATA:
  19.         return False
  20.     return True    
  21.         
  22. def check_all_raws():
  23.     if check_raw(0) and check_raw(1) and check_raw(2):
  24.         return True
  25.     else:
  26.         return False    

  27. def check_bias():
  28.     temp_data = ready_return_array[0] + ready_return_array[4] + ready_return_array[8]
  29.     if temp_data != TEST_DATA:
  30.         return False
  31.     temp_data = ready_return_array[2]+ready_return_array[4]+ready_return_array[6]
  32.     if temp_data != TEST_DATA:
  33.         return False
  34.     return True




  35. LIST_NAME = r'E:\study\src\src\list.txt'



  36. # 2,9,4,7,5,3,6,1,8        
  37. if __name__ == '__main__':
  38.     # king(6,2)
  39.     temp_data = []
  40.     answer_question=[]
  41.     print BIAOZHENG
  42.     # handle = open(LIST_NAME,'w')
  43.     # temp = itertools.permutations(BIAOZHENG)
  44.     # temp_data = list(temp)
  45.     # handle.write(str(temp_data))
  46.     # handle.close()
  47.     temp = itertools.permutations(BIAOZHENG)
  48.     temp_data = list(temp)
  49.     print 'the len is =',len(temp_data)
  50.     for i in xrange(len(temp_data)):
  51.         # print temp_data[i]
  52.         ready_return_array = list(temp_data[i])
  53.         # print ready_return_array
  54.         if check_bias() and check_all_raws() and check_all_lines():
  55.             print ready_return_array
  56.             answer_question.append(ready_return_array)
  57.             # break
  58.         
  59.     print answer_question


点击(此处)折叠或打开

  1. #!/usr/bin/env pythgon
  2. # -*- coding:utf-8 -*-

  3. import itertools

  4. TEST_DATA = 15
  5. BIAOZHENG    = range(1,10,1)

  6. def check_line(line_num=0):
  7.     temp_data = ready_return_array[line_num*3+0]+ready_return_array[line_num*3+1]+ready_return_array[line_num*3+2]
  8.     if temp_data != TEST_DATA:
  9.         return False
  10.     return True    
  11. def check_all_lines():
  12.     if check_line(0) and check_line(1) and check_line(2):
  13.         return True
  14.     else:
  15.         return False    




  16. def check_raw(raw_num=0):

  17.     temp_data = ready_return_array[raw_num]+ready_return_array[raw_num+3]+ready_return_array[raw_num+6]
  18.     if temp_data != TEST_DATA:
  19.         return False
  20.     return True    
  21.         
  22. def check_all_raws():
  23.     if check_raw(0) and check_raw(1) and check_raw(2):
  24.         return True
  25.     else:
  26.         return False    

  27. def check_bias():
  28.     temp_data = ready_return_array[0] + ready_return_array[4] + ready_return_array[8]
  29.     if temp_data != TEST_DATA:
  30.         return False
  31.     temp_data = ready_return_array[2]+ready_return_array[4]+ready_return_array[6]
  32.     if temp_data != TEST_DATA:
  33.         return False
  34.     return True




  35. LIST_NAME = r'E:\study\src\src\list.txt'



  36. # 2,9,4,7,5,3,6,1,8        
  37. if __name__ == '__main__':
  38.     # king(6,2)
  39.     temp_data = []
  40.     answer_question=[]
  41.     print BIAOZHENG
  42.     # handle = open(LIST_NAME,'w')
  43.     # temp = itertools.permutations(BIAOZHENG)
  44.     # temp_data = list(temp)
  45.     # handle.write(str(temp_data))
  46.     # handle.close()
  47.     temp = itertools.permutations(BIAOZHENG)
  48.     temp_data = list(temp)
  49.     print 'the len is =',len(temp_data)
  50.     for i in xrange(len(temp_data)):
  51.         # print temp_data[i]
  52.         ready_return_array = list(temp_data[i])
  53.         # print ready_return_array
  54.         if check_bias() and check_all_raws() and check_all_lines():
  55.             print ready_return_array
  56.             answer_question.append(ready_return_array)
  57.             # break
  58.         
  59.     print answer_question

阅读(2809) | 评论(0) | 转发(0) |
0

上一篇:python 数字游戏

下一篇:python tab补全功能

给主人留下些什么吧!~~