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 <iterator> | |
#include <iostream> | |
#include <future> | |
#include <experimental/coroutine> | |
std::function<void()> resume; | |
template <typename _Ty, typename _Alloc = std::allocator<char>> | |
class future { | |
public: |
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
val s = Array("A", "B", "C") | |
val lock = new java.util.concurrent.locks.ReentrantLock() | |
val total = s.length | |
var token: Int = 0 | |
val cvs = s.map(i => lock.newCondition()) | |
val threads = for (t <- 0 until 3) yield { | |
val thread = new Thread { | |
override def run { | |
lock.lock() |
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
function unfold(p, f, g, seed, reduce, tailgen) { | |
function recursive(iter) { | |
if (p(iter)) return tailgen(iter); | |
return reduce(f(iter), recursive(g(iter))); | |
} | |
return recursive(seed); | |
} | |
function sum(a) { |
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
function unfold(p, f, g, seed, reduce, tailgen) { | |
function recursive(iter) { | |
if (p(iter)) return tailgen(iter); | |
return reduce(f(iter), recursive(g(iter))); | |
} | |
return recursive(seed); | |
} |
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> | |
#if defined(__i386__) | |
static __inline__ unsigned long long rdtsc(void) | |
{ | |
unsigned long long int x; | |
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); | |
return x; | |
} |
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/sh | |
MAX=10000 | |
case "$script_type" in | |
route-up) | |
op=add | |
;; | |
route-pre-down) | |
op=delete |
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 test | |
object TileAndTrouble extends App { | |
//val row = List(8, 8, 20, 17, 25, 25, 11) | |
//val col = List(15, 13, 10, 21, 20, 18, 17) | |
val row = List(12, 17, 43, 44, 34, 42, 43, 21, 36, 29, 30, 26) | |
val col = List(30, 35, 45, 43, 41, 28, 25, 29, 25, 38, 18, 20) | |
val size = row.length | |
def seperate_inner(n: Int, c: Int, max: Int): Seq[Map[Int, Int]] = { |
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
// use dp to speed up | |
def Count(n: Int, m: Int) = { | |
def Loop(n: Int, m: Int, max: Int): Int = { | |
if (m == 0) { | |
if (n == 0) 1 else 0 | |
} else { | |
(0 to Math.min(max, n)).map({ x => Loop(n - x, m - 1, x) }).sum | |
} | |
} |
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
def Conbination(n: Int, m: Int) { | |
def Loop(n: Int, m: Int, prefix: List[Int]) { | |
if (m == 0) | |
println(prefix) | |
else | |
for (x <- m to n) | |
Loop(x - 1, m - 1, x :: prefix) | |
} | |
Loop(n, m, Nil) | |
} |
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
case class BinaryTree(left: BinaryTree, right: BinaryTree) | |
def isFull(tree: BinaryTree): Boolean = { | |
def FullWithHeight(tree: BinaryTree): Int = { | |
if (tree == null) 0 else { | |
val l = FullWithHeight(tree.left) | |
val r = FullWithHeight(tree.right) | |
if (l >= 0 && l == r) l+1 else -1 | |
} | |
} |
NewerOlder