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

import itertools

dim = 100
m = list(range(1, dim+1))
w = list(range(-1, -dim-1, -1))
num = 0
global zero_num
zero_num = 0 m_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
break print(zero_num)
print(num)
print((num-zero_num)/num)

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

Python codes的更多相关文章

  1. program 1 : python codes for login program(登录程序python代码)

    #improt time module for count down puase time import time #set var for loop counting counter=1 #logi ...

  2. Embeding Python & Extending Python with FFPython

    Introduction ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. ...

  3. 机器学习算法基础(Python和R语言实现)

    https://www.analyticsvidhya.com/blog/2015/08/common-machine-learning-algorithms/?spm=5176.100239.blo ...

  4. xls===>csv tables===via python ===> sqlite3.db

    I've got some files which can help a little bit to figure out where people are from based on their I ...

  5. A Complete Tutorial to Learn Data Science with Python from Scratch

    A Complete Tutorial to Learn Data Science with Python from Scratch Introduction It happened few year ...

  6. python coding style guide 的高速落地实践

    python coding style guide 的高速落地实践 机器和人各有所长,如coding style检查这样的可自己主动化的工作理应交给机器去完毕,故发此文帮助你在几分钟内实现coding ...

  7. Python之Pandas库学习(二):数据读写

    1. I/O API工具 读取函数 写入函数 read_csv to_csv read_excel to_excel read_hdf to_hdf read_sql to_sql read_json ...

  8. python coding style guide 的快速落地实践——业内python 编码风格就pep8和谷歌可以认作标准

    python coding style guide 的快速落地实践 机器和人各有所长,如coding style检查这种可自动化的工作理应交给机器去完成,故发此文帮助你在几分钟内实现coding st ...

  9. python学习笔记(2):科学计算及数据可视化入门

    一.NumPy 1.NumPy:Numberical Python 2.高性能科学计算和数据分析的基础包 3.ndarray,多维数组(矩阵),具有矢量运算的能力,快速.节省空间 (1)ndarray ...

随机推荐

  1. OpenGL ES 2.0 变换

    基本变换都是通过将表示点坐标的向量与特定的变换矩阵相乘完成的. 进行基于矩阵的变换时,三位空间中点的位置需要表示成齐次坐标形式. 齐次坐标形式:在X.Y.Z3个坐标值后面增加第四个量W,未变换时W值一 ...

  2. hdu4006 优先队列

    A - 签到 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65768KB     64bit I ...

  3. socket网络编程中的同步,异步,阻塞式,非阻塞式,有何联系与区别?

    一.举个打电话的例子: 阻塞   block   是指,你拨通某人的电话,但是此人不在,于是你拿着电话等他回来,其间不能再用电话.同步大概和阻塞差不多. 非阻塞   nonblock   是指,你拨通 ...

  4. web qq 获取好友列表hash算法

    web qq 获取好友列表hash算法 在使用web qq的接口进行好友列表获取的时候,需要post一个参数:hash 在对其js文件进行分析之后,发现计算hash的函数位于: http://0.we ...

  5. git教程 入门

    快速上传已有代码到github 如何将最新代码上传到github,这里讲本地已有项目文件的情况(假如本地有一个helloworld的工程目录,目录中有很多项目文件.),步骤如下: 前提:已安装git客 ...

  6. Windows Server 2003 SP2企业版ISO下载, windows2003系统下载,2003系统下载,2003系统

    Windows Server 2003 SP2 企业版ISO下载(真正企业免激活版) 此版本适合作为一个新系统来安装,也适合在虚拟机中安装 点评:Windows Server 2003 SP2 企业版 ...

  7. The Time in Words

    def main(): time = ["one", "two", "three", "four", "fiv ...

  8. Eclipse开发Python项目

    最近倒腾python自带的开发工具idle,用的很不习惯,还是用Eclipse编写python项目方便(自动补齐,智能报错,调试方便),下面就说说怎么用Eclipse编写python代码吧~ 1.安装 ...

  9. MVC中ActionFilterAttribute用法并实现统一授权

    MVC中ActionFilterAttribute经常用来处理权限或者统一操作时的问题. 先写一个简单的例子,如下: 比如现在有一个用户管理中心,而这个用户管理中心需要登录授权后才能进去操作或浏览信息 ...

  10. mvc上传,下载,浏览文件功能(用uploadify插件)

    类 public class UpLoadFileController : Controller { // // GET: /UpLoadFile/ public ActionResult Index ...