博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python codes
阅读量:5057 次
发布时间:2019-06-12

本文共 646 字,大约阅读时间需要 2 分钟。

Vertification of an assignment from Stochastic Processing. Using Brute Force and "itertools" library.

import itertoolsdim = 100m = list(range(1, dim+1))w = list(range(-1, -dim-1, -1))num = 0global zero_numzero_num = 0m_all = list(itertools.permutations(m,dim))w_all = list(itertools.permutations(w,dim))num = len(m_all) * len(w_all)for m in m_all:    for w in w_all:        for i in range(dim):            if m[i] + w[i] == 0:                zero_num += 1                breakprint(zero_num)print(num)print((num-zero_num)/num)

 As dim goes to infinity, the final ratio should be approaching to 1/e.

 

转载于:https://www.cnblogs.com/devai/p/4837425.html

你可能感兴趣的文章
hdoj 1846 Brave Game(巴什博弈)
查看>>
Round #345 B. Beautiful Paintings(Div.2)
查看>>
51nod 1018排序
查看>>
sqlite的坑
查看>>
Elastic Search 上市了,市值翻倍,这群人财务自由了!
查看>>
digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
查看>>
linux swoole
查看>>
An Easy Problem?! - POJ 2826(求面积)
查看>>
【题解】[P4178 Tree]
查看>>
Jquery ui widget开发
查看>>
css3实现循环执行动画,且动画每次都有延迟
查看>>
更改git仓库地址
查看>>
有标号DAG计数 [容斥原理 子集反演 组合数学 fft]
查看>>
Recipe 1.4. Reversing a String by Words or Characters
查看>>
Rule 1: Make Fewer HTTP Requests(Chapter 1 of High performance Web Sites)
查看>>
sql注入
查看>>
「破解」Xposed强
查看>>
Linux 平台下 MySQL 5.5 安装 说明 与 示例
查看>>
src与href的区别
查看>>
ABAP工作区,内表,标题行的定义和区别
查看>>