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
case class irof (formula: Boolean)(irofBlock: => Unit) { | |
formula match { | |
case true => irofBlock | |
case _ => | |
} | |
def elof(elofBlock: => Unit): Unit = { | |
formula match { | |
case false => elofBlock |
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
List list = [ | |
[color:"blue", weight:10], | |
[color:"red", weight:30], | |
[color:"blue", weight:50], | |
] | |
// Javaで | |
int weight1 = 0; | |
for (def e : list) { | |
if ("blue".equals(e.color)) |
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
trait hentaiConverter { | |
implicit def stringToHentaiChecker(s: String) = HentaiChecker(s) | |
case class HentaiChecker(s: String) { | |
def hentaiPower: Int = { | |
import scala.io.Source | |
val contents = Source.fromURL("http://www.google.co.jp/search?q=変態+%s".format(s), "utf8").getLines.mkString | |
val searchCountPattern = "約? ?([0-9,]+) ?件".r |
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
trait hentaiConverter { | |
implicit def stringToHentaiChecker(s: String) = HentaiChecker(s) | |
case class HentaiChecker(s: String) { | |
def isHentai: Boolean = s == "変態" | |
} | |
} |
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
/** | |
* http://projecteuler.net/problem=16 | |
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2016 | |
*/ | |
val pow = (base: Int, n: Int) => { | |
def calc(base: Int, n: Int, summary: BigInt): BigInt = { | |
n match { | |
case 1 => summary * base | |
case _ => calc(base, n - 1, summary * base) |
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
/** | |
* http://projecteuler.net/problem=14 | |
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2014 | |
*/ | |
object collatz { | |
def apply(i: Int) = calc(i :: Nil).reverse | |
private def calc(xs: List[Long]): List[Long] = { |
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
/** | |
* http://projecteuler.net/problem=13 | |
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2013 | |
*/ | |
val xs = List( | |
BigInt("37107287533902102798797998220837590246510135740250"), | |
BigInt("46376937677490009712648124896970078050417018260538"), | |
BigInt("74324986199524741059474233309513058123726617309629"), | |
BigInt("91942213363574161572522430563301811072406154908250"), |
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
/** | |
* http://projecteuler.net/problem=12 | |
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2012 | |
*/ | |
def numbers(n: Long): Stream[Long] = n #:: numbers(n + 1L) | |
val triangle = numbers(2L).scanLeft(1L){(a,b) => a + b } | |
val divisors = (n: Long) => { |
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
/** | |
* http://projecteuler.net/problem=11 | |
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2011 | |
*/ | |
val xs: List[List[Int]] = List( | |
List(8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8), | |
List(49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0), | |
List(81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65), | |
List(52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91), |
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
/** | |
* http://projecteuler.net/problem=9 | |
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%209 | |
*/ | |
def triplesOfTotal1000: List[(Int, Int, Int)] = { | |
def search(a: Int, b: Int, c: Int, xs: List[(Int, Int, Int)]): List[(Int, Int, Int)] = { | |
val ys = if (a + b + c == 1000) (a, b, c) :: xs else xs |