Skip to content

Instantly share code, notes, and snippets.

@adampolar
adampolar / threewaypartition.go
Created January 29, 2019 20:06
Three way partition
package main
func threeWayPartitionAlgo(ints []int) {
intsFromLeft := 0
intsFromRight := len(ints) - 1
initial := ints[0]
cmpIndex := intsFromLeft + 1
vacations := 0
for intsFromLeft != intsFromRight-vacations {
if ints[cmpIndex] < initial {
@adampolar
adampolar / makePerformanceGraphs.sh
Last active August 24, 2018 14:23
Quick and dirty shell script to get some pngs from the go test tool and pprof
#!/bin/bash
#get file name
number=0
suffix="$( printf -- '-%02d' "$number" )"
while test -e "memprofile$suffix.png" || test -e "cpuprofile$suffix.png" || test -e timeprofile$suffix.txt; do
((++number))
suffix="$( printf -- '-%02d' "$number" )"
@adampolar
adampolar / index.js
Created March 10, 2017 11:17
"Your scientists were so preoccupied with whether or not they could... they didn’t stop to think if they should."
function addRecursive(a, compute) {
return compute? a : (b, compute2) =>addRecursive(a + b, compute2);
}
console.log(addRecursive(1)(1)(15)(6)(10)(2, true)); //35