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
int fordFulkerson(int n, int s, int t) { | |
//ASSUMES: cap[u][v] stores capacity of edge (u,v). cap[u][v] = 0 for no edge. | |
//Initialise the flow network so that fnet[u][v] = 0 for all u,v | |
int flow = 0; //no flow yet | |
while (true) { | |
//Find an augmenting path using BFS | |
int[] prev = new int[n]; | |
Arrays.fill(prev, -1); | |
LinkedList<Integer> queue = new LinkedList<Integer>(); |
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
int m, n; | |
boolean[][] graph; | |
boolean seen[]; | |
int matchL[]; //What left vertex i is matched to (or -1 if unmatched) | |
int matchR[]; //What right vertex j is matched to (or -1 if unmatched) | |
int maximumMatching() { | |
//Read input and populate graph[][] | |
//Set m to be the size of L, n to be the size of R | |
Arrays.fill(matchL, -1); |
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
import org.junit.runner.RunWith | |
import org.scalatest.junit.JUnitRunner | |
import org.scalatest.FunSuite | |
@RunWith(classOf[JUnitRunner]) | |
class GameOfLifeTest extends FunSuite { | |
type Rules = ((Int, Int, Int)) => Int | |
case class TheRules(rules: List[Int]) extends Rules { |
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
import org.scalatest.FunSuite | |
class MnemonicsDemoSolution extends FunSuite { | |
class Coder(val words: List[String]) { | |
val mnem = Map( | |
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL", | |
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ") | |
/** Invert the mnem map to give a map from chars 'A'...'Z' to '2'...'9' */ | |
val charCode: Map[Char, Char] = |
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
package main | |
import ( | |
"errors" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"math/rand" | |
"os" |