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 / hexpuzzle.py
Last active December 20, 2015 20:49
1, 6, f, 1c, 2d, 42, 5b, 78, 99 What is the first term of this hex sequence that is at least 9 digits and composed only of letters (a-f)?
#x = ['1', '6', 'f', '1c', '2d', '42', '5b', '78', '99']
#x = [ int(i,16) for i in x ]
#for i in x:
# print hex(i)
#print x
#for i in range(1, len(x)):
# print x[i]-x[i-1]
def lessthanf(x):
for i in x:
@ygabo
ygabo / msort.cpp
Created August 8, 2013 08:07
Mergesort sorting algorithm using recursion and vectors.
#include <vector>
#include <iostream>
using namespace std;
void msort(vector<int>&);
void merge(vector<int>&, vector<int>&, vector<int>&);
void print(vector<int>&);
int main(int argc, char* argv[]){
int d[] = { 1, 3, 5, 4, 12, 23, 11, 12, 0};
@ygabo
ygabo / palindrome.cpp
Created July 12, 2013 10:36
Check if palindrome
#include <iostream>
#include <string>
using namespace std;
bool is_pal( string x ){
int j = x.length()-1;
for( int i = 0; i < x.length()-1; ++i){
if( x[i] != x[j--]) return false;
}
@ygabo
ygabo / reverse.cpp
Last active December 19, 2015 16:19
Reverse string.
#include <iostream>
#include <string>
using namespace std;
void rev(string &x){
int j = x.length()-1;
for( int i = 0; i < x.length()/2; ++i){
swap(x[i], x[j--]);
}
#include "sorter.hpp"
using namespace std;
int main(){
int d[] = {0,1,2,5,5,5,6,5,5};
vector<int> x(begin(d), end(d));
srand(time(0));
Sorter s(x);
s.print();
s.quicksort();
@ygabo
ygabo / hanoi.cpp
Created July 1, 2013 02:34
Towers of Hanoi solver
#include "hanoi.hpp"
Hanoi::Hanoi(){
x = 4;
for( int i = x-1; i >= 0; --i)
peg[0].push(i);
}
Hanoi::Hanoi(int n){
x = n;
@ygabo
ygabo / anagrams.cpp
Last active December 18, 2015 23:39
Get all the anagrams of a word. (Given a dictionary)
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
@ygabo
ygabo / getset.cpp
Created June 25, 2013 21:53
How many subsets in the current set have all the elements but one sum up to the last element.
#include <iostream>
#include <vector>
using namespace std;
int xcount = 0;
void getset( int i, int j, vector<int> nums, int sum){
if( j >= i ) return ;
if( sum+nums[j] == nums[i] ){
xcount++;
@ygabo
ygabo / ransom.cpp
Last active December 18, 2015 12:39
Ransom note
#include <iostream>
#include <string>
#include <map>
using namespace std;
bool ransom( string note, string mag ){
if( mag.empty() ) return false;
if( note.empty()) return true;
int length = note.length();
int length_mag = mag.length();
@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) {}