step1
パラメータを受け取るコントローラを作る
object Application extends Controller {
def parameterExample(parameter: String) = Action {
Ok(views.html.index(parameter))
}
}
def qSort[T <% Ordered[T]](data: List[T]): List[T] = { | |
data match { | |
case Nil => data | |
case x::xs => { | |
qSort(xs.filter(_ < x)) ++ List(x) ++ qSort(xs.filter(x <= _)) | |
} | |
} | |
} | |
qSort(List(2, 44, 5, 3, 1, 3, 9, 56, 7, 8, 4, 111, 0, 3, 4)) foreach println |
def bubbleSort(arr: Array[Int]): Array[Int] = { | |
for(i <- 0 until arr.length - 1; j <- 0 until arr.length - 1 - i) { | |
if (arr(j) > arr (j + 1)) { | |
val temp = arr(j) | |
arr(j) = arr(j + 1) | |
arr(j + 1) = temp | |
} | |
} | |
arr | |
} |
class MyException(message: String, cause: Throwable) extends RuntimeException(message, cause) { | |
def this() = this(null, null) | |
def this(message: String) = this(message, null) | |
def this(cause: Throwable) = this(null, cause) | |
} |
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant::Config.run do |config| | |
# All Vagrant configuration is done here. The most common configuration | |
# options are documented and commented below. For a complete reference, | |
# please see the online documentation at vagrantup.com. | |
# Every Vagrant virtual environment requires a box to build off of. | |
config.vm.box = "centos64_64" |
step1
パラメータを受け取るコントローラを作る
object Application extends Controller {
def parameterExample(parameter: String) = Action {
Ok(views.html.index(parameter))
}
}
package util | |
import java.util.Date | |
import java.text.SimpleDateFormat | |
object DateUtil { | |
implicit class StringToDate(self: String) { | |
/** | |
* フォーマット指定された形式でDate型に変換する | |
* |
// コードを読みやすいように名前をつけとこう. | |
val Up = 0 | |
val Right = 1 | |
val Down = 2 | |
val Left = 3 | |
type Direction = Int | |
/* | |
* 石像をあらわすcase class. 像の向きを状態として持つ. | |
* また、一回の動作で向きが90度回転するという振る舞いも定義. |
// 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 |
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 | |
} |
(BigInt(100) to BigInt(1) by -1).reduce((x, y) => x * y).toString.toList.map(_.getNumericValue).sum |