Skip to content

Instantly share code, notes, and snippets.

@y-sumida
Created January 26, 2013 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-sumida/4640261 to your computer and use it in GitHub Desktop.
Save y-sumida/4640261 to your computer and use it in GitHub Desktop.
package doukaku
class Poker {
final def handPattern = ['14':'4K', '23':'FH', '113':'3K', '122':'2P', '1112':'1P', '11111':'-']
String judge(String hand) {
def eachNumberCount = [:].withDefault {0}
(hand =~ /([2-9AJQK]|10)/).each {
++eachNumberCount[it]
}
def countPattern = ""
eachNumberCount.sort { it.value }.each {
countPattern += it.value
}
handPattern[countPattern]
}
}
package doukaku
import doukaku.Poker
import spock.lang.Specification
import spock.lang.Unroll
class PokerSpec extends Specification {
@Unroll
def "#hand の場合は #result を返す"() {
setup:
Poker sut = new Poker()
expect:
sut.judge(hand) == result
where:
hand |result
"S2HKD10CJCA" |"-"
"S2H3D10DKC2" |"1P"
"S2H3D10D2C10" |"2P"
"SAHAD10DAC2" |"3K"
"SAHAD10DACA" |"4K"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment