Skip to content

Instantly share code, notes, and snippets.

View jyukutyo's full-sized avatar

Koichi Sakata jyukutyo

View GitHub Profile
@jyukutyo
jyukutyo / gist:5149355
Created March 13, 2013 04:21
CheckStyleの設定ファイル
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the sun coding conventions from:
- the Java Language Specification at
@jyukutyo
jyukutyo / gist:4705331
Created February 4, 2013 06:50
ランダムな文字列を生成するワンライナー
ruby -e 'puts (("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..32].join'
@jyukutyo
jyukutyo / gist:4601010
Created January 23, 2013 01:44
Project Euler Problem 9 Answer
import java.text.DecimalFormat
object Problem9 extends App {
for (a <- 1 to 1000; b <- 1 to 1000) yield {
val total = math.pow(a, 2) + math.pow(b, 2)
val c = math.sqrt(total).floor
val t = c * c
@jyukutyo
jyukutyo / gist:4520576
Created January 12, 2013 21:32
Project Euler Problem 6 Answer(improved)
object Problem6 extends App {
val numbers = 1 to 100
def square(n: Int) = n * n
val r = square(numbers.sum) - numbers.map(square).sum
Console.println(r)
@jyukutyo
jyukutyo / gist:4520565
Last active December 11, 2015 00:59
Project Euler Problem 8 Answer(improved)
object Problem8 extends App {
val target = "73167176531330624919225119674426574742355349194934" +
"96983520312774506326239578318016984801869478851843" +
"85861560789112949495459501737958331952853208805511" +
"12540698747158523863050715693290963295227443043557" +
"66896648950445244523161731856403098711121722383113" +
"62229893423380308135336276614282806444486645238749" +
"30358907296290491560440772390713810515859307960866" +
"70172427121883998797908792274921901699720888093776" +
@jyukutyo
jyukutyo / gist:4520557
Created January 12, 2013 21:25
Project Euler Problem 8 Answer
object Problem8 extends App {
val target = "73167176531330624919225119674426574742355349194934" +
"96983520312774506326239578318016984801869478851843" +
"85861560789112949495459501737958331952853208805511" +
"12540698747158523863050715693290963295227443043557" +
"66896648950445244523161731856403098711121722383113" +
"62229893423380308135336276614282806444486645238749" +
"30358907296290491560440772390713810515859307960866" +
"70172427121883998797908792274921901699720888093776" +
@jyukutyo
jyukutyo / gist:4510750
Created January 11, 2013 13:41
Project Euler Problem 7 Answer
object Problem7 extends App {
lazy val ps: Stream[Int] = 2 #:: Stream.from(3).filter(
i => {
// 素数だけのリストを作る。jはiの平方根より小さい数で、iが割り切れる数である。
ps.takeWhile(j => { j * j <= i }).forall(i % _ > 0)
}
)
Console.println(ps.take(10001).last)
@jyukutyo
jyukutyo / gist:4510684
Created January 11, 2013 13:33
Project Euler Problem 6 Answer
import java.text.DecimalFormat
object Problem6 extends App {
val a = math.pow(1 to 100 sum, 2)
val b = 1 to 100 map(math.pow(_, 2)) sum
val formatter = new DecimalFormat("#")
Console.println(formatter.format(a - b))
@jyukutyo
jyukutyo / gist:4506098
Created January 10, 2013 21:50
Project Euler Problem 5 Answer(improved)
Range(20, Int.MaxValue)
.find(n => Range(2, 21).forall(n % _ == 0)).get
@jyukutyo
jyukutyo / gist:4423812
Created December 31, 2012 23:26
Project Euler Problem 5 Answer
object Problem5 extends App {
lazy val ps: Stream[Int] = 2 #:: Stream.from(3).filter(
i => {
// 素数だけのリストを作る。jはiの平方根より小さい数で、iが割り切れる数である。
ps.takeWhile(j => { j * j <= i }).forall(i % _ > 0)
}
)
val limit = 20