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
package util | |
import java.util.Date | |
import java.text.SimpleDateFormat | |
object DateUtil { | |
implicit class StringToDate(self: String) { | |
/** | |
* フォーマット指定された形式でDate型に変換する | |
* |
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
// コードを読みやすいように名前をつけとこう. | |
val Up = 0 | |
val Right = 1 | |
val Down = 2 | |
val Left = 3 | |
type Direction = Int | |
/* | |
* 石像をあらわすcase class. 像の向きを状態として持つ. | |
* また、一回の動作で向きが90度回転するという振る舞いも定義. |
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
// http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2025 | |
// http://projecteuler.net/problem=25 | |
val fib:Stream[BigInt] = BigInt(1) #:: fib.scanLeft(BigInt(1)){(a, b) => a + b } | |
def getDigits = (n: BigInt) => n.toString.size | |
fib.takeWhile(getDigits(_) <= 1000).zipWithIndex.find(t => getDigits(t._1) == 1000).get._2 + 1 |
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
def maxPrime(n: Int) = { | |
def isPrime(n: Int) = Iterator.from(2).takeWhile(p => p * p <= n).forall(p => n % p != 0) | |
(1 to n).filter(isPrime).max | |
} |
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
(BigInt(100) to BigInt(1) by -1).reduce((x, y) => x * y).toString.toList.map(_.getNumericValue).sum |
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
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 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
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 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
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 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
trait hentaiConverter { | |
implicit def stringToHentaiChecker(s: String) = HentaiChecker(s) | |
case class HentaiChecker(s: String) { | |
def isHentai: Boolean = s == "変態" | |
} | |
} |
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
/** | |
* 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) |