Skip to content

Instantly share code, notes, and snippets.

@crouch74
crouch74 / balanced parentheses
Created August 9, 2017 13:25
balanced parentheses js solution
function isValid(s) {
var stack = [];
for (var i = 0; i < s.length; i++) {
var c = s[i];
if (c == '(' || c== '[' || c == '{') {
stack.push(c);
continue;
}
if (c == ')' || c== ']' || c == '}') {
var l = stack.pop();
@crouch74
crouch74 / packages.txt
Last active July 8, 2017 19:04
My BoxStarter script
choco install nimbletext
choco install nimbleset
choco install f.lux
choco install notepadplusplus
choco install teracopy
choco install rdcman
choco install fiddler4
choco install linqpad
choco install sandboxie
choco install adobereader-update
@crouch74
crouch74 / flatten
Created May 30, 2015 01:21
Simple reduce and recurse implementation to flatten nested arrays
function flatten(arr) {
return arr.reduce(function(c,l){
return c.concat(Array.isArray(l) ? flatten(l) : l);
},[]);
}
flatten([1, [2], [3, [[4]]]]);
@crouch74
crouch74 / LCM
Created May 30, 2015 01:02
calculate LCM using javascript reduce and recursive GCD calculator
function smallestCommons(arr) {
range = findRange(arr);
return calcRangeLCM(range);
}
function findRange(arr){
//arr=[1,5] ==> res=[1,2,3,4,5]
var res = [];
var min = Math.min.apply(null,arr);
var max = Math.max.apply(null,arr);
for(var i = min; i <=max;i++){
@crouch74
crouch74 / stable arrays difference
Last active August 29, 2015 14:22
difference between two arrays using reduce and the result with the same order (stable)
function diff(arr1, arr2) {
if(arr1.length === 0){
return arr2;
}
if(arr2.length === 0){
return arr1;
}
var newArr = [];
var deletedArr = [];
newArr = arr1.concat(arr2);
@crouch74
crouch74 / anagram_breaker
Last active August 29, 2015 14:17
anagram_breaker ,, please note that this script depends on pygene and written for 2.7 ...
## please note that I was too lazy to write a new script :D ,, so I just edited one of pygene demos :D
## this script is written only for lower case chars ,, change the word you want to hack by changing the variable teststr
import math,random
def stringNorm(s):
norm = 0
for c in s:
if not c==" ":
norm+=math.pow(ord(c),2)
return math.sqrt(norm)