Created
September 11, 2014 05:15
-
-
Save omiend/61f95fc3614d64463c1f to your computer and use it in GitHub Desktop.
世界のナベアツあるごりずむ
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
| 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