当前位置:网站首页>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 .
边栏推荐
- Household enterprises use WMS warehouse management system. What are the changes
- You can command Siri without making a sound! The Chinese team of Cornell University developed the silent language recognition necklace. Chinese and English are OK
- Important reference indicators for data center disaster recovery: RTO and RPO
- I3wm get window class
- js模块化
- JS modularization
- Teach you how to use the harmonyos local simulator
- Encapsulating ranging and surface class based on leaflet
- Request&Response
- Jemter 压力测试 -基础请求-【教学篇】
猜你喜欢

Redis(4)----浅谈整数集合
![[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

How to design API return codes (error codes)?

How to convert Unicode into Chinese characters in Excel

多传感器融合感知

C implementation adds a progress bar display effect to the specified column of the GridView table in devaxpress - code implementation method

Jemter 压力测试 -可视化工具支持-【安装篇】

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

Solve psycopg2 NotSupportedError: PQconninfo not available in libpq < 9.3

Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp
随机推荐
Systemctl PHP configuration file
Jemter stress test - basic requirements - [teaching]
Junit
Oracle creates stored procedures with return values and executes SQL calls
Exploration and practice of incremental data Lake in station B
Minor problems in importing D
Nine hours, nine people and nine doors (01 backpack deformation) - Niuke
[SystemVerilog basics] post_ Randomize function record
卡尔曼滤波器_Recursive Processing
Open a file at line with'filename:line'syntax - open a file at line with'filename:line' syntax
js模块化
Is it legal to open an account for compass stock trading software? Is it safe?
Kalman filter_ Recursive Processing
PyTorch-12 GAN、WGAN
Request&Response
Liangshui Xianmu shows his personal awareness as a unity3d worker
Attention mechanism yyds, AI editor finally bid farewell to P and destroyed the whole picture
Jemter 压力测试 -基础请求-【教学篇】
Basic use of swiperefreshlayout, local refresh of flutterprovider
What is the five levels of cultivation of MES management system