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

  1. import itertools
  2.  
  3. dim = 100
  4. m = list(range(1, dim+1))
  5. w = list(range(-1, -dim-1, -1))
  6. num = 0
  7. global zero_num
  8. zero_num = 0
  9.  
  10. m_all = list(itertools.permutations(m,dim))
  11. w_all = list(itertools.permutations(w,dim))
  12.  
  13. num = len(m_all) * len(w_all)
  14. for m in m_all:
  15. for w in w_all:
  16. for i in range(dim):
  17. if m[i] + w[i] == 0:
  18. zero_num += 1
  19. break
  20.  
  21. print(zero_num)
  22. print(num)
  23. 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. tiny xml 使用总结

    这几天在埋头写自己的3D文件浏览器(稍后发布),突发奇想的要把自己的内部格式转化成XML,于是,把以前在研究所时用过的ExPat翻了出来.ExPat是基于事件的XML解释器,速度挺快的,但结构方面有点 ...

  2. C# 获取当前路径

    // 获取程序的基目录.System.AppDomain.CurrentDomain.BaseDirectory  F:\广告编辑系统新\taxi_edit\taxi_form\bin\Debug\ ...

  3. Python中range的用法

    函数原型:range(start, end, scan): 参数含义:start:计数从start开始.默认是从0开始.例如range(5)等价于range(0, 5); end:技术到end结束,但 ...

  4. [HDU] 2094 产生冠军(拓扑排序+map)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2094 注意每组数据处理前,map要清空. #include<cstdio> #includ ...

  5. [LA] 2031 Dance Dance Revolution

    Dance Dance Revolution Time limit: 3.000 seconds Mr. White, a fat man, now is crazy about a game nam ...

  6. Ubuntu下配置NFS服务

    Table of Contents 1.下载相关软件 2.建立共享目录 3.修改该配置文件 4.重启服务 5.测试服务器 6.测试客户端 测试系统:Ubuntu8.04 1.下载相关软件 使用如下命令 ...

  7. sign starfieldtech

    signtool sign /f certfile.pfx /p password /tr http://tsa.starfieldtech.com /td SHA256 mycode.exe htt ...

  8. 【转】Android HAL实例解析

    原文网址:http://www.embedu.org/Column/Column339.htm 作者:刘老师,华清远见嵌入式学院讲师. 一.概述 本文希望通过分析台湾的Jollen的mokoid 工程 ...

  9. POJ 2752 Seek the Name, Seek the Fame (KMP next 数组 变形)

    题意:给一个字符串S,判断在什么下标的时候,前缀和后缀相等,输出前缀和后缀相等的点. 分析:next数组的一种很巧妙的用法 next数组表示的意义是当前下标前面k字符和开头的前面k个字符相等 所以就会 ...

  10. 【剑指offer】面试题35:第一个只出现一次的字符

    题目: 在一个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符的位置.若为空串,返回-1.(书上是要求返回字符) 思路: 第一遍扫描保存下每个字符出现的 ...