Skip to content

Instantly share code, notes, and snippets.

View bruceoutdoors's full-sized avatar
🧗

Lee Zhen Yong bruceoutdoors

🧗
View GitHub Profile
@bruceoutdoors
bruceoutdoors / csv.cpp
Last active December 7, 2015 04:24
Simple CSV file reader. Only reads comma delimited files, though it doesn't take must effort to customize that...
#include "csv.h"
#include <fstream>
#include <sstream>
#include <stdexcept>
Csv::Csv(const string &dir)
{
directory = dir;
read(dir);
}
@bruceoutdoors
bruceoutdoors / mat-chain-mult-dp-trace.cpp
Last active November 18, 2015 09:45
Matrix Chain Multiplication Dynamic Programming Implementation with trace
#include <algorithm>
#include <iostream>
#include <vector>
#include <climits>
#include <string>
using namespace std;
vector<int> rc;
vector< vector<int> > DP, splits;
@bruceoutdoors
bruceoutdoors / mat-chain-mult-dp.cpp
Last active November 17, 2015 16:22
Matrix Chain Multiplication Dynamic Programming Implementation
#include <algorithm>
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
vector<int> rc;
vector< vector<int> > DP;
@bruceoutdoors
bruceoutdoors / mat-chain-mult-recursive.cpp
Last active November 17, 2015 13:03
Matrix Chain Multiplication recursive solution
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
vector<int> rc;
int B(int i, int j)
@bruceoutdoors
bruceoutdoors / generic-lis.cpp
Created November 5, 2015 16:34
Generic longest increasing subsequence (LIS) dynamic programming solution (O(n^2) time)
#include <iostream>
#include <functional>
#include <deque>
#include <vector>
using namespace std;
template<typename T>
deque<T> find_lis(const vector<T> &a,
function<bool(const T &, const T &)> comp = [&](const T &a, const T &b)->bool { return a < b; })
@bruceoutdoors
bruceoutdoors / meaure-run-time.cpp
Last active November 5, 2015 07:04
Measure running time using chrono (C++11). Enable/disable printing the time by comment/uncomment the __EXE_CLOCK__ macro. This is also solution for Hashmat the Brave Warrior (UVa 10055), excluding the __EXE_CLOCK__ macro.
/*
sample run:
./measure-run-time < source-input.txt
output:
2
4
100
** elapsed time: 0.523ms **
@bruceoutdoors
bruceoutdoors / example-run-sjf.txt
Last active August 29, 2015 14:26
SJF example using input text file. NOTE: The algorithm itself is wrong!!
[bruceoutdoors@BruceManjaro bash]$ ./sjf.sh input.txt
Process Name: P1
Arrival Time: 2
Burst Time: 6
Priority: 7
Process Name: P2
Arrival Time: 1
Burst Time: 8
Priority: 1
@bruceoutdoors
bruceoutdoors / Signal.hpp
Last active December 29, 2017 15:29
Simple implementation of the Signal and Slot (Observer pattern) mechanism.
/**
* Signal.hpp
* - Simple implementation of the Signal and Slot (Observer pattern) mechanism.
* Requires C++11 compatible compiler.
*
* @author Lee Zhen Yong
*/
#pragma once
@bruceoutdoors
bruceoutdoors / TableToTree.js
Created March 8, 2015 12:50
Table To Tree Algorithm implementation in TestComplete JScript
function Leaf(name)
{
this.Name = name;
this.ParentBranch = null;
}
Branch.prototype = new Leaf();
Branch.prototype.constructor = Branch;
Branch.prototype.Super = Leaf.prototype;
@bruceoutdoors
bruceoutdoors / TableToTree.txt
Created March 8, 2015 12:47
Table To Tree Algorithm Pseudocode
TABLE TO TREE ALGORITHM PSEUDOCODE
The algorithm can traverse and read an infinite number of cells of an
infinite number of depth, as it reads the cells in a recursive fashion
with the base case as the leaf of the cells. Note that you should not
think this will work for graphs (there's simply no way you could
represent graphs in a table structure anyway).
Some Notes:
- A cell is either a leaf or a branch.