Created
June 18, 2014 00:02
-
-
Save krishnanraman/107b5db2269f5032d1a2 to your computer and use it in GitHub Desktop.
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
// See https://news.ycombinator.com/item?id=7856135 | |
object zsb extends App { | |
type T = (Int,Int,Int) | |
def ok(zsb:T) = { val (z,s,b) = zsb; z>=0 && s>=0 && b>=0 } | |
def parse(s:String) = { val arr = s.split(",").map(s=> s.toInt); (arr(0), arr(1), arr(2)) } | |
def buyout(zsb:T, set:Set[T]):Set[T] = { | |
val (z,s,b) = zsb // z zombie, s startup, b bigcorp | |
val ret = Set((z-1, s-1, b+1), (z-1,s+1,b-1), (z+1,s-1,b-1)) | |
.filter(ok) | |
.diff(set) | |
if (ret.size > 0) set ++ ret else set | |
} | |
def loop(zsb:T, set:Set[T]):Unit = { | |
val newset = buyout(zsb,set) | |
if ( newset != set) { | |
//println(newset.size) | |
//newset.foreach(println) | |
newset.foreach { e => loop(e,newset) } | |
} //else { | |
println(newset.size) | |
newset.foreach(println) | |
//} | |
} | |
loop(parse(args(0)), Set[T]()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment