Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the calculation method of Card Triangle

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to realize the card triangle calculation method". In the daily operation, I believe that many people have doubts about how to realize the card triangle calculation method. The editor consulted all kinds of data and sorted out a simple and easy-to-use operation method. I hope it will be helpful for you to answer the doubts about "how to realize the card triangle calculation method"! Next, please follow the editor to study!

Problem description

Nine cards are arranged into a regular triangle (An is calculated as 1). The sum of each side is required to be equal.

The following figure shows an arrangement (see p1.png if you have alignment problems).

A

9 6

4 8

37 5 2

There may be many such arrangements.

If you consider the same kind of rotation and mirror image, how many different arrangements are there?

Benben has something to say:

It feels like it can be cracked violently.

The trouble is that for each arrangement, we have to calculate its rotation and mirror image arrangement to see if it is repeated with history.

Crooked has something to say:

You are not allowed to print out everything, just to count the types.

For each basic situation, isn't there a fixed number of new situations that can be created through rotation and mirroring?

Solution

Through for this question, the more important point is to do a full arrangement of the given data, how to do the full arrangement, it is necessary to use itertools, an iterator for efficient loops, but this problem only involves a simple application, so it is only a simple learning of a small part of the knowledge of the iterator, more can not be done, this question uses the use of permutations (), this operation will get all possible sorting There are no duplicate elements. After that, we use the if condition to judge whether all the numbers marked in advance satisfy the corresponding knowledge of equilateral triangles, because there are three cases of rotation and two kinds of mirrors, so we can get the final answer by dividing the results by 6.

Import itertools

A = [1,2,3,4,5,6,7,8,9]

Res = 0

For i in itertools.permutations (a, 9): # iterate through the list an and get the full permutation result with itertools

W = list (I)

If w [0] + w [1] + w [2] + w [3] = = w [3] + w [4] + w [5] + w [6] = = w [6] + w [7] + w [8] + w [0]:

Res + = 1

Print ('% d'% (res/6))

# iterator circulator, itertools.permutations is to return all the mathematical permutations of iterable objects.

At this point, the study of "how to realize the calculation of card triangles" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report