Sort by

recency

|

119 Discussions

|

  • + 0 comments

    great post

  • + 0 comments

    An nCr table, also known as a combination table, is a systematic way to list combinations of items, especially useful in probability and statistics. It typically shows the number of ways to choose r items from a set of n items without regard to the order of selection. Such tables are invaluable in fields like combinatorics, where precise calculations of permutations and combinations are required. They serve as quick references, aiding in computations for various scenarios, from binomial coefficients to complex probability distributions. For those interested in exploring practical applications or enhancing their understanding of these concepts, resources like Studio Trataka's Qutub Copper Candle Stand T-Light, available at https://studiotrataka.com/product/qutub-copper-candle-stand-t-light/, can add a touch of elegance to your study environment while you delve into the intricacies of combinatorial mathematics.

  • + 0 comments

    Python math.comb is so fast that the following brute-force one-liner works:

    def solve(n):
        return [math.comb(n, i)%10**9 for i in range(n+1)]
    

    You can watch Raymond Hettinger's amazing talk "Numerical Marvels Inside Python" to understand why math.comb is so fast, including with very very large n (group theory ahead!).

  • + 0 comments

    def solve(n): ncr = [] for r in range (n//2 + 1): ncr.append(comb(n, r)%(10**9)) if n % 2== 0: return ncr + ncr[:-1][::-1] else: return ncr + ncr[::-1]

  • + 0 comments

    My accepted Go solution:

    func solve(n int32) []int32 {
        one := big.NewInt(1)
        tmpResult := []*big.Int{one}
        result := []int32{1}
        mod := int64(math.Pow(10, 9))
        bigMod := big.NewInt(mod)
        bigN := big.NewInt(int64(n))
        i := int32(0)
        for ; i < n; i++ {
            tmpItem := new(big.Int).Set(tmpResult[i])
            tmpN := new(big.Int).Set(bigN)
            num := tmpN.Sub(tmpN, big.NewInt(int64(i))).Mul(tmpN, tmpItem)
            denom := big.NewInt(int64(i))
            denom.Add(denom, one)
            val := num.Div(num, denom)
            tmpResult = append(tmpResult, val)
        }
    
        j := int32(1)
        for ; j <= n; j++ {
            tmpVal := new(big.Int).Set(tmpResult[j])
            modVal := tmpVal.Mod(tmpVal, bigMod)
            result = append(result, int32(modVal.Int64()))
        }
        return result
    }