Created
June 5, 2012 03:56
-
-
Save sakamotodesu/2872538 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
import io.Source | |
object Main { | |
val toFizzBuzz = ((x:Int) => (x%3,x%5) match { | |
case (0,0) => "fizzbuzz" | |
case (0,_) => "fizz" | |
case _ => "buzz" | |
}) | |
val isFizzBuzz = ((x:Int) => x%3 ==0 || x%5 ==0) | |
val fizzbuzz = new PartialFunction[Int,String] { | |
def isDefinedAt(x:Int) = isFizzBuzz(x) | |
def apply(x:Int) = toFizzBuzz(x) | |
} | |
def main(args: Array[String]) { | |
//print((1 to 10).map(x => x * 15).collect(fizzbuzz)) | |
//print((2 to 12).map(x => (x * 15 to x * 15 + 10).collect(fizzbuzz))) | |
val lines = Source.fromFile("C:\\temp\\test.txt").getLines().toList | |
print(lines) | |
print(fizzbuzz(4)) | |
} | |
def inverse(list:List[String]):(Int,Int) = { | |
def iter(l:List[String],n:Int):(Int,Int) = | |
val m = next(n) | |
match { | |
case l.head => iter(tail,n+1) | |
case _ => Nil | |
} | |
list match { | |
case "fizz"::tail => iter(list,3) | |
case "buzz"::tail => iter(list,5) | |
case "fizzbuzz"::tail => iter(list,15) | |
} | |
} | |
def explore(l:List[String],n:Int):(Int,Int)={ | |
} | |
def next(n:Int):Int = { (n to n+5).map(isFizzBuzz).head} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
inverse find next explore