Skip to content

Instantly share code, notes, and snippets.

@irof
Created August 12, 2011 13:56
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 irof/1142079 to your computer and use it in GitHub Desktop.
Save irof/1142079 to your computer and use it in GitHub Desktop.
お題:文字列を先頭から見て同じところまで除去
def hoge(String... args) {
def i = -1, v = ''
while(++i < args*.size().min() && args.every{it[i] == args[0][i]}) {
v += args[0][i]
}
args*.minus(v)
}
assert hoge('123', '123') == ['','']
assert hoge('112233', '123123') == ['12233', '23123']
assert hoge('なまむぎ', 'なまごめ', 'なまたまご') == ['むぎ', 'ごめ', 'たまご']
assert hoge('abcde', 'abcdefg') == ['', 'fg']
assert hoge('abcdefg', 'abcde') == ['fg', ''] // 追加したテスト
// お題
assert hoge('abcdef', 'abc123') == ['def', '123']
assert hoge("あいうえお", "あいさんさん", "あいどる") == ["うえお", "さんさん", "どる"]
assert hoge("12345", "67890", "12abc") == ["12345", "67890", "12abc" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment