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 combinations | |
"creates combinations of items for example [1 2 3] | |
will generate ((1 2 3) (1 2) (1 3) (1) (2 3) (2) (3) [])" | |
(memoize (fn[items] | |
(if (empty? items) [[]] | |
(let [els (combinations (rest items))] | |
(concat (map #(cons (first items) %)els) els)))))) |
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
package com.masary.util; | |
import java.util.Collection; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.stream.Collectors; | |
/** |
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
package graph; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
import java.util.Stack; | |
public class Reachability { | |
private static int[] pre; | |
private static int[] post; |
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
package graph; | |
import java.util.PriorityQueue; | |
public class GraphSearch { | |
// Priority queue for getting the shortest connected edge | |
PriorityQueue<Node> Q = new PriorityQueue<Node>((n1, n2) -> { | |
if (n1.distance < n2.distance) | |
return -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
package graph; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class ConnectedComponents { | |
private static boolean[] v; | |
private static ArrayList<Integer>[] g; | |
private static int counter = 0; |
NewerOlder