Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import choices, sample | |
from statistics import mean | |
def common_birthday(k): | |
'''Generate k independent uniformly random birthdays & check if there are any repeats''' | |
birthdays = choices(range(1, 366), k=k) | |
return len(set(birthdays)) != k | |
>>> mean(common_birthday(23) for _ in range(10000)) | |
0.4979 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io._ | |
import java.util.zip.{Inflater, Deflater} | |
import java.io.{File, FileOutputStream} | |
object App { | |
def compress(inData: Array[Byte]): Array[Byte] = { | |
var deflater: Deflater = new Deflater() | |
deflater.setInput(inData) | |
deflater.finish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <math.h> | |
using namespace std; | |
#define MOD 1000000007 | |
unsigned long long power(unsigned long long num, int p) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import math | |
seed = 1 | |
boost = 5 | |
iter = 3 | |
numCities = 4 | |
maxDistance = 40000 | |
upperX = 24000 | |
upperY = 32000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install python-pip python-dev build-essential | |
sudo pip install --upgrade pip | |
sudo pip install --upgrade gensim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
from random import uniform, gauss | |
def gaussian(mu, sigma = 0.1): | |
prob = gauss(mu, sigma) | |
if prob < 0: | |
return 0.0 | |
elif prob > 1: | |
return 1.0 | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
struct node | |
{ | |
char c; | |
struct node* left, *right; | |
}; | |
struct node* createNode(char c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <limits.h> | |
unsigned int prevTwo(unsigned int x) // bit twiddling | |
{ | |
unsigned int y = x; | |
x--; | |
x |= x >> 1; | |
x |= x >> 2; |
NewerOlder