Skip to content

Instantly share code, notes, and snippets.

View khoatle's full-sized avatar

Khoa Le khoatle

  • Microsoft @Azure
  • Redmond, WA
View GitHub Profile
@khoatle
khoatle / 0_reuse_code.js
Last active August 29, 2015 14:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
import java.util.*;
public class AlienLanguage {
private static class Token {
Set<Character> validChars = new HashSet<Character>();
public Token(String string) {
for(int i = 0; i < string.length(); i++) {
@khoatle
khoatle / GeneratePalindrome.java
Created April 14, 2013 07:01
Generate a palindrome sequence of size N
import java.util.*;
public class GeneratePalindrome {
public static List<String> palindromesOfLength(int N, Set<String> alphabet) {
List<String> result = new ArrayList<String>();
if(N == 1) {
for(String letter : alphabet) {
result.add(letter);
}
import java.util.Scanner;
public class Yeehaa {
public double findr(double R, int N) {
double theta = Math.PI * 2 / N;
double b = Math.sqrt(R * R + R * R - 2 * R * R * Math.cos(theta));
return b * R / (b + 2 * R);
}
import java.util.*;
public class DNASorting {
public static class DNA implements Comparable {
String dna;
public DNA(String str) {
dna = str;
}
@khoatle
khoatle / longest.cpp
Created May 20, 2013 06:34
Given two input texts, find the longest string that occurs in both.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
string longest_in_both(const string& s1, const string& s2) {
vector<vector<int> > dp;
for(int i = 0; i < s1.length(); i++) {
dp.push_back(vector<int>(s2.length(), -1));