当前位置:网站首页>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 .
边栏推荐
- Error reported by using two-dimensional array [[]] in thymeleaf: could not parse as expression
- Take you three minutes to get started typescript
- [industry cloud talk live room] tomorrow afternoon! Focus on digital intelligence transformation of the park
- js模块化
- Systemctl PHP configuration file
- Exit of shell internal value command
- My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?
- Tsinghua Yaoban chendanqi won Sloan award! He is a classmate with last year's winner Ma Tengyu. His doctoral thesis is one of the hottest in the past decade
- Jemter 压力测试 -可视化工具-【使用篇】
- Kalman filter_ Recursive Processing
猜你喜欢

How to design API return codes (error codes)?

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
![Jemter stress test - visualization tool support - [installation]](/img/e9/9acda4e37c98cc21df9499684205c6.png)
Jemter stress test - visualization tool support - [installation]

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

Calculate division in Oracle - solve the error report when the divisor is zero

Google Earth Engine(GEE) 02-基本了解和学习资源
![[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system](/img/4d/01310b489ca6a599a125e849ae4856.jpg)
[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system
![[UVM basics] understanding of sequence and sequencer](/img/74/ff451e500d0b7154d7bb95398eaef0.jpg)
[UVM basics] understanding of sequence and sequencer
![JMeter stress test web agent local interface test [teaching]](/img/6d/a8b3cd1ca55993fe59c066f95ef093.png)
JMeter stress test web agent local interface test [teaching]

Deeply analyze storage costs and find cost reduction solutions
随机推荐
数据中心灾难恢复的重要参考指标:RTO和RPO
MySQL storage and custom functions
Yyds dry inventory executor package (executor function)
Qt基础教程:QString
ES cluster_ block_ exception read_ only_ allow_ Delete question
The "big grievances" in the workplace are not only physically tired, but also mentally emptied
Redis (4) -- Talking about integer set
Error reported by using two-dimensional array [[]] in thymeleaf: could not parse as expression
Exit of shell internal value command
Liangshui Xianmu shows his personal awareness as a unity3d worker
Summary of domestic database examination data (continuously updated)
技术分享 | MySQL:caching_sha2_password 快速问答
MXNet对NIN网络中的网络的实现
ReW_p
[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system
Calculate division in Oracle - solve the error report when the divisor is zero
What are the key points of turnover box management in warehouse management
Exploration and practice of incremental data Lake in station B
The difference between insert ignore and insert into
[UVM basics] connect of UVM_ Phase execution sequence