LoginSignup
3
3

More than 5 years have passed since last update.

Scalaの進捗どうですか

Last updated at Posted at 2015-08-03

最近Scalaを勉強していて、Qiitaの進捗どうですかシリーズにScalaがなさそうだったので練習がてら書いてみた。

sinchoku.scala
import scala.util.Random

val a = Array("進捗", "どう", "です", "か")
val goal = s".*${a.mkString}".r

def doudesuka(text: String): String = {
  text match {
    case goal() => text + "???"
    case _ => doudesuka(text + Random.shuffle(a.toList).head)
  }
}

val text = doudesuka("")
println(text)
println(text.size + "文字で煽られました")

どうですどうどうですですか進捗かどう進捗かか進捗かかです進捗進捗です進捗ですどうどうどうかどう進捗進捗進捗どう進捗どうどうですどうか進捗ですどうかですですですどうかですです進捗かかですかかどう進捗進捗どう進捗か進捗ですどうかどうです進捗か進捗進捗進捗進捗どうかかか進捗進捗か進捗どうかどうかですかかです進捗ですかかかかですどうです進捗どうですか???
175文字で煽られました

なるべくScalaっぽさを出すためにループは使わなかったりmatchを使うようにしてみた。
Scala詳しい方はレビューしていただければ嬉しいです。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3