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
def coin_change n, d | |
s = Array.new(n+1) {0} | |
s[0] = 0 | |
for i in 1..n | |
s[i] = get_min(s, i, d) + 1 | |
end | |
return s[n] | |
end |
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
B = [ | |
[3], | |
[7,4], | |
[2,4,6], | |
[8,5,9,3] | |
] | |
############# Iterative (bottom up) | |
DP = Array.new(B.length) {Array.new(B.length) {0}} |
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
def sum sol, p | |
s = p[0][0] | |
n = p.length | |
index = sol[0] | |
for i in 1..(n-1) | |
row = p[i] | |
for j in 0..(row.length-1) | |
if j == index |
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
######## | |
# HELPERS | |
######## | |
extend = (protoProps, staticProps) -> | |
parent = this | |
child | |
if (protoProps && _.has(protoProps, 'constructor')) | |
child = protoProps.constructor; | |
else |
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
reverseMe = function(string){ | |
var result = "", | |
arr = string.split(" "); | |
for (var j=0; j <=arr.length-1; j++) { | |
for (var i = arr[j].length - 1; i >= 0; i--) { | |
result += arr[j][i] | |
if (i == 0) result += " "; //put space when EOW | |
}; | |
}; |
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
def first_unique_char(string) | |
count = {} | |
string.split("").each do |char| | |
if count[char] | |
count[char] += 1 | |
else | |
count[char] = 1 | |
end | |
end |
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
function find(string, sub){ | |
var small = sub.split(""); | |
var found = []; | |
var indexes = []; | |
var j = 0; | |
for (i=0; i<=string.length-1; i++){ | |
if( string[i] == small[j] ){ | |
found.push( small[j] ); | |
if(j == 0) |
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
VOWELS = %w{a e i o u} | |
def to_pig (text) | |
text.gsub(/(\A|\s)\w+/) do |str| | |
str.strip! | |
str += str[0] #appends first char | |
kind = (VOWELS.include? str[0]) ? 'vowel' : 'consonant' | |
is_upper = str[0].upcase! #returns nil if str[0] is alredy uppercase |
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
primes = []; | |
memo = [2]; | |
num = 13195; | |
function isPrime(n) { | |
for(i = 0; i <= memo.length; i++){ | |
if (n % memo[i] == 0) | |
return false; | |
} | |
return true; |
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 alphabet = 'abcdefghijklmnopqrstuvwxyz', | |
shipher = [], | |
key, | |
output = []; | |
function generateKey(input, string){ | |
for(var j = 0; j < input.length; j++){ | |
var numRand = Math.floor( Math.random() * (string.length-1) ); //gets a random integer between [0 - alphabet.length] | |
shipher.push( string.charAt(numRand).toUpperCase() ); //appends next char to shipher. | |
} |