Archive for the ‘C++/Algorithms’ Category
IOCCC.
The International Obfuscated C Code Contest
제목을 보면 참 -_-;;
말 그대로, ‘참 복잡한 C 코드 만들기’대회입니다.
그런데 단순히 ‘복잡하다’란 단어로는 이 대회를 설명할 수 없는것 같네요 -_- 수상작들을 보면 차라리 예술에 가까운 코드들입니다.
Goals of the Contest를 보면 :
- To write the most Obscure/Obfuscated C program under the rules below.
- To show the importance of programming style, in an ironic way.
- To stress C compilers with unusual code.
- To illustrate some of the subtleties of the C language.
- To provide a safe forum for poor C code. :-)
…여전히 이 대회의 진정한 목적이 무엇인지 납득이 되지 않습니다….
자, 가장 중요한 수상작들입니다. 수상작 C 소스는 오스트레일리아 IOCCC 대회(http://www.au.ioccc.org/main.html)에서 퍼왔습니다.
이 소스는 timwi란 분의 작입니다 :
#include <stdio.h>
#define _ main(
#define _l ___l ___l ___l ___l ___)
#define __l int
#define ___l ___)*(
#define ____l (_l],
#define ____ 1
#define ___ __+_____
#define __ ____+____
#define _____ __+____
#define ______1 *(l__
#define _____1 *__1%(__
#define ____1 )?(
#define ___1 _1&(__
__l __I[____l _I[____l*l__=_I,*l_=__I;__l _ __l _1,__l*__1){__l _l_;
return ___1+ __ ____1 ___1 ____1*__1 = getchar()):__ ____1*__1<____?
____:_____1+___ ____1 _____1+_____ ____1 _____1+____)____1 ___1+___+
____ ____1 _____1 +__)____1 _____1 )____1 *l__)++:_____1+____)-____?
______1 ++) :_____1+_____) -____?__:printf("%d\n",*l__):_____1+____+
___ ____1 *l__) =*(l_++ ):__:___l ____- ____):_____1 +_____)-3?__-2:
____:(___1+____+___ ____1 _____1)____1*l__)-- :_____1+__)?__:______1
--):___l 0))?__:_ _1,__1+____)+____:(___1+____+___ )) &&* l__?_ ___1
+___+___+__),__1+____)?_ ___1+11 )|(___1)?____:__- 2),__1):____-1 :(
_l_=_ ___1 -____+___l ____),__1+____ )) ?_l_+_ ___1 )?_1 :___1+10)|(
___1-____ ____1 __):0),__1+_l_):0):__:_1%(__ ____1 _1/(__)) ?_ scanf
("%i",__1 ____1 _____):(___l _____)-____,__1 +____):_ _____,l_):__;}
......
.......-_-.......
참고로 컴파일 가능합니다.
저랑 조교 형이랑 앞부분 조금만 풀어봤는데;; 힌트를 보시려면 오른쪽을 드래그해보세요 : 시작은 global variable + 변수명
네, 두 번째 작품입니다. chia란 분의, Java를 상당히 싫어하는 분이 작성한 코듭니다.
#define aSet c
#define BufferedReader(x)1
#define byte Y[I][_^1]?do(:):_&1?do(.):do(`):8;++y;}
#define class int N=0,_,O=328,l=192,y=4,Y[80][64]={0},I;struct
#define do(c)a(#c “\b”)
#define err c,c
#define getAllStrings(x));q()
#define if(x)b(#x)
#define IOException
#define line c
#define main(a)b(char*x){write(1,”33[",2),null}main()
#define new
#define null a(x);}a(char*x){write(1,x,strlen(x));try;try;try;try;
#define out c,c
#define println(x)c
#define private int d(int
#define public short c;}c;typedef int BufferedReader;char*F="JF>:>FB;;BII";
#define return {return
#define static f(x){N=(N+x)%6,y--?f(0),f(1),f(4),f(1):++Y[(I=O+N[F]-66)
#define String
#define System c
#define this if(D):1,O=I,I/=16,l<_/32?if(B):l>_/32?if(A):2,l=_,_/=16,byte
#define throws
#define toArray(x)c
#define try for(;–c.c;)
#define void /16][(_=l+N[6+F]-66)/16]?O/=16,l/=32,O<I/16?if(C):O>I/16?this
#define while(k)if(2J),if(7;21H),f(0),f(4),f(4),if(H),/*import java.io.*;
import java.util.*;/**
* A lame Java program.
* @author J. Random Worker
*/
class LameJavaApp
{/** The infamous Long-Winded Signature From Hell. */
public static void main(String[] args)
throws IOException
{
/* Don’t get me started on this. */
BufferedReader reader =
new BufferedReader(new FileReader(args[0]));/* What, this long incantation just to print a string? */
System.err.println(“Hello world!”);/* At least this is sane. */
String line;
while ((line = reader.readLine()) != null)
System.out.println(line.length());
}/**
* Method with a needlessly long name.
* @param aSet a set (!)
*/
private String[] getAllStrings(Set<String> aSet)
{
/*
* This dance is needed even in J2SE 5, which has type
* templates. It was worse before that.
*/
return aSet.toArray(new String[0]);
}}
…….
-_-;;;;;;;; 예술….?? 분명 C코드인데? -_;;;;;
이 외에도 정말 입벌어지는 소스들이 많습니다만(소스로 그림을 그립니다) 할 일도 많고, 포스팅이 너무 길어질 것 같에서 이만 줄입니다:)
그래프에서 cycle 판명법?
문제는 정말 간단하다. 답변도 만만치 않게 간단하다.
그런데 뭔가 해탈을 주는듯한 그런 문제일까나 ㅎㅎ
엄청나게 긴 linked list가 있다. 여기서 cycle을 어떻게 찾을 수 있을까?
답은 간단하다. pointer 2개를 만드는데, 하나는 0에 위치하고 하나는 1에 위치한다. 그리고, 전자의 것은 1칸씩, 후자의 것은 2칸씩 뛰게 해서 둘이 만나면 싸이클이다.
Downloadable C++ Compilers(or Editors)
- Visual Studio 2005 C++ Express edition(for Windows)
http://msdn.microsoft.com/vstudio/express/visualc/download/
http://www.microsoft.com/korea/msdn/vstudio/express/visualc/download/ (for Korean)
- Dev-C++(for Windows)
http://www.bloodshed.net/dev/devcpp.html
- KDevelop(for Linux)
http://www.kdevelop.org/