Skip to content

Instantly share code, notes, and snippets.

View ygabo's full-sized avatar
🎯
Focusing

Yel Gabo ygabo

🎯
Focusing
  • Vancouver Canada
View GitHub Profile
@ygabo
ygabo / naivebayes.py
Created September 5, 2012 04:12
Naive Bayes Implementation
import numpy as np
import scipy.io
import matplotlib.pyplot as pl
class Classifier ( object ):
def __init__ ( self ):
self.params = [ 'logpi', 'logtheta' ]
def fit (self , X, y):
@ygabo
ygabo / solver.java
Created September 5, 2012 12:20
Sudoku Solver
package sudoku;
import java.util.ArrayList ;
import java.util.HashSet ;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random ;
/**
* Place for your code.
*/
public class RobustSudokuSolver {
@ygabo
ygabo / topK.cpp
Last active December 17, 2015 17:18
Extract the top K elements from a given set.
#include "topK.hpp"
using namespace std;
int main(){
int xx[] ={124,34,324,54,6,645,33,43};
vector<int> x(begin(xx), end(xx));
int k = 5;
heapK<int> hpk(k);
@ygabo
ygabo / kmp.cpp
Last active December 17, 2015 20:38
String searching in linear time, O(n).
#include <iostream>
#include <thread>
#include <string>
#include <vector>
using namespace std;
// This KMP algorithm is described, explained and written out at
// http://www.inf.fh-flensburg.de/lang/algorithmen/pattern/kmpen.htm
void preprocess( string pattern, vector<int> &b ){
int m = pattern.length();
@ygabo
ygabo / heapsort.cpp
Created May 29, 2013 07:21
Heapsort implementation.
#include <vector>
#include <iostream>
using namespace std;
int get_parent(int i){
if( i < 1 ) return 0;
return ( (i-1) / 2);
}
int get_left(int parent){
void prob8(){
for( int c = 1; c <= 1000; c++ ){
for( int b = 1; b < c; b++){
for( int a = 1; a < b; a++){
if ( (a + b + c == 1000 ) &&
(pow(a,2) + pow(b,2) == pow(c,2)))
std::cout << a << " " << b << " " << c << " " << a*b*c << std::endl;
}
}
}
@ygabo
ygabo / combinations.cpp
Created June 10, 2013 12:19
Generate combinations from a given set.
#include <vector>
#include <stdint.h>
#include <iostream>
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
@ygabo
ygabo / lcs.cpp
Created June 11, 2013 07:41
Longest Commong Substring (Length only)
void main(){
// 5-choose-3
std::size_t n =184;
std::size_t k = 3;
std::string s = "hello";
std::string s2 = "llo";
std::vector<std::vector<int>> lcs(s.length()+1, std::vector<int>(s2.length()+1));
@ygabo
ygabo / lss.cpp
Created June 13, 2013 10:42
Largest sum sequence
#include <vector>
#include <iostream>
using namespace std;
void main(){
int x[] = { 1, -4 ,4 ,3 , -2 ,-3, 2 ,1 };
vector<int> s(begin(x), end(x));
int max_so_far = 0, begin_so_far =0, max = 0, begin = 0, end =0;
int temp;
for(int i = 0; i < s.size(); ++i){
@ygabo
ygabo / Tree.cpp
Created June 14, 2013 11:41
Binary Tree inserting, print in-order, print by level, find next node in-order.
#include <vector>
#include <iostream>
#include <random>
#include <time.h>
#include <queue>
using namespace std;
class Node{
public:
Node():data(0),left(nullptr),right(nullptr),parent(nullptr) {}