Created
January 6, 2015 08:50
-
-
Save Yachida/838b86a79f6a5b81f244 to your computer and use it in GitHub Desktop.
逆から読んでも日付になる4桁の数値
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 java.text._ | |
| object dateCheck extends App { | |
| def isDate(str: String): Boolean = { | |
| val d = new SimpleDateFormat("yyyyMMdd") | |
| d.setLenient(false) | |
| try { | |
| d.parse("2000"+str) | |
| true | |
| } catch { | |
| case e:Exception => false | |
| } | |
| } | |
| Range(0,10000) | |
| .map(i => "%04d".format(i)) | |
| .filter(i => isDate(i) && isDate(i.reverse)) | |
| .foreach(i => println(i)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment