Skip to content

Instantly share code, notes, and snippets.

# Michael Haufe mlhaufe

Created April 9, 2014 04:41
Greedy Change Making Algorithm
This file contains 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 qapik = [50,20,10,5,3,1], usCoins = [25,10,5,1]; //denominations (ds) must be in descending order function makeChange(coins,ds){ var result = {} for(var i = 0, d = ds[i]; i < ds.length; d = ds[++i]){ result['n'+d] = Math.floor(coins/d) // a div d coins = coins % d }
Created April 16, 2014 05:06
Max Subsequence Sum
This file contains 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 xs = [-4,-3,-7,+2,+1,-1,-4], //[2,1] = 3 ys = [-2,11,-4,13,-5,-2], //[11,-4,13] = 20 zs = [5,15,-30,10,-5,40,10,-8] // [...] = 55 function sum(j,as){ var max = Math.max; function tabulate(i,runMax,curMax){ if(i > j) return curMax var newMax = max(runMax+as[i],as[i]) return tabulate(i + 1, newMax, max(curMax,newMax))
Created April 16, 2014 08:40
Count inversions in an array
This file contains 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 countInversions(xs){ var count = 0; function mergeSort(xs){ var size = xs.length if (size < 2) return xs var mid = Math.floor(size / 2), left = xs.slice(0, mid), right = xs.slice(mid)
Last active August 29, 2015 14:01
Tiny File System
This file contains 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
 04425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E25000000
Created July 17, 2014 19:04
Active Directory from LINQPad
This file contains 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 searchRoot = new System.DirectoryServices.DirectoryEntry( @"LDAP://server:389/DC=foo,DC=com", @"DOMAIN\USERNAME", "PASSWORD" ){ AuthenticationType = AuthenticationTypes.ReadonlyServer }; using(var searcher = new System.DirectoryServices.DirectorySearcher(searchRoot)) { searcher.Filter = "(&(objectCategory=group))"; var results = searcher.FindAll(); results.Dump();
Last active August 29, 2015 14:06
This file contains 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
 Click-Through Circle
Last active August 29, 2015 14:12
Lapis Design Notes
This file contains 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
 module exports Bool protocol Bool False True and Bool => Bool or Bool => Bool not => Bool
Created June 22, 2015 00:54
This file contains 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
 insert(X, Xs, [X|Xs]). insert(E, [X|Xs], [X|Ys]) :- insert(E,Xs,Ys). permute([],[]). permute(L,[H|T]) :- insert(H,R,L), permute(R,T). sudoku([[X11,X12,X13,X14,X15,X16,X17,X18,X19], [X21,X22,X23,X24,X25,X26,X27,X28,X29], [X31,X32,X33,X34,X35,X36,X37,X38,X39], [X41,X42,X43,X44,X45,X46,X47,X48,X49],
Created June 22, 2015 00:55
Pathfinding
This file contains 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
 adjacent(ems,phy). adjacent(ems,soccer). adjacent(soccer,cunn). adjacent(ems,chem). adjacent(chem,lap). adjacent(lap,bridge). adjacent(lap,arch). adjacent(arch,engel). adjacent(cunn,engel). adjacent(bridge,union1).
Last active September 29, 2015 02:08
WSH Quick DOM
This file contains 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