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 / infostack.cpp
Created March 10, 2014 00:15
For pretty debug information on the callstack.
static int g_infoStackDepth = 0;
static vector<string> g_infoStack;
const int MaxInfoLength = 2056;
void push_info_stack(const string str)
{
g_infoStack.push_back(str);
}
void pop_info_stack()
@ygabo
ygabo / coins.cpp
Created February 24, 2014 04:55
minimum number of coins to make change, n.
void change(vector<int>* coins, int n)
{
vector<int> table(n + 1);
table[0] = 1;
table[1] = 1;
for (int i = 2; i < n + 1; i++)
{
int min = 0;
int prev = 0;
@ygabo
ygabo / itoa.cpp
Created September 26, 2013 12:37
Own implementation of int to string (char array).
#include <iostream>
#include <string>
using namespace std;
int main(){
int x = -1234;
string y;
int temp;
int templeft;
@ygabo
ygabo / sieve.cpp
Created September 14, 2013 10:20
Sieve of Eratosthenes.
#include <iostream>
using namespace std;
#include <list>
void TA(int n){
list<int> m;
m.push_back(2);
for( int i = 3; i <= n; i+=2)
m.push_back(i);
@ygabo
ygabo / Beautiful.cpp
Created September 3, 2013 02:13
Beautiful String. More beautiful if bigger than the other. More beautiful if string is lexicographically bigger than the other, when they're equal length. This code gets the most beautiful unique string from a given string.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
using namespace std;
bool valid( map<char, vector<int>> m, string me){
// this one checks if a string is valid
@ygabo
ygabo / beautiful.cpp
Created September 3, 2013 00:47
Depth First Search on the map to build a unique string that depends on the index.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <list>
@ygabo
ygabo / sstreamex.cpp
Created August 26, 2013 06:19
Stringstream splitting words
int main(){
string x = "helllo there sd";
string d;
stringstream ss(x);
while( getline(ss, d, ' ') ){
cout << d << endl;
}
cin.get();
@ygabo
ygabo / nQueens.cpp
Created August 24, 2013 22:56
Write an algorithm to prim all ways of arranging eight queens on an 8x8 chess board so that none of them share the same row, column or diagonal. In this case, "diagonal" means all diagonals, not just the two that bisect the board.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <fstream>
#include < ctime >
#include <algorithm>
#include <vector>
#include <iostream>
@ygabo
ygabo / magicarray.cpp
Created August 24, 2013 20:02
A magic index in an array A[l.. .n-l] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <fstream>
#include < ctime >
#include <algorithm>
#include <vector>
#include <iostream>
@ygabo
ygabo / SortedList.cpp
Created August 24, 2013 18:59
Sorted Linked List.
template <class T>
class SortedList
{
public:
SortedList():m_head(nullptr),size(0)
{}
void Push(T value);
T Pop();
int Size();