当前位置:网站首页>Orderly arrangement
Orderly arrangement
2022-06-26 07:45:00 【Beauty of algorithm and programming】
introduction
In the process of learning mathematics , We sometimes encounter the problem of permutation and combination . Several elements are given in the title , Find out how many different combinations these elements can have . And now we use python Medium for A loop can produce results quickly , And output these combinations one by one .
problem
Yes 1,2,3,4 Four numbers find out how many different and non repeating three digits can be generated by four numbers ( It cannot contain 122,133 similar ), Output these three digits at the same time .
Method
First, take these numbers as a string , Reuse for Loop through the string , Three digit numbers are required to be nested three levels for loop ( Note that the indentation ), Reuse if Statement to determine whether a number is repeated . Finally, set a variable as a counter , Count the total number of combinations .
Experimental results and discussion
Through the experiment 、 Practice has proved that the proposed method is effective , Is able to solve the problem raised at the beginning .
Code list 1
| m='1234' n=0 for i in m: for j in m: for q in m: if (i!=j) and (j!=q) and (q!=i): n += 1 print(i,j,q) print(' Yes ',n,' individual ') |
Conclusion
For this orderly arrangement problem , Put forward for Loop nested method , Through the experiment , The method is proved to be effective . Because there are three nested loops , The running speed will decrease . And once there are too many elements to be combined , Need to nest more loops . In the future, we can explore other ways to solve this kind of permutation problem .
边栏推荐
- How to design API return codes (error codes)?
- Jemter stress test - visualization tool support - [installation]
- QT basics tutorial: qstring
- Redis(5)----浅谈压缩列表
- Junit
- Google Earth engine (GEE) 01- the prompt shortcut ctrl+space cannot be used
- C#/. Net phase VI 01C Foundation_ 02:vs2019 basic operations, excluding code files, smart tips, data types, differences between float and double, and differences between string and string
- Detailed explanation of the generate go file command of import in golang (absolute detail)
- 少年,你可知 Kotlin 协程最初的样子?
- 解决 psycopg2.NotSupportedError: PQconninfo not available in libpq < 9.3
猜你喜欢

The "big grievances" in the workplace are not only physically tired, but also mentally emptied

B站增量数据湖探索与实践

How MySQL implements the RC transaction isolation level

Solution to the problem of multi application routing using thinkphp6.0

Solution to the permission problem when NPM install -g serve reports an error

Okhttp3 source code explanation (IV) cache strategy, disadvantages of Android mixed development

Junit

Redis (4) -- Talking about integer set

Flutter (III) - master the usage of dart language in an article

Junit
随机推荐
Junit
My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?
Open a file at line with'filename:line'syntax - open a file at line with'filename:line' syntax
Is it safe for individuals to buy stocks with compass software? How to buy stocks
How to define a digital factory and what is the relationship with smart factory and industry 4.0
[UVM practice] Chapter 3: UVM Fundamentals (3) field automation mechanism
What is the five levels of cultivation of MES management system
[recommend an entity class conversion tool mapstruct, which is powerful and easy to use]
蓝桥杯嵌入式学习总结(新版)
Qt基础教程:QString
Xiaosha's counting (bit operation, Combinatorial Mathematics) - Niuke
ECE 9203/9023 analysis
Error: the specified LINQ expression contains a reference to a query associated with a different context
记一次开发 pgadmin 时执行 Building the Web Assets 遇到的依赖安装问题
Google Earth engine (GEE) 02 basic knowledge and learning resources
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
Basic use of swiperefreshlayout, local refresh of flutterprovider
A bold sounding and awesome operation - remake a Netflix
2021 project improvement
指南针炒股软件开户是合法的吗?安全吗