2015년 2월 12일 목요일

groovy 연습 3



// 2015-02-13 11:25:27 (금요일)

// 그루비의 튜토리얼 문서가 부실하다는 느낌을 지울수없다.


"potatoe" ==~ /potatoe/
println "potatoe" ==~ /potatoe/


"potatoe" ==~ /potatoe?/
println "potatoe" ==~ /potatoe?/

"potato" ==~ /potatoe?/
println "potato" ==~ /potatoe?/

"motato" ==~ /potatoe?/
println "motato" ==~ /potatoe?/


// 함수를 정의할때 def 를 쓴다.

def checkSpelling( spellingAttempt, spellingRegularExpression)
{
    if (spellingAttempt ==~ spellingRegularExpression)
    {
        println("철자를 맞게 썼음.")
    } else {
        println("철자가 틀림. 다시 해보기 바람.")
    }    
}

theRegularExpression = /Wisniewski/
checkSpelling("Wisniewski", theRegularExpression)
checkSpelling("Wisnewski", theRegularExpression)



def 철자검사( 철자, 정규식)
{
    if (철자  ==~ 정규식)
    {
        println("철자를 맞게 썼음.")
    } 
    else 
    {
        println("철자가 틀림. 다시 해보기 바람.")
    }
}


theRegularExpression = /Wisniewski/

철자검사("Wisniewski", theRegularExpression)
철자검사("Wisnewski", theRegularExpression)


// 함수를 정의할때 def 를 쓴다.
// 일반함수 정의와 클로져함수 정의의 차이점을 잘봐두자.
def fac1(n) { n == 0 ? 1 : n * fac(n-1) }
def fac2 = { n -> n == 0 ? 1 : n * call(n-1) }

println fac2(4)

def message( contents) {
    println contents
}

message( "연락바람.")

//
// 구루비 스크립트 파일명을 정할때, 숫자로 시작하는 파일명을하면
// 함수나 클래스에서 에러가 난다.
// 또한 파일명과 같은 클래스이름을 만들면 에러가 난다.
// 파일명에 주의할것.
//

/*
Regular Expression

a?           a 가 0 또는 1 개 있음.              'a' 또는 빈문자열
a*           a 가 0 또는 여러개 있음.            빈문자열 또는 'a', 'aa', 'aaa', ...
a+           a 가 1 또는 여러개 있음.            'a', 'aa', 'aaa', ...
a|b          a 또는 b                            'a' 또는 'b'
.            어떤 문자가 하나 있음.              'a', 'q', 'l', '_', '+', ...
[woeirjsd]   나열된문자중 하나가 있음.           'w','o','e','i','r','j','s'
[1-9]        주어진 범위의 문자중 하나가 있음.   '1','2','3','4','5','6','7','8','9'
[^13579]     나열된문자가 아닌것.                 짝수, 또는 다른 문자.
(ie)         식의 그룹                            'ie'
^a           a 가 줄의 맨처음에 있음.             'a'
a$           a 가 줄의 맨끝에 있음.               'a'

*/

Firefly Algorithms

firefly algorithm 001 Firefly Algorithms ¶ 반딧불 알고리즘 번역 요약 ¶ References [1] X. S. Y...