글
Goedel, Escher, Bach 에 나오는 함수들을 만들어 보았다.
G sequence
H sequence
M and F sequence
Q sequence
그냥 작동하기만 할 뿐인 프로그램들이다.
컴파일은 DevC++ 4.9.9.1 with MinGW 에서 해서 작동하는 것을 확인하였다.
G sequence
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int gfunction(int);
int main(int argc, char* argv[])
{
int i;
if (argc==1){
printf("Error. There are no options.\n");
exit(1);
}
i=atoi(argv[1]);
printf("%d",gfunction(i));
}
int gfunction(int i)
{
if (i<0) {
printf("Error. Parameter is negative.\n");
}
else if (i==0) {
return 0;
}
else {
return (i-gfunction(gfunction(i-1)));
}
}
H sequence
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int hfunction(int);
int main(int argc, char* argv[])
{
int i;
if (argc==1){
printf("Error. There are no options.\n");
exit(1);
}
i=atoi(argv[1]);
printf("%d",hfunction(i));
}
int hfunction(int i)
{
if (i<0) {
printf("Error. Parameter is negative.\n");
}
else if (i==0) {
return 0;
}
else {
return (i-hfunction(hfunction(hfunction(i-1))));
}
}
M and F sequence
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int mfunction(int);
int ffunction(int);
int main(int argc, char* argv[])
{
int i;
if (argc==1){
printf("Error. There are no options.\n");
exit(1);
}
i=atoi(argv[1]);
printf("%d\n",mfunction(i));
printf("%d\n",ffunction(i));
}
int mfunction(int i)
{
if (i<0) {
printf("Error. Parameter is negative.\n");
}
else if (i==0) {
return 0;
}
else {
return (i-ffunction(mfunction(i-1)));
}
}
int ffunction(int i)
{
if (i<0) {
printf("Error. Parameter is negative.\n");
}
else if (i==0) {
return 1;
}
else {
return (i-mfunction(ffunction(i-1)));
}
}
Q sequence
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int hfunction(int);
int main(void)
{
int n;
for(n=1;n<100;n++)
printf("%d, ",qfunction(n));
}
int qfunction(int i)
{
if (i<0) {
printf("Error. Parameter is negative.\n");
}
else if (i==2 || i==1) {
return 1;
}
else {
int q=qfunction(i-qfunction(i-1))+qfunction(i-qfunction(i-2));
return q;
}
}
그냥 작동하기만 할 뿐인 프로그램들이다.
컴파일은 DevC++ 4.9.9.1 with MinGW 에서 해서 작동하는 것을 확인하였다.
RECENT COMMENT