小编Rob*_*Dey的帖子

有效解决Python中的字母/数字问题

如果a = 15152表示为a2while,215则表示为2a必须找到数字x

8x = 8*x8

我试过这个天真的Python代码

>>> i = 0
>>> while(i<=100000000000000000):
...   if(int("8"+str(i))==8*int(str(i)+"8")):
...     break
...   i = i+1
... print i
Run Code Online (Sandbox Code Playgroud)

但是要花费大量时间才能产生正确的结果.

如何优化代码?

python math

8
推荐指数
1
解决办法
326
查看次数

组合实现和谜题

在此输入图像描述

在图像中找到了这个谜题.根据我的想法,方法的总数应该是多少

2*comb(7,i) for i <- 1 to 7其中comb定义如下.我的方法是否正确?我关心的是我得到的结果而不是下面写的函数.

def comb(N,k): 
    if (k > N) or (N < 0) or (k < 0):
        return 0L
    N,k = map(long,(N,k))
    top = N
    val = 1L
    while (top > (N-k)):
        val *= top
        top -= 1
    n = 1L
    while (n < k+1L):
        val /= n
        n += 1
    return val
Run Code Online (Sandbox Code Playgroud)

不要介意我在短时间内提出太多问题.我很热情.

python math combinatorics

5
推荐指数
1
解决办法
324
查看次数

标签 统计

math ×2

python ×2

combinatorics ×1