Skip to content

自然常数 e | Math #6

Open
Open

Description

@haozi

https://math.haozi.me/E.html

Easy Math for Coder

Activity

  1. Hitsuki9 commented on Nov 12, 2020

    @Hitsuki9

    0.36 不应该是没有中奖的概率吗

  2. Zhang-zm commented on Nov 12, 2020

    @Zhang-zm

    大佬,factorial 不考虑尾递归实现嘛

  3. wwb91 commented on Nov 13, 2020

    @wwb91

    假设有 1000 个乒乓球,其中有一个是可以中奖的红球,那么抽 1000 次,中奖的概率是多少?

    计算公式应为1-(1-1/N)^N

  4. haozi commented on Nov 16, 2020

    @haozi
    CollaboratorAuthor

    @Zhang-zm
    大佬,factorial 不考虑尾递归实现嘛

    目前V8 还没有支持尾递归调用优化,由于阶乘增长得很快,得配合 bigInt,而鸡肋的 bigInt 并不能在本文场景用来计算浮点数。

    const factorial = (n, acc = 1n) =>
      n == 1n ? acc
             : factorial(n - 1n, acc * n)
    
    factorial(9999n)

    这个可以在 safari 和 firefox 下执行,V8 还是会栈溢出。

    V8 团队早在 16 年就提了个语法草案,一直悬而未决
    https://v8.dev/blog/modern-javascript
    https://github.com/tc39/proposal-ptc-syntax

    其实阶乘也可以用循环实现。

    不过本专栏不太想讲工程实践

  5. haozi commented on Nov 16, 2020

    @haozi
    CollaboratorAuthor

    假设有 1000 个乒乓球,其中有一个是可以中奖的红球,那么抽 1000 次,中奖的概率是多少?

    计算公式应为1-(1-1/N)^N

    非常感谢指正,已订正。造成困扰非常抱歉。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions