This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numList = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
var NOT_FOUND = -1; | |
var NOT_SORTED = -2; | |
function search(list, num) { | |
var start = 0; | |
var end = list.length - 1; | |
while (true) { | |
if (start === end && list[start] !== num) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var combo = (function() { | |
var charList; | |
function doCombo(buffer, start) { | |
for (var i = start; i < charList.length; i++) { | |
buffer.push(charList[i]); | |
console.log(buffer.join('')); | |
doCombo(buffer, i + 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var combo = (function() { | |
var limit = 0; | |
function doCombo(charList, buffer, level, start) { | |
if (level === limit) { | |
console.log(buffer.join(' * ')); | |
return; | |
} | |
for (var i = start; i < charList.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
PrintFactors(12) | |
12 * 1 | |
6 * 2 // 2 * 6 ( 2 * 2 * 3) | |
4 * 3 | |
3 * 2 * 2 ( 3 * 4) | |
PrintFactors(32) | |
32 * 1 | |
16 * 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable tab completion | |
source ~/git-completion.bash | |
# colors! | |
green="\[\033[0;32m\]" | |
blue="\[\033[0;34m\]" | |
purple="\[\033[0;35m\]" | |
reset="\[\033[0m\]" | |
# Change command prompt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a + permute(b, c, d); | |
// a + b + permute(c, d); | |
// a + c + permute(b, d); | |
// a + d + permute(b, c) | |
function permute(str) { | |
var used = new Array(4); | |
var list = str.split(''); | |
var out = []; | |
doPermute(used, list, 0, out); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Permute { | |
public static void main(String args[]) { | |
permute(args[0]); | |
} | |
public static void permute(String list) { | |
boolean[] used = new boolean[list.length()]; | |
char[] in = list.toCharArray(); | |
StringBuffer out = new StringBuffer(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* It gets an array of top k maximum or minimum elements from the given integer array | |
* For example, findFirstK([2, 10, 1, 3, 4 ,6, 7], 3) returns [10, 7, 6], the top 3 maximum values from the array in the descending order | |
* or findFirstK([2, 10, 1, 3, 4, 6, 7], 3, true) return [1, 2, 3] | |
*/ | |
function shift(arr, k, value, asc) { | |
if (k > arr.length - 1) { | |
return; | |
} |
NewerOlder