1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

勉強会の参考問題の解答例。groovyで。

Last updated at Posted at 2012-10-10

7/6(金) に行われる予定の勉強会( http://atnd.org/events/30285 )の参考問題( http://qiita.com/items/cbc3af152ee3f50a822f )の解答例、もう一つ。
まだ出てない言語で書こうということで、groovy。

poka.groovy
import java.util.regex.Pattern

def hands=[ "14":"4K", "23":"FH", "113":"3K", "122":"2P", "1112":"1P", "11111":"--" ]
def cardPattern=Pattern.compile( /[SHDC](\d+|J|Q|K|A)/ )

[ "DASAD10CAHA", "S10HJDJCJSJ",
  "S10HAD10DAC10", "HJDJC3SJS3",
  "S3S4H3D3DA", "S2HADKCKSK",
  "SASJDACJS10", "S2S10H10HKD2",
  "CKH10D10H3HJ", "C3D3S10SKS2",
  "S3SJDAC10SQ", "C3C9SAS10D2"].each(
{ q->
  m=cardPattern.matcher( (CharSequence)q )
  ranks=[:].withDefault{0}
  while( m.find() ){
    ++ranks[m.group(1)]
  }
  println( hands[ranks.values().sort().join()] )
} )

投稿のプレビューをみて初めて気づいたんだけど、シンタックスハイライト可能な言語リストに groovy が入っていない。

scala も coffeescript もあるのに groovy がないなんて。

それはさておき、java の正規表現ライブラリの使い方の勉強になった気がするが、実装内容としては新味がない。そんなものだと思う。

1
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?