Reference

https://www.shuxuele.com/combinatorics/combinations-permutations.html

Online Tool

https://gadget.chienwen.net/x/math/percomb

Cracking the Safe!

假设你要暴力破解一个保险箱,密码只有4位,每位有0-9个可能,请思考怎么破解呢?

这个密码排列的特征是:

  • 次序重要
  • 可重复

那么就选重复排列方式计算即可。

Code:

import itertools

product_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
product = list(itertools.product(product_list, repeat=4))
print("product number :", len(product))
print("product list: ", product) # out:
product number : 10000
product list: [(1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 1, 3), (1, 1, 1, 4) ... ]

计算比赛前三名有多少种排列方式?

有一场比赛,分别有A,B,C,D,E,F,G,H共8支队伍参加,现在想算到时得前三名的排列情况有多少种?

这个名次排列的特征:

  • 次序重要
  • 不可以重复

那么就选不重复排列方式计算即可。

from itertools import permutations

itering = permutations(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], 3)
plist = list(itering)
print("前三名的排列有多少种: ", len(plist))
print("permutations list: ", plist) # 前三名的排列有多少种: 336
# permutations list: [('A', 'B', 'C'), ('A', 'B', 'D'), ('A', 'B', 'E'), ('A', 'B', 'F'), ... ]

Can you win the lottery?

假设彩票的玩法是从编号为01~33个球中随机抽出6个,顺序不重要。你选6个数组合成一注彩票,如果所选的6个号码都中了,就表示你中了1等奖。

那么有多少种组合情况?

这个中奖号码组合的特征:

  • 次序不重要
  • 不可重复

用不可重复组合求即可。

from itertools import combinations, permutations
from scipy.special import comb, perm C = comb(33, 6)
# out: C = 3.0
print("combinations number: ", C) itering = combinations(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33], 6)
Clist = list(itering)
with open('temp.txt', 'w') as f:
for i in Clist:
f.writelines(str(i) + "\r")
# out:
combinations number: 1107568.0

out:

如何做仙丹?

假设有个神仙要你用5种材料('人参', '萝卜', '火龙果', '鹿茸', '熊掌')做一个仙丹,需要按照特定的配方,但是配方不告诉你,只告诉你做的规则,顺序无所谓,可以有重复,正确的只有一种配方。

你知道你要尝试多少次才能做出仙丹?

这个配方组合的特征:

  • 次序不重要
  • 可重复

用重复组合求即可。

c_list = ['人参', '萝卜', '火龙果', '鹿茸', '熊掌']
clist = list(itertools.combinations_with_replacement(c_list, 3)) print("一共有多少种组合: ", len(clist))
print("List: ", clist) #out:
一共有多少种组合: 35
List: [('人参', '人参', '人参'), ('人参', '人参', '萝卜'), ('人参', '人参', '火龙果'), ('人参', '人参', '鹿茸'), ('人参', '人参', '熊掌')...]

Think

Do you know any other application scenarios?

TODO

Permutation Concept

TODO

Combination Concept

TODO

Application of Permutation and Combination的更多相关文章

  1. Leetcode 46 47 Permutation, 77 combination

    Permutation class Solution { List<List<Integer>> res = new ArrayList<List<Integer& ...

  2. Multiplexing SDIO Devices Using MAX II or CoolRunner-II CPLD

    XAPP906 Supporting Multiple SD Devices with CoolRunner-II CPLDs There has been an increasing demand ...

  3. DDD:小议 BoundexContext 设计

    背景 看了这篇文章:Coding for Domain-Driven Design: Tips for Data-Focused Devs,对 BoundedContext 的设计有了一点新的体会,记 ...

  4. keybd_event函数用法

    转自不用winio,直接达到驱动级模拟键盘效果的keybd_event函数用法 键盘模拟技术是在编写游戏外挂时经常使用的技术.但是由于很多游戏采用了directinput的方式,使得发送的一般键盘消息 ...

  5. Ruby数组方法整理

    数组方法整理 方法列表: all().any().none()和one():测试数组中的所有或部分元素是否满足给定条件.条件可以是语句块中决定,也可以是参数决定 append():等价于push() ...

  6. 算法题思路总结和leecode继续历程

    2018-05-03 刷了牛客网的题目:总结思路(总的思路跟数学一样就是化简和转化) 具体启发点: 1.对数据进行预处理排序的思想:比如8皇后问题 2.对一个数组元素进行比较的操作,如果复杂,可以试试 ...

  7. [Windows Azure] Windows Azure Execution Models

    Windows Azure Execution Models Windows Azure provides different execution models for running applica ...

  8. 【读书笔记】《Computer Organization and Design: The Hardware/Software Interface》(1)

    笔记前言: <Computer Organization and Design: The Hardware/Software Interface>,中文译名,<计算机组成与设计:硬件 ...

  9. Method, apparatus, and system for speculative abort control mechanisms

    An apparatus and method is described herein for providing robust speculative code section abort cont ...

  10. 自然语言处理(NLP) - 数学基础(1) - 排列组合

    正如我在<自然语言处理(NLP) - 数学基础(1) - 总述>一文中所提到的NLP所关联的概率论(Probability Theory)知识点是如此的多, 饭只能一口一口地吃了, 我们先 ...

随机推荐

  1. requests发送post请求

    post请求 语法结构 requests.post(url,data = None,json = None) 参数说明 url:需要爬取的网站的网址 data:请求数据 json:json格式的数据 ...

  2. 在windows系统中设置MySQL数据库

    MySQL搭建 效果图 step1:下载安装包 https://downloads.mysql.com/archives/community/ step2:解压后即完成安装 step3:创建 my.i ...

  3. vue指令之属性指令

    目录 属性指令 示例 属性指令 标签上的属性可以绑定变量,变量变化,属性也会变化 # 什么是属性?比如: href/src/name/value/class/style... 语法: v-bind:属 ...

  4. [Linux]CentOS查看RPM包依赖问题

    [经典应用案例] 查看此文前,可先查看 此博文中:在安装软件过程中,如何解决的依赖组件问题? [数据库/Linux]CentOS7安装MySQL Percona版(RPM方式) : 2-1 依赖组件问 ...

  5. [Git/GitLab]使用SSH远程登录GitLab/GitHub

    1 前言 近日,换了台新电脑. 今日,正要更新(git pull)GitLab的源码时,在配置(用户名,邮箱,密码git config --global -l)完全无误的情况下,却报出如下错误: $ ...

  6. [架构]辨析: 高可用 | 集群 | 主从 | 负载均衡 | 反向代理 | 中间件 | 微服务 | 容器 | 云原生 | DevOps | ...

    词汇集 灾备 冷备份 双机热备份 异地容灾备份 云备份 灾难演练 磁盘阵列(RAID) 故障切换 心跳监测 高可用 集群 主从复制(Master-Slave) 多集群横向扩容(master-clust ...

  7. JSON.parse 函数 (JavaScript)

    将 JavaScript 对象表示法 (JSON) 字符串转换为对象. 语法 参数 返回值 异常 以下示例使用 JSON.parse 将 JSON 字符串转换成对象. var jsontext = ' ...

  8. 05-打包样式资源(编写webpack配置文件)

    /** * webpack.config.js webpack的配置文件 * 作用:指示 webpack 干哪些活(当你运行 webpack 指令时,会加载里面的配置) * * 所有构件工具都是基于n ...

  9. Git代码提交规范

    1. 引言 思想,因人而异,难以重复 写代码时,每个人的习惯是不一样的,所以,引入了代码规范,为了省力,引入了自动格式化代码工具,前端工程中比较典型的自动格式化代码工具如:Prettier · Opi ...

  10. MySql中执行计划如何来的——Optimizer Trace

    作者:京东物流 籍磊 1.前言 当谈到MySQL的执行计划时,会有很多同学想:"我就觉得使用其他的执行方案比EXPLAIN语句输出的方案强,凭什么优化器做的决定与我得不一样?".这 ...