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
//ランダムにユーザーデータを作成 | |
//name⇒20文字以内の英字 | |
//age⇒1~100歳 | |
import org.scalacheck.Gen | |
case class User(name:String, age:Int) | |
val userGen = for{ | |
s <- Gen.choose(1,20) | |
n <- Gen.alphaStr | |
a <- Gen.choose(1,100) | |
}yield User(n.take(s),a) |
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
//文字列で構成された配列から、大文字の数をカウントし配列毎に改行して表示する | |
//Java | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
public class Aaa { | |
public static void main(String[] args) { | |
List<String> list = new ArrayList<String>(); |
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
def prime(n:Int) = !(2 to scala.math.sqrt(n).toInt exists(n % _ == 0)) | |
assert(List(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97).filter(prime(_) == false).size == 0) | |
assert(List(4,6,8,9,10).filter(prime(_) == true).size == 0) | |
//2~nまでの素数リスト | |
def plist(n:Int) = 2 to n filter(prime(_) == true) | |
def plist(n:Int) = 2 to n filter(BigInt(_).isProbablePrime(64) == true) |
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
//scalaっぽい素因数分解 | |
import scala.annotation.tailrec | |
object PrimeTest extends App { | |
def primeDec(n: Int) = { | |
@tailrec | |
def r(in: Int, plist: List[Int], result: List[Int] = List()): List[Int] = { | |
plist match { | |
case x :: xs if in % x == 0 => r(in / x, plist, x :: result) | |
case x :: xs if in % x != 0 => r(in, xs, result) |
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
def hb(i1:String,i2:String) = (i1 zip i2).foldLeft((0,0)){(a, b) => if(b._1 == b._2) (a._1+1,a._2) else (a._1,a._2+1)} | |
def s(n:Int) = (1 to n).foldLeft(List("")){(l,_) => List("A","C","G","T").flatMap(x => l.map(_ + x))}.filter(_.contains("AAG")) |
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 sbt._ | |
import Keys._ | |
object ScalaStromBuild extends Build { | |
lazy val root = Project(id = "ScalaStorm", base = file(".")) aggregate (scalaRedis) dependsOn(scalaRedis) | |
lazy val scalaRedis = Project(id = "scala-redis", base = file("scala-redis")) | |
} |
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
package storm.scala.examples | |
import storm.scala.dsl._ | |
import backtype.storm.Config | |
import backtype.storm.LocalCluster | |
import backtype.storm.topology.TopologyBuilder | |
import backtype.storm.tuple.{Fields, Tuple, Values} | |
import com.redis._ | |
import collection.mutable.{Map, HashMap} | |
import util.Random |
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
libraryDependencies += "net.liftweb" %% "lift-json" % "2.4" |
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
この問題を解決するには、 | |
scala> val f:Int => Int = x => x | |
f: (Int) => Int = <function1> | |
この関数に数値を代入して、同じ関数を返す事が出来ないとダメなので解決出来ない。 | |
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
def maxDupStr(str:String) = { | |
def tails:String => List[String] = { | |
case "" => Nil | |
case x => x :: tails(x.tail) | |
} | |
val sorted = tails(str) sorted | |
val pair = sorted zip sorted.tail | |
val maxPair = { | |
pair map { case (s1,s2) => (s1 zip s2 filter {c => c._1 == c._2} size, s1)} max | |
} |
OlderNewer