Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Last active August 29, 2015 14:04
Show Gist options
  • Save jackliusr/3b0294f27e9957cc6ba9 to your computer and use it in GitHub Desktop.
Save jackliusr/3b0294f27e9957cc6ba9 to your computer and use it in GitHub Desktop.
Hackerrank Utopian Tree in scala
object Solution {
def main(args: Array[String]) {
val lines = io.Source.stdin.getLines().filter(_.length > 0).drop(1)
val nums = lines.map(_.toInt)
nums.foreach( n => println( (0 to n).fold(0)( (acc, n) => if(n %2 == 0) acc +1 else acc *2 )) )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment