用python完成计算一个图形中三角形数目,python三角形,用python完成计算一
用python完成计算一个图形中三角形数目,python三角形,用python完成计算一
用python完成计算一个图形中三角形数目,微信朋友圈的一个游戏,数三角形的数目。自己用Python了一个小程序来处理了一下,简介写在了这儿。1.[文件] triangle_counter.py~2KB
#!/usr/bin/python"""---------------------------------------------------------------------------------------------------2015.07.23 Grey www.iplaypy.com***************************************************************************************************Counter all the triangles in a picture---------------------------------------------------------------------------------------------------"""import itertools,stringdef CounterTriangle():print "All the triangles we can find in the picture are as follows:"triangle_number = 0sides_match_list = ['abh','acgi','adfj','aek','bcde','efgh','hijk']dot_list = []i = 0while i < 26:dot_list.append(string.lowercase[i])if string.lowercase[i] == 'k':breakelse:i += 1for each_combination in itertools.combinations(dot_list,3):triangle_flag = Truefor each_dot_combination in itertools.combinations(each_combination,2):for each_side in sides_match_list:if each_dot_combination[0] in each_side and each_dot_combination[1] in each_side:triangle_flag = Truebreakelse:triangle_flag = Falseelse:triangle_flag = Falsebreakline_flag = Falsefor each_side in sides_match_list:if each_combination[0] in each_side and each_combination[1] in each_side and each_combination[2] in each_side:line_flag = Trueif triangle_flag == True and line_flag == False:triangle_number += 1print "%d : %s" % (triangle_number,each_combination)print "The number of triangles in the picture is : %d" % triangle_numberCounterTriangle()
2.[图片] triangle.jpg
编橙之家文章,
相关内容
- python 狂人TD1.5 krtd1.5积分代码破解教程,td1.5krtd1.5,pyt
- python撞库操作的实战脚本源代码,python实战,python撞库是
- 使用python等差数列求和问题教程,python等差数列,使用
- python实现同行内容匹配输出功能,python同行,python实现同
- 利用python抓取返利网 商品信息,python抓取,<利用p
- Python抓取保存cookies用于模拟登录教程,pythoncookies,<
- 人生的第一条Python语句 测试hello world,pythonhello,<人生
- 一行Python代码 输出99乘法表格,python乘法,<一行Pyth
- 今天用python实现坐标点生成shp图斑教程,pythonshp,今天来
- python邮件收发之密送带附件源码,python邮件收发,pytho
评论关闭