SHARE
TWEET

Untitled

a guest Sep 14th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. val edges = List(
  2.   "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC",
  3.   "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS",
  4.   "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO",
  5.   "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP",
  6.   "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN",
  7.   "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY",
  8.   "AA", "AE", "AP"
  9. ).groupBy(_(0)).mapValues(_.map(_(1)).toSet)
  10.  
  11. var bestLenSoFar = 0
  12. def search(current: List[Char], visited: Set[(Char, Char)]): Unit = {
  13.   if (current.size > bestLenSoFar) {
  14.     println(current.size + ": " + current.reverse.mkString(""))
  15.     bestLenSoFar = current.size
  16.   }
  17.   val x = current(0)
  18.   edges.getOrElse(x, Set.empty).filterNot(y => visited.contains((x, y))).foreach { y =>
  19.     search(y :: current, visited + ((x, y)))
  20.   }
  21. }
  22.  
  23. edges.keySet.foreach(x => search(List(x), Set.empty))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top