Skip to content

Instantly share code, notes, and snippets.

function f(x) { }
c = 7;
while (c > 0) {
r = Math.floor(Math.random() * 49);
if (! f(r)) {
console.log(r + 1);
f = function(r, f, x) { return x == r || f(x) }.bind(null, r, f);
c--;
}
N = 49
M = 7
def l(n, i) # left
(i == M - 1) ? n : l(n, i + 1) / (N - (i + 1))
end
def b(n, i) # branch
l(n, i) % (N - i)
end
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int N = 49;
const int M = 7;
long long l(const long long n, const int i) { // left
return (i == M - 1) ? n : l(n, i + 1) / (N - (i + 1));
}
@LCamel
LCamel / gist:1401491
Created November 28, 2011 18:47
no-loop c version
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int N = 49;
const int M = 7;
//const int N = 5;
//const int M = 3;
long long l(const long long n, const int i) { // left
@LCamel
LCamel / a.cpp
Created November 29, 2011 17:28
P(N, M) with template metaprogramming
// g++ -std=c++0x a.cpp 2>&1 | grep Print
const int N = 49;
const int M = 7;
template <long long n, int i> struct L { enum : long long {
v = L<n, i + 1>::v / (N - (i + 1))
};};
template <long long n > struct L<n, M - 1> { enum : long long {
v = n
a =: 20 15 30 45
((#~0<|)(0=|10|a)*1+i.#a)-1
0 2
@LCamel
LCamel / a.c
Created February 9, 2012 18:44
// gcc -pedantic -std=c99 a.c
#include <stdio.h>
#include <string.h>
void f(char *msg, int size, int pos) {
if (pos >= size)
return;
int len = (msg[pos] & 0x80) == 0 ? 1 : (msg[pos] & 0xe0) == 0xc0 ? 2 : 3;
char buf[len];
memcpy(buf, msg + pos, len);
@LCamel
LCamel / gist:1892034
Created February 23, 2012 09:59
Search
// http://www.facebook.com/groups/javascript.tw/194457013988978/
var n2ed = [ [ [0, 1], [1, 1] ], [ [0, 0], [1, 0], [2, 2], [3, 2] ], [ [2, 1], [3, 1] ] ];
function comp(val, edge) {
if (edge == 0) return val + 7;
if (edge == 1) return val / 2;
if (edge == 2) return val * 3;
if (edge == 3) return val - 5;
}
@LCamel
LCamel / gist:1901135
Created February 24, 2012 14:08
Search 2012
for (var n = 0; 1; n++)
if (ok(n))
show(n);
function ok(n) {
var v = 2011 + 7;
while (1) {
var x = n % 4;
if (x == 0) v = (v + 7) / 2;
else if (x == 1) v = (v / 2) + 7;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
runAndKill("java A", 3000);
}
public static void runAndKill(String cmd, final long millis) throws IOException, InterruptedException {
final Process proc = Runtime.getRuntime().exec(cmd);
new Thread() {