LoginSignup
1
0

More than 5 years have passed since last update.

Googleの入社試験(非公式)にGroovyでチャレンジしてみる

Last updated at Posted at 2017-02-20

概要

@megmism さんの 「Googleの入社試験(非公式)にチャレンジしてみた[java]」 を見て、試されている気がしたので、特に書けるわけでもない Groovy で書いてみました。

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

雑すぎる上にまったく Groovy のよさがないコードですみません。もっと Groovy っぽい書き方をお教えください :bow:

Gist 連携

投稿する際に「Gist に投稿する」のチェックを入れると、連携している GitHub アカウントの Gist に自動でコードを投稿してくれる機能が Qiita にあると知りました。連携先はこちら

詳細は以下をご覧ください。

1
0
3

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
1
0