Skip to content

Instantly share code, notes, and snippets.

View yasith's full-sized avatar
🐢

Yasith Vidanaarachchi yasith

🐢
  • Google
  • Toronto, Canada
  • 00:57 (UTC -04:00)
View GitHub Profile
@yasith
yasith / CasketOfStars.cpp
Created February 18, 2012 19:34
SRM 533: Casket of Stars
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
@yasith
yasith / MinimumLiars.cpp
Created March 31, 2012 15:35
TCO'11 Qual 1
int MinimumLiars::getMinimum(vector <int> claim) {
for (int i=0;i<claim.size();i++){
int count=0;
for (int j=0;j<claim.size();j++)
if(claim[j]>i+1)
count++;
if (count==i+1)
return i+1;
}
@yasith
yasith / gist:2338534
Created April 8, 2012 17:09
Variable Passing Example
class FrameOne extends JFrame{
private void init(){
FrameTwo f = new FrameTwo("Hi");
f.setVisible(true);
}
//main method calls init.
}
@yasith
yasith / prefixsums.py
Created April 12, 2012 04:10
PrefixSums
1 def rec(L, p=0):
2 ans = []
3 if p > len(L):
4 return ans
5
6 ans.append(sum(L[:p]))
7 ans += rec(L, p+1)
8
9 return ans
@yasith
yasith / merge_sort.py
Created April 18, 2012 01:18
Merge Sort Python
def msort(L):
if len(L) == 1:
return L
m = len(L)/2
return merge(msort(L[:m]), msort(L[m:]))
def merge(left, right):
@yasith
yasith / permute.py
Created April 19, 2012 19:22
Permutations
def permute(L):
if len(L) == 1:
return [L]
ret = []
for i in range(len(L)):
X = permute(L[:i] + L[i+1:])
for sub_list in X:
@yasith
yasith / powerset.py
Created April 20, 2012 02:52
PowerSet
def powerset(L):
ret = [tuple(L)]
if len(L) == 0:
return ret
for i in range(len(L)):
ret += powerset(L[:i] + L[i+1:])
@yasith
yasith / exam.py
Created April 20, 2012 23:33
2009 Final 5a CSC148
class EmptyQueueException(Exception):
pass
class LinkedListQueueNode:
def __init__(self, data):
self._next = None
self._data = data
def set_next(self, n):
self._next = n
@yasith
yasith / AkariDaisukiDiv2.java
Created April 23, 2012 16:56
TopCoder SRM 541 d2 250
import java.util.HashMap;
public class AkariDaisukiDiv2 {
public int countTuples(String S) {
int ans = 0;
HashMap map = new HashMap<String, Integer>();
for(int i = 1; i < S.length(); i++){
@yasith
yasith / AkariDaisukiDiv2.java
Created April 23, 2012 16:56
TopCoder SRM 541 d2 250
import java.util.HashMap;
public class AkariDaisukiDiv2 {
public int countTuples(String S) {
int ans = 0;
HashMap map = new HashMap<String, Integer>();
for(int i = 1; i < S.length(); i++){