Instantly share code, notes, and snippets.

# Yi Wangwangkuiyi

• Sort options
Last active Aug 29, 2015
JSON RPC Go Example
View jsonrpc_example.go
 package main import ( "errors" "fmt" "log" "net" "net/rpc" "net/rpc/jsonrpc" )
Created Sep 6, 2012
Project Euler Problem 50: http://projecteuler.net/problem=50
View prime-as-sum-of-consecutive-primes.cc
 #include #include #include typedef std::set Set; bool is_prime(int a, Set* primes) { for (Set::const_iterator i = primes->begin(); i != primes->end() && *i <= sqrt(a); ++i) {
Created Sep 6, 2012
Find the largest prime factor of a number. http://projecteuler.net/problem=3
View largest-prime-factor.cc
 #include #include #include typedef std::vector Queue; long find_smallest_divisor(long number) { for (long i = 2; i < sqrt(number); ++i) { if (number % i == 0) { return i;
Created Sep 6, 2012
Find the largest palindrome made from the product of two 3-digit numbers. http://projecteuler.net/problem=4
View palindrome-as-product.cc
 #include #include std::string positive_to_string(int num) { std::string s; while (num > 0) { s.push_back((char)('0' + (num % 10))); num /= 10; } return s;
Created Sep 6, 2012
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? http://projecteuler.net/problem=5
View number-divisible-by-numbers.cc
 // 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.
Created Dec 14, 2012
O(n)-time non-recursive traversal of binary trees without extract space cost.
View binary-tree-traversal.cc
 #include struct Node { int key; Node* left; Node* right; Node* parent; Node(int k, Node* l, Node* r) { key = k;
Created Dec 2, 2015
View learn-go-hdfs-write.go
 // 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
Created Jan 14, 2016
This sample program shows how to read Gob-encoded records out from a file.
View learn-gob.go
 package main import ( "encoding/gob" "io" "log" "os" ) func main() {
Created Feb 3, 2016
Shows how to use https://github.com/AdRoll/goamz/tree/master/s3 to access an AWS bucket created on AWS console.
View goaws-s3.go