Skip to content

Instantly share code, notes, and snippets.

@sungkmi
Created June 20, 2014 13:26
Show Gist options
  • Save sungkmi/1343142b23736b381827 to your computer and use it in GitHub Desktop.
Save sungkmi/1343142b23736b381827 to your computer and use it in GitHub Desktop.
object NewLotteryGame extends App {
def count(a: Long, b: Long, k: Long): Long = {
10
}
def countPairs(less: (Boolean, Boolean, Boolean), bound: List[(Boolean, Boolean, Boolean)]): Long = {
if (bound.isEmpty) {
val (a, b, k) = less
if (a & b & k) 1 else 0
}
val (a, b, k) = bound.head
val maxA = less._1 | a
val maxB = less._2 | b
val maxK = less._3 | k
var count = countPairs((maxA, maxB, maxK), bound.tail)
if (maxA) count += countPairs((less._1, maxB, maxK), bound.tail)
if (maxB) count += countPairs((maxA, less._2, maxK), bound.tail)
if (maxA && maxB && maxK) count += countPairs(less, bound.tail)
count
}
def process(iter: Iterator[String])(output: String => Unit) =
for (i <- 1 to iter.next().toInt) {
val n = iter.next().toInt
val input = Seq.fill(n)(iter.next())
// output(s"Case #$i: ${minMove(input) getOrElse "Fegla Won"}")
}
val writer = new java.io.PrintWriter("b.out")
try {
process(io.Source.fromFile("B-small-practice.in").getLines)(writer.println)
} finally {
writer.flush(); writer.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment