Skip to content

Instantly share code, notes, and snippets.

@vo
vo / supersale.cpp
Created April 29, 2011 17:44
10130: SuperSale
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/*-----------------------------------------------------------------------------
* Process the data
*
* input:
* v[i]: value of the ith object
@vo
vo / gist:948704
Created April 29, 2011 17:51
Sudoku
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(ITER,FROM,TO) for(ITER=FROM;ITER<TO;ITER++)
int A[9][9];
bool chk[9];
@vo
vo / gist:1008214
Created June 4, 2011 19:08
Compute number of days between dates
<?php
$birth = strtotime('1902-01-01');
$current = strtotime('2011-03-06');
$days = round(abs($current-$birth)/86400);
?>
@vo
vo / grab.cpp
Created July 2, 2011 00:13
Capture Image to Disk
#include <cstdio>
#include <ctime>
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
// open camera
cv::VideoCapture cap(0);
if(!cap.isOpened())
@vo
vo / grab.py
Created July 5, 2011 15:25
Capture Image to Disk
#!/usr/bin/env python
from opencv import cv
from opencv import highgui
from datetime import datetime
capture = highgui.cvCreateCameraCapture(0)
for i in range(0, 15):
img = highgui.cvQueryFrame(capture)
filename = datetime.now().strftime("%Y-%m-%d %H:%M:%S.jpg")
@vo
vo / wordEnds.java
Created April 10, 2012 22:14
wordEnds
/*
* A solution for programming problem "wordEnds":
* http://codingbat.com/prob/p147538
*/
public String wordEnds(String str, String word) {
StringBuffer tmp = new StringBuffer();
int ss=0, idx=-1;
while((idx = str.indexOf(word, ss)) >= 0) {
ss = idx + word.length();
if(idx-1 >= 0) tmp.append(str.charAt(idx-1));
@vo
vo / SimpleSolver.java
Created April 24, 2012 17:28
Simple cryptarithmetic puzzle solver in Java, C, and Python
public class SimpleSolver {
static int eval(String q) {
int val = 0;
java.util.StringTokenizer st = new java.util.StringTokenizer(q, "*/+-", true);
while (st.hasMoreTokens()) {
String next = st.nextToken().trim();
if (next.equals("+")) {
val += Integer.parseInt(st.nextToken().trim());
} else if (next.equals("-")) {
val -= Integer.parseInt(st.nextToken().trim());
@vo
vo / point-plane-dist.c
Created April 28, 2012 17:15
Point Plane Distance
// given 3 points on plane (x1,y1,z1), (x2,y2,z2), (x3,y3,z3)
// get distance to (x,y,z)
double plane_exp_point_dist_3d ( double x1, double y1, double z1, double x2,
double y2, double z2, double x3, double y3, double z3, double x, double y, double z )
{
double a;
double b;
double c;
double d;
double dist;
@vo
vo / Link.java
Created May 20, 2012 17:54
Reversing a Linked List Using Recursion
@vo
vo / test.cpp
Created June 5, 2012 17:25
Simplest OpenGL Program ever
#include <GL/glut.h>
void draw(void)
{
glClearColor(0,1,0,1);
glClear(GL_COLOR_BUFFER_BIT );
glFlush();
}
int main(int argc, char **argv)