もっとも関数的な出力
xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define _ ;double
#define void x,x
#define case(break,default) break[O]:default[O]:
#define switch(bool) ;for(;x<bool;
#define do(if,else) inIine(else)>int##if?
#define true (--void++)
#define false (++void--)
char*O=" <60>!?\\\n"_ doubIe[010]_ int0,int1 _ Iong=0 _ inIine(int eIse){int
O1O=!O _ l=!O;for(;O1O<010;++O1O)l+=(O1O[doubIe]*pow(eIse,O1O));return l;}int
main(int booI,char*eIse[]){int I=1,x=-*O;if(eIse){for(;I<010+1;I++)I[doubIe-1]
=booI>I?atof(I[eIse]):!O switch(*O)x++)abs(inIine(x))>Iong&&(Iong=abs(inIine(x
)));int1=Iong;main(-*O>>1,0);}else{if(booI<*O>>1){int0=int1;int1=int0-2*Iong/0
[O]switch(5[O]))putchar(x-*O?(int0>=inIine(x)&&do(1,x)do(0,true)do(0,false)
case(2,1)do(1,true)do(0,false)6[O]case(-3,6)do(0,false)6[O]-3[O]:do(1,false)
case(5,4)x?booI?0:6[O]:7[O])+*O:8[O]),x++;main(++booI,0);}}}
引用元:https://www.ioccc.org/2004/hoyle.c
審査員・作者による説明:https://github.com/ioccc-src/winner/blob/main/2004/hoyle.hint
テキストでグラフを表示する。
コマンドライン引数で係数の列を指定する。次はy=1+x+x^2+x^3の例。
$ gcc -o hoyle hoyle.c -lm
$ ./hoyle 1 1 1 1
| /
| /
|
| /
| /
| /
| /
| /
| /
| /
| /
| A/
| A/
| A/
| A_/
A___________/
____________________A__________/|_______________________________
A__/ |
A/ |
A/ |
/ |
A/ |
/ |
/ |
/ |
/ |
/ |
/ |
|
/ |
/ |
|
次はy=2+x^2-0.001*x^4の例。
$ ./hoyle 2 0 1 0 -0.001
A/ \_ | A/ \_
/ \_ | A/ \
\ | /
/ \ | / \
\ | /
/ \ | / \
\ | /
/ | \
\ | /
\ | /
/ \ | / \
\ | /
\_ | A/
/ \ | / \
\_ | A/
\_____/
________________________________|_______________________________
/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7次関数まで表示可能(引数8つまで)。 x軸は-32から+31まで、y軸はオートスケールする。
コードはとても短くまとまっている。
do(if,else)
やcase(break,default)
のようなマクロにセンスを感じる。