加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

计算一个图形中的三角形数目

发布时间:2020-05-24 23:27:05 所属栏目:Python 来源:互联网
导读:计算一个图形中的三角形数目

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

#!/usr/bin/python

"""
---------------------------------------------------------------------------------------------------
2015.07.23  Grey
***************************************************************************************************
Counter all the triangles in a picture
---------------------------------------------------------------------------------------------------
"""

import itertools,string

def CounterTriangle():
	print "All the triangles we can find in the picture are as follows:"
	triangle_number    = 0
	sides_match_list   = ['abh','acgi','adfj','aek','bcde','efgh','hijk']
	dot_list           = []
	i = 0
	while i < 26:
		dot_list.append(string.lowercase[i])
		if string.lowercase[i] == 'k':
			break
		else:
			i += 1
	for each_combination in itertools.combinations(dot_list,3):
		triangle_flag = True
		for 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 = True
					break
				else:
					triangle_flag = False
			else:
				triangle_flag = False
				break
		line_flag = False
		for 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 = True
		if triangle_flag == True and line_flag == False:
			triangle_number += 1
			print "%d : %s" % (triangle_number,each_combination)
	print "The number of triangles in the picture is : %d" % triangle_number

CounterTriangle()
		

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读