Last active
February 20, 2017 09:14
-
-
Save toastkidjp/30d0c66c890e2ac9644beae66ecca778 to your computer and use it in GitHub Desktop.
Googleの入社試験(非公式)にGroovyでチャレンジしてみる ref: http://qiita.com/y_q1m/items/9b8b20cdd9cfea4cc078
This file contains 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
int count = 0 | |
(1..1000000).forEach{it -> | |
String str = Integer.toString(it) | |
for (int i = 0; i < str.length(); i++) { | |
char c = str.charAt(i) | |
if (c == '1') { | |
count++ | |
} | |
} | |
if (it == count) { | |
println it | |
return | |
} | |
} | |
println count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment