Created
August 7, 2014 15:07
-
-
Save jackliusr/486708eaf9193a8339fb to your computer and use it in GitHub Desktop.
Hackerrank Is Fibo in scala
This file contains hidden or 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 scala.math.BigInt | |
object Solution { | |
def main(args: Array[String]) = { | |
def fibFrom(a: BigInt, b: BigInt): Stream[BigInt] = a #:: fibFrom(b, a + b) | |
val lines = io.Source.stdin.getLines.drop(1).toList | |
val nums:List[BigInt] = lines.map( l => BigInt(l)) | |
def isFib(n: BigInt):String = { | |
val fs = fibFrom(0,1).takeWhile(f => f <= n).toList | |
if (fs.last < n ) "IsNotFibo" else "IsFibo" | |
} | |
nums.foreach( n => println(isFib(n))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment