夏サミポスター用サンプルコード

11 views
Skip to first unread message

k-kuwana

unread,
Jul 16, 2013, 12:08:32 PM7/16/13
to jg...@googlegroups.com
はじめまして。桑名と申します。
まずは誰かが・・・ということで先日勉強のために書いたスクリプトを。
Groovyっぽくはないかも?

START -------------------------------
import static org.codehaus.groovy.tools.Utilities.*
def headersCollecter(List strings){
    if(strings.any{ it == [] })
        []
    else
        [strings.collect{it.head()}] + headersCollecter(strings.collect{it.tail()})
}

def sentences = ["あいうえお", "かきくけこ", "夏です", "あつい !"]
def maxLength = sentences.max( {a, b -> a.length() <=> b.length()} ).size()
def padString = sentences.any({it.getBytes().length > 1}) ? " " : " "
def newStrings = sentences.collect{ String sentence ->
    sentence.padRight(maxLength, padString).toList()
}

def result = headersCollecter(newStrings).collect{it.reverse(false)}.collect{it.join()}
assert ["あ夏かあ", "つできい", "いすくう", "  けえ", "! こお"] == result
assert """\
あ夏かあ
つできい
いすくう
  けえ
! こお\
""" == result.join(eol()).normalize()

result.each{println it}

END -----------------------------------

UEHARA Junji

unread,
Jul 17, 2013, 10:03:40 AM7/17/13
to JGGUG
桑名さん、
上原です。
ご応募ありがとうございます。
厳選たる審議の上、柄として採用とさせて頂くことを通知
させて頂きます。
楽しみにしてください。
ありがとうございました。



2013年7月17日 1:08 k-kuwana <saba...@gmail.com>:

--
このメールは Google グループのグループ「JGGUG」の登録者に送られています。
このグループから退会し、メールの受信を停止するには、jggug+un...@googlegroups.com にメールを送信します。
このグループに投稿するには、jg...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/jggug からこのグループにアクセスしてください。
その他のオプションについては、https://groups.google.com/groups/opt_out にアクセスしてください。
 
 



--
UEHARA Junji
Reply all
Reply to author
Forward
0 new messages