からだのブログ

五体満足に生まれてきたことに感謝してブログの名前を「からだ」にしました。

からだのブログ header image 4

Entries Tagged as 'Scala'

run length encoding

10月 21st, 2012 · 1 Comment · programming, Scala

run length encoding って、手続型で書くの面倒だよね。というか、手続型で書くこと考えるの面倒くさくていやだよ。 Scalaちゃんで解いてみる。 scala> def runlength[T](li […]

[Read more →]

Tags:

数を数える

10月 15th, 2012 · No Comments · programming, Scala

よくありがちな処理。リストの要素の数をそれぞれいくつあるか数える。 scala> val list = List(1,2,2,1,4,2,3,1) list: List[Int] = List(1, 2, 2, 1 […]

[Read more →]

Tags:

def pascal(n: Int)

11月 27th, 2011 · No Comments · programming, Scala

パスカルの三角形の n 段目(0-origin)を求める。 def pascal(n: Int): IndexedSeq[Int] = {   val pre = if(n == 0) IndexedSeq(1) els […]

[Read more →]

Tags:

do/while

10月 9th, 2011 · No Comments · Scala

Scala で do/while が予約語だなんて、今まで知らなかった。 つーか、そんなダサい構文なくても問題にならん。さすが Scala ちゃん。

[Read more →]

Tags:

WordCount.scala

5月 15th, 2011 · 2 Comments · programming, Scala

stdin からの入力に含まれる「単語」を辞書順に並べて、出現した行番号と一緒に出力するプログラム。Scala で。 object WordCount extends Application { val lines = […]

[Read more →]

Tags:

Project Euler + Scala #8

5月 24th, 2010 · No Comments · projectEuler, Scala

今更だろうが Project Euler っていう数学の問題が大量に集められたサイトがある。 それを Scala で解くのがすごく楽しい。例えばこんな問題。 #8 「Find the greatest product o […]

[Read more →]

Tags: