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 <math.h> | |
#include <stdio.h> | |
#include <set> | |
typedef std::set<int> Set; | |
bool is_prime(int a, Set* primes) { | |
for (Set::const_iterator i = primes->begin(); | |
i != primes->end() && *i <= sqrt(a); | |
++i) { |
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 <math.h> | |
#include <stdio.h> | |
#include <vector> | |
typedef std::vector<long> Queue; | |
long find_smallest_divisor(long number) { | |
for (long i = 2; i < sqrt(number); ++i) { | |
if (number % i == 0) { | |
return i; |
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 <string> | |
std::string positive_to_string(int num) { | |
std::string s; | |
while (num > 0) { | |
s.push_back((char)('0' + (num % 10))); | |
num /= 10; | |
} | |
return s; |
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
// Question: What is the smallest number divisible by each of the | |
// numbers 1 to 20? | |
// | |
// I factorize each of the numbers 1 to 20. For example, 12=2*2*3. | |
// This factorization can be represented by a histogram (2*2 3*1). If | |
// a number is evenly divisible by 20, it must be a product of at | |
// least two 2's and a 3. So I accumulate each factorization into a | |
// histogram by the following rule: if the factorization contains two | |
// 2's, the accumulation must contain at least two 2's. Then the | |
// final result is the product of numbers in the accumulation. |
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> | |
struct Node { | |
int key; | |
Node* left; | |
Node* right; | |
Node* parent; | |
Node(int k, Node* l, Node* r) { | |
key = k; |
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
cc_plugin( | |
name = 'lda', | |
srcs = ['lda.c'], | |
deps = ['#pthread'] | |
) |
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
# This script download, build and deploy MPICH 3.1 | |
# (http://www.mpich.org) and pLDA 3.1 (https://code.google.com/p/plda) | |
# to computers in a cluster. | |
# | |
# Usage: | |
# | |
# You download and run this script from any directory. For example, | |
# consider that Alice is running this script to install MPICH and pLDA | |
# on David's workstation in the role of Steven, she should do: | |
# |
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
#!/bin/bash | |
# git pre-commit hook that runs an clang-format stylecheck. | |
# Features: | |
# - abort commit when commit does not comply with the style guidelines | |
# - create a patch of the proposed style changes | |
# modifications for clang-format by [email protected] | |
# This file is part of a set of unofficial pre-commit hooks available | |
# at github. |
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
package main | |
import ( | |
"errors" | |
"fmt" | |
"log" | |
"net" | |
"net/rpc" | |
"net/rpc/jsonrpc" | |
) |
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
// This simple program shows how to use the write-support branch of | |
// https://github.com/colinmarc/hdfs/, which accesses HDFS of Hadoop | |
// 2.2.x throught the native protobuf-based RPC protocol |
OlderNewer