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 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 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
//文字列で構成された配列から、大文字の数をカウントし配列毎に改行して表示する | |
//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 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
//ランダムにユーザーデータを作成 | |
//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) |
NewerOlder