Skip to content

Instantly share code, notes, and snippets.

@omiend
Created September 11, 2014 05:15
Show Gist options
  • Select an option

  • Save omiend/61f95fc3614d64463c1f to your computer and use it in GitHub Desktop.

Select an option

Save omiend/61f95fc3614d64463c1f to your computer and use it in GitHub Desktop.
世界のナベアツあるごりずむ
import scala.collection.immutable.List
object nabeatsuAlgorism {
/**
* 世界のナベアツアルゴリズム
* 3の倍数と3がつく数字のときだけ'アホ'になります
*/
def main(args: Array[String]): Unit = {
// 1~40までの数字に対してmapを実行
List.range(1, 41) map { i =>
// Tupleで(Int, Boolean"Stringのcontainsを利用して3が含まれている場合true")の型に
(i % 3, i.toString.contains("3")) match {
// 3で割り切れる場合
case (0, _) => println(i + "(アホ)")
// 3が含まれる場合
case (_, true) => println(i + "(アホ)")
case _ => println(i)
}
}
println("オモロー!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment