Skip to content

Instantly share code, notes, and snippets.

#if os(Linux)
import Glibc
#else
import Darwin
#endif
// Still not lovely but tested under OS X Swift 3 and Linux Swift 3
// Use fopen/fwrite to output string
func writeStringToFile(string: String, path: String) -> Bool {
@rougier
rougier / binomial.py
Created January 25, 2016 09:50
A fast way to calculate binomial coefficients in python (Andrew Dalke)
def binomial(n, k):
"""
A fast way to calculate binomial coefficients by Andrew Dalke.
See http://stackoverflow.com/questions/3025162/statistics-combinations-in-python
"""
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in xrange(1, min(k, n - k) + 1):
ntok *= n