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. C#按钮打开浏览器,网址

    1.加入 using System.Diagnostics; 2. private void button_main_baidu_Click(object sender, EventArgs e) { ...

  2. 对面向对象程序设计(OOP)的认识

    前言 本文主要介绍面向对象(OO)程序设计,以维基百科的解释: 面向对象程序设计(英语:Object-oriented programming,缩写:OOP),指一种程序设计范型,同时也是一种程序开发 ...

  3. JavaScript语法学习笔记

    1.关于执行JavaScript代码的方法: 第一种方法是将JavaScript代码放到文档<head>标签中的<script>标签之间: <head>     & ...

  4. React java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.edaixi.activity/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit

    E/AndroidRuntime: FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 3659 at java.lang.Runtime ...

  5. 以字符串形式读取github上.json文件

    如下: https://github.com/hpu-spring87/ebooks/blob/master/update.json 如果直接用httpclient读取该URL地址,得到结果是这样的: ...

  6. CoreData概略

    CoreData概略 分类: IOS开发2013-10-25 16:19 178人阅读 评论(0) 收藏 举报 CoreData是IOS对数据进行对象化管理的一种高效方式,提供了对数据的增.删.查.改 ...

  7. mysql group_concat函数是有长度限制的

    在表关联查询中,特别是一对多关系的表查询中,group_concat函数是很有用的一个函数,帮助我们减少对数据库查询的次数,减少服务器的压力. 但是今天使用group_concat函数查询数据库时,发 ...

  8. Linux权限机制

    权限是操作系统用来限制用户.组.进程对操作系统资源(文件.设备等)的访问的机制 权限分为:读.写.执行,一般表示为 r.w.x http://itercast.com/lecture/22 每个文件或 ...

  9. Java宝典(二)

    --String s = "a" + "b" + "c" + "d"; 一共创建了多少个对象? --对于如下代码: St ...

  10. ecshop 管理员不需要旧密码