# 实施图形计算器

12

``````f1(x)=x+1
``````

``````          +       1
|      1
+     1
|    1
+   1
|  1
+ 1
|1
+
1|
+-+-+-+-+-+-+-+-+-+-+
1  |
1   +
1    |
1     +
1      |
1       +
1        |
1         +
|
+
``````

``````f2(x)=(x^2)^0.25
``````

``````          +       1
|      1
+     1
|    1
+   1
|  1
2222      + 1    2222
222   |1  222
22 + 22
2|2
+-+-+-+-+-+-+-+-+-+-+
1  |
1   +
1    |
1     +
1      |
1       +
1        |
1         +
|
+
``````

``````f1(x)=-x
``````

（请注意，您的程序可以拒绝此输入，并且仅接受0-x或x * -1除外，但这应予以记录）

``````1         +
1        |
1       +
1      |
1     +
1    |
2222  1   +      2222
2221  |   222
22 + 22
2|2
+-+-+-+-+-+-+-+-+-+-+
|1
+ 1
|  1
+   1
|    1
+     1
|      1
+       1
|        1
+         1
``````

5

### Perl，177个字符（+1命令行开关）

``````perl -nE 's!\^!**!g;s!x!(\\$k/2-6)!g;s/\d.*=/;/;\$f[\$&]=\$_;my%a;for\$k(@x=2..22){\$i=0;\$a{int 12.5-2*eval}[\$k-2]=\$i++for@f}\$p="|";\$\$_[10]=\$p^=W,\$a{12}=[\$p."-+"x10],say map\$_//\$",@\$_ for@a{@x}'
``````

6

### Ruby，200个字符

``````f={}
r=0..20
(f[gets[1]]=\$_[6..-1].gsub /\^/,'**'
s=r.map{' '*21}
f.map{|n,k|r.map{|y|x=y*0.5-5
v=(2*eval(k)).round
v.abs<11&&y!=10&&s[10-v][y]=n
s[y][10]='+|'[y%2]
s[10][y]='+-'[y%2]}}
puts s)while 1
``````

PhiNotPi 2011年

2
@PhiNotPi不幸的是，这行不通。`y/2`进行整数除法。

2012年

blutorange

5

### Python 2：320个字符

``````N=20
r=range(N+1)
d={}
while(1):
l=raw_input()
d[l[1]]=l[6:].replace('^','**')
g=[[' ']*(N+1) for i in r]
for n,f in d.items():
for x in r:
v=N/2+int(round(2*eval(f.replace('x','(%f)'%(x/2.0-N/4)))))
if 0<=v<=N:g[N-v][x]=n
for i in r:
g[i][N/2]='+|'[i%2]
g[N/2][i]='+-'[i%2]
for l in g:print''.join(l)
``````