본문 바로가기
STUDY

특정해의 60갑자를 출력하는 계산기 만들어보기와 chatGPT

by PsychoFLOOD 2023. 1. 3.
728x90

2023년 새해가 되었다..

다들 새해 복 많이 받으시길..ㅎ

다들 아시다시피 올해는 계묘(癸卯)년 으로 검은 토끼의 해라고 한다.

항상 신년이 되면 60갑자 중 어느 해인지 나오고 이에 대한 의미 등이 설명된 기사 등을 보곤 하게 된다.

10개의 천간과 12개의 지지의 조합을 통해서 60간지를 60갑자로 한다.(10간과 12지가 각각 1개씩 증가하면서 짝을 이루는데 10과 12의 최소공배수가 60이므로 갑자의 수는 60개가 된다.)

자세한 내용은 나무위키의 60갑자 설명을 참조.

https://namu.wiki/w/%EC%9C%A1%EC%8B%AD%EA%B0%91%EC%9E%90

 

육십갑자 - 나무위키

갑축(甲丑), 갑묘(甲卯), 갑사(甲巳), 갑미(甲未), 갑유(甲酉), 갑해(甲亥) 을자(乙子), 을인(乙寅), 을진(乙辰), 을오(乙午), 을신(乙申), 을술(乙戌) 병축(丙丑), 병묘(丙卯), 병사(丙巳), 병미(丙未),

namu.wiki

아래 소스로 돌려본 서기 4년부터 계산해본 60갑자

특정 해의 60갑자를 알아보고 이에 해당하는 오행/색상/음양/띠 를 출력하는 간단한  c 코드를 작성하여 보았다.

서기 1년은 신유년으로 이를 기준점으로 삼아서 사용자가 알고 싶은 년도까지 while문을 돌고 이때부터 사용자가 입력한 년도 이후 특정 기간만큼 출력하는 것을 기본 구성으로 작성하여 보았다.(사실 계산을 편하게 하고자 하면 위의 나무위키 60갑자 설명중 3.계산법에서 사용하는 방법으로 하는게 더 빠르긴 할 것이다.ㅎㅎ)

해당 천간에 해당하는 정보들과 해당 지지에 해당하는 정보들을 출력하기 위해 3개의 2차원 배열을 사용하였다.(한글띠이름 말고는 다 1글자씩 이기때문에 쉽게 처리하기 위해 이렇게 하였다. 한글 혹은 한자 는 콘솔에서 기본적으로 한글자당 2바이트를 사용하므로 저렇게 저장하고 한글자만 출력하려면 printf 문에서 %c 를 2번 사용하면 된다.)

int main(int argc, char* argv[])
{
    char hs[10][10] = { "갑甲木청","을乙木청", "병丙火적", "정丁火적", "무戊土황", "기己土황", "경庚金백", "신辛金백", "임壬水흑", "계癸水흑" };
    char eb[12][10] = {"자子水","축丑土", "인寅木", "묘卯木", "진辰土", "사巳火", "오午火", "미未土", "신申金", "유酉金", "술戌土", "해亥水"};
    char eb2[12][10] = { "쥐","소", "호랑이", "토끼", "용", "뱀", "말", "양", "원숭이", "닭", "개", "돼지" };
    int hs_index = 7, eb_index = 9, total=0, year=1;
    int t_year = 1, offset = 1;

    printf("Input start year : ");
    scanf("%d", &t_year);
    printf("Input period(years) : ");
    scanf("%d", &offset);
    printf("서기   60갑자        오행  색상 음양 띠\n");
    while (year < (t_year+offset)) {
        if(year >= t_year)
        printf("%04d년 %c%c%c%c(%c%c%c%c)년  %c%c%c%c  %c%c색  %c%c  %s띠\n", year, hs[hs_index][0], hs[hs_index][1], eb[eb_index][0], eb[eb_index][1],
            hs[hs_index][2], hs[hs_index][3], eb[eb_index][2], eb[eb_index][3],
            hs[hs_index][4], hs[hs_index][5], eb[eb_index][4], eb[eb_index][5],
            hs[hs_index][6], hs[hs_index][7],
            hs_index%2==0?'+':'-', eb_index % 2 == 0 ? '+' : '-', eb2[eb_index]
        );
        hs_index++;
        eb_index++;
        if (hs_index == 10) hs_index = 0;
        if (eb_index == 12) eb_index = 0;
        year++;
    }

    return 0;
}

 

요즘 재미들린 일은 이런 간단한? 코딩을 chat gpt에 시켜도 잘 할수 있을까? 이므로 이 코드를 또 다시 이번에는 chat gpt 에게 시켜보았다. ㅎㅎ

질문은 대충 아래처럼 해보았다.

"write c language code that show specific years 60 sexagenary cycle code based upon 10 Heavenly Stems and 12 Earthly Branches in korean"

chatGpt 가 내놓은 대답과 코드는 아래와 같다.

"Here is some sample code in C that generates the sexagenary cycle code for a specific year in Korean, based on the 10 Heavenly Stems and 12 Earthly Branches:"

#include <stdio.h>

// Returns the sexagenary cycle code for a given year in Korean
char* get_sexagenary_cycle_code_korean(int year) {
static char code[3]; // Sexagenary cycle code is two characters long

// The 10 Heavenly Stems and 12 Earthly Branches form the basis of the sexagenary cycle
static char* heavenly_stems[10] = { "갑", "을", "병", "정", "무", "기", "경", "신", "임", "계" };
static char* earthly_branches[12] = { "자", "축", "인", "묘", "진", "사", "오", "미", "신", "유", "술", "해" };

// Calculate the index of the Heavenly Stem and Earthly Branch corresponding to the given year
int stem_index = (year - 4) % 10;
int branch_index = (year - 4) % 12;

// Copy the Heavenly Stem and Earthly Branch to the code array and return it
code[0] = heavenly_stems[stem_index][0];
code[1] = earthly_branches[branch_index][0];
code[2] = '\0';
return code;
}

int main() {
// Test the function with some example years
printf("%d: %s\n", 2022, get_sexagenary_cycle_code_korean(2022));
printf("%d: %s\n", 2023, get_sexagenary_cycle_code_korean(2023));
printf("%d: %s\n", 2024, get_sexagenary_cycle_code_korean(2024));

return 0;
}

"When run, this code will output the following:

2022: 기축 2023: 경인 2024: 신묘

Note that the sexagenary cycle code is based on the traditional Chinese calendar, which uses a 60-year cycle. The code above assumes that the cycle starts with the year 4, which is the first year of the cycle according to the traditional Chinese calendar. The Korean version of the cycle is similar to the Chinese version, with the same 10 Heavenly Stems and 12 Earthly Branches being used to represent the years in the cycle."

서기 4년이 갑자년으로 60간지의 시작이 맞기는 한데... 예시로 보여준 2023년의 60갑자가 경인으로 나왔다??

원인은 한글은 2바이트인데 위의 코드에서는 이를 고려하지 않았기 때문이다. 제대로 고치려면 get_sexagenary_cycle_code_korean 함수에서 리턴해주는 code 선언을 5바이트로 변경하고 리턴할때 할당하는 부분을 아래과 같이 변경하면 된다.

    code[0] = heavenly_stems[stem_index][0];
    code[1] = heavenly_stems[stem_index][1];
    code[2] = earthly_branches[branch_index][0];
    code[3] = earthly_branches[branch_index][1];
    code[4] = '\0';

그렇다면 chatGPT에 다시 질문을 한글은 2바이트임을 고려해서 코딩해라라고 시키면 잘 나올까?

한번 해보았다.

질문의 말미에 한글은 2바이트임을 고려해라 라는 단서를 달아주었다.

질문 : "write c language code that show specific years 60 sexagenary cycle code based upon 10 Heavenly Stems and 12 Earthly Branches in korean and consider that korean is two bytes"

답변 : "Here is some sample code in C that generates the sexagenary cycle code for a specific year in Korean, based on the 10 Heavenly Stems and 12 Earthly Branches, while considering that Korean is a two-byte character set:"

코드

#include <stdio.h>
#include <wchar.h>

// Returns the sexagenary cycle code for a given year in Korean
wchar_t* get_sexagenary_cycle_code_korean(int year) {
static wchar_t code[3]; // Sexagenary cycle code is two characters long

// The 10 Heavenly Stems and 12 Earthly Branches form the basis of the sexagenary cycle
static wchar_t* heavenly_stems[10] = { L"갑", L"을", L"병", L"정", L"무", L"기", L"경", L"신", L"임", L"계" };
static wchar_t* earthly_branches[12] = { L"자", L"축", L"인", L"묘", L"진", L"사", L"오", L"미", L"신", L"유", L"술", L"해" };

// Calculate the index of the Heavenly Stem and Earthly Branch corresponding to the given year
int stem_index = (year - 4) % 10;
int branch_index = (year - 4) % 12;

// Copy the Heavenly Stem and Earthly Branch to the code array and return it
code[0] = heavenly_stems[stem_index][0];
code[1] = earthly_branches[branch_index][0];
code[2] = L'\0';
return code;
}

int main() {
// Test the function with some example years
wprintf(L"%d: %ls\n", 2022, get_sexagenary_cycle_code_korean(2022));
wprintf(L"%d: %ls\n", 2023, get_sexagenary_cycle_code_korean(2023));
wprintf(L"%d: %ls\n", 2024, get_sexagenary_cycle_code_korean(2024));

return 0;
}

코드이후 답변 : "When run, this code will output the following:

2022: 기축 2023: 경인 2024: 신묘

Note that the sexagenary cycle code is based on the traditional Chinese calendar, which uses a 60-year cycle. The code above assumes that the cycle starts with the year 4, which is the first year of the cycle according to the traditional Chinese calendar. The Korean version of the cycle is similar to the Chinese version, with the same 10 Heavenly Stems and 12 Earthly Branches being used to represent the years in the cycle. The code uses wide character strings (wchar_t) to represent the Korean characters, as Korean is a two-byte character set. The wide character version of the printf function (wprintf) is used to print the strings."

오호 이번에는 2바이트를 고려하여서 wchat_t 를 사용하여 데이터를 선언하고 출력도 해당 타입을 이용하는 wprintf를 사용하였다.

그런데 예상결과는 또 틀렸다 ㅋㅋ

이유는... locale 을 지정해주지 않아서다. 위의 코드에서 main() 안에 아래 구문을 넣어주면 올바르게 출력된다.

setlocale(LC_ALL, "KOREAN");

그렇다면 chatGPT에게 setLocale 함수도 고려해서 코딩해라 라고 시키면 제대로 나올까?

질문 : "write c language code that show specific years 60 sexagenary cycle code based upon 10 Heavenly Stems and 12 Earthly Branches in korean and consider that korean is two bytes and use setlocale function"

이랬더니 역시 해당 함수를 사용해서 코딩을 해주긴 하였다. 그러나 결과는 역시 실패.

Here is some sample code in C that generates the sexagenary cycle code for a specific year in Korean, based on the 10 Heavenly Stems and 12 Earthly Branches, while considering that Korean is a two-byte character set and using the setlocale function:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

// Returns the sexagenary cycle code for a given year in Korean
wchar_t* get_sexagenary_cycle_code_korean(int year) {
static wchar_t code[3]; // Sexagenary cycle code is two characters long

// The 10 Heavenly Stems and 12 Earthly Branches form the basis of the sexagenary cycle
static wchar_t* heavenly_stems[10] = { L"갑", L"을", L"병", L"정", L"무", L"기", L"경", L"신", L"임", L"계" };
static wchar_t* earthly_branches[12] = { L"자", L"축", L"인", L"묘", L"진", L"사", L"오", L"미", L"신", L"유", L"술", L"해" };

// Calculate the index of the Heavenly Stem and Earthly Branch corresponding to the given year
int stem_index = (year - 4) % 10;
int branch_index = (year - 4) % 12;

// Copy the Heavenly Stem and Earthly Branch to the code array and return it
code[0] = heavenly_stems[stem_index][0];
code[1] = earthly_branches[branch_index][0];
code[2] = L'\0';
return code;
}

int main() {
// Set the locale to Korean
setlocale(LC_ALL, "ko_KR.UTF-8");

// Test the function with some example years
wprintf(L"%d: %ls\n", 2022, get_sexagenary_cycle_code_korean(2022));
wprintf(L"%d: %ls\n", 2023, get_sexagenary_cycle_code_korean(2023));
wprintf(L"%d: %ls\n", 2024, get_sexagenary_cycle_code_korean(2024));

return 0;
}

When run, this code will output the following:

2022: 기축 2023: 경인 2024: 신묘

Note that the sexagenary cycle code is based on the traditional Chinese calendar, which uses a 60-year cycle. The code above assumes that the cycle starts with the year 4, which is the first year of the cycle according to the traditional Chinese calendar. The Korean version of the cycle is similar to the Chinese version, with the same 10 Heavenly Stems and 12 Earthly Branches being used to represent the years in the cycle. The code uses wide character strings (wchar_t) to represent the Korean characters, as Korean is a two-byte character

뭐 로케일을 고려하여 코딩을 하긴 하였으나 결과는 꽝이다. 그렇다면... 아예 파라미터를 KOREAN으로 해라라고 시키면 결과가 제대로 나올까?

질문 : write c language code that show specific years 60 sexagenary cycle code based upon 10 Heavenly Stems and 12 Earthly Branches in korean and consider that korean is two bytes and use setlocale function with KOREAN parameter

답변 :Here is some sample code in C that generates the sexagenary cycle code for a specific year in Korean, based on the 10 Heavenly Stems and 12 Earthly Branches, while considering that Korean is a two-byte character set and using the setlocale function with the "KOREAN" parameter:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

// Returns the sexagenary cycle code for a given year in Korean
wchar_t* get_sexagenary_cycle_code_korean(int year) {
static wchar_t code[3]; // Sexagenary cycle code is two characters long

// The 10 Heavenly Stems and 12 Earthly Branches form the basis of the sexagenary cycle
static wchar_t* heavenly_stems[10] = { L"갑", L"을", L"병", L"정", L"무", L"기", L"경", L"신", L"임", L"계" };
static wchar_t* earthly_branches[12] = { L"자", L"축", L"인", L"묘", L"진", L"사", L"오", L"미", L"신", L"유", L"술", L"해" };

// Calculate the index of the Heavenly Stem and Earthly Branch corresponding to the given year
int stem_index = (year - 4) % 10;
int branch_index = (year - 4) % 12;

// Copy the Heavenly Stem and Earthly Branch to the code array and return it
code[0] = heavenly_stems[stem_index][0];
code[1] = earthly_branches[branch_index][0];
code[2] = L'\0';
return code;
}

int main() {
// Set the locale to Korean
setlocale(LC_ALL, "KOREAN");

// Test the function with some example years
wprintf(L"%d: %ls\n", 2022, get_sexagenary_cycle_code_korean(2022));
wprintf(L"%d: %ls\n", 2023, get_sexagenary_cycle_code_korean(2023));
wprintf(L"%d: %ls\n", 2024, get_sexagenary_cycle_code_korean(2024));

return 0;
}

When run, this code will output the following:

2022: 기축 2023: 경인 2024: 신묘

Note that the sexagenary cycle code is based on the traditional Chinese calendar, which uses a 60-year cycle. The code above assumes that the cycle starts with the year 4, which is the first year of the cycle according to the traditional Chinese calendar. The Korean version of the cycle is similar to the Chinese version, with the same 10 Heavenly Stems and 12 Earthly Branches being used to represent the years in the cycle. The code uses wide character strings (wchar_t) to represent the Korean characters, as Korean is a

(영어답변도 길면 짤리긴 한다...)

 

답변중 예재 결과는 틀린 답이 나왔으나 해당 소스대로 실제로 컴파일해서 돌려보면 2023년은 계묘 로 잘 나온다.

이를 통해서 유추해볼 수 있는 것은 chatGPT가 알려주는 소스와 이에 대한 예제 결과는 chatGPT가 직접 컴파일을 해서 돌려본 결과가 아니라는 사실이다. 반드시 해당소스를 컴파일해서 확인을 해봐야 한다.(뭐 당연한...이야기이겠지만..ㅎㅎ)

질문에 실제 컴파일 결과를 보여줘 라는 단서를 다시 달게 되면 chatGPT는 나는 컴파일을 실제할수 있는 능력이 없다는 단서를 답변초기에 깔고 시작한다. ㅎㅎ

질문 : write c language code that show specific years 60 sexagenary cycle code based upon 10 Heavenly Stems and 12 Earthly Branches in korean and consider that korean is two bytes and use setlocale function with KOREAN parameter and show me real compile result 

답변초기 :I'm sorry, but I am unable to compile code or show you the real compile result. I am a language model trained to assist with generating code and providing explanations, but I do not have the ability to execute code or access a compiler.

 

그래도 이정도까지 코딩해주는 chatGPT는 정말 대단하고 신기하긴 하다...ㅎㄷㄷㄷ

 

 

 

 

 

728x90

댓글