Skip to content

Instantly share code, notes, and snippets.

View alecbz's full-sized avatar

Alec Benzer alecbz

View GitHub Profile
@alecbz
alecbz / pi.clj
Created July 3, 2011 06:47
compute pi via monte carlo
(defn circle-test [x y]
(not ( > ( + (* (- x 0.5) (- x 0.5)) (* (- y 0.5) (- y 0.5))) 0.25)))
(defn error [est]
(Math/abs (* (/ (- Math/PI est) Math/PI) 100)))
(defn pi [n]
(loop [hits 0 total 0]
(let [x (rand) y (rand)]
(if (< total n)
@alecbz
alecbz / inc.cpp
Created July 4, 2011 21:51
increment an integer without arithmetic operators
void inc(int& n)
{
int off = 1;
while(n & off)
{
n ^= off;
off <<= 1;
}
n ^= off;
}
``` cpp
void inc(int& n)
{
int off = 1;
while(n & off)
{
n ^= off;
off <<= 1;
}
n ^= off;
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
class Trie
{
public:
struct Node
{
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;
class Trie
{
public:
#inclsdfsdf
s
fsd
faf
sdf
I don't know if using a tool like [ctrlp for vim](https://github.com/kien/ctrlp.vim) is always such a great idea, especially when exploring a directory structure that you're unfamiliar with. ctrlp is great, and I love it for things like rails projects, where I more or less know where all the files are but I'm getting ready to bash my head in from having to type app/views/post/show.html.erb in 50 billion times.
Unfortunately, I'm also tempted to love ctrlp in situations where I'm not familiar with the directory structure. While going through some google training exercises, there are parts that go "open blah.cc", which happens to reside in a directory structure I'm not so familiar with. It's really tempting to just ctrl+p and type "blah.cc", but now I have no idea where the file was, and I get to go on doing stuff without getting an understanding of the directory structure. It's much better to spend some time digging through the directory tree to see what's what and where what is.
Fuzzy finders like cltrp are
package main
import (
"bufio"
"fmt"
"os"
"unicode"
)
type node struct {
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int countOnes(unsigned int input) {
// lab answer here
}
unsigned int countOnesSlow(unsigned int input) {
int count = 0;
#include <stdio.h>
int main() {
unsigned int x = 11;
printf("count:"" %u", x);
return 0;
}