# Implement a Graphing Calculator

There have been many questions involving calculators; however, it does not appear that any involve implementing a graphing calculator.

The Challenge

You are to write a complete program that takes multiple formulas as input from STDIN and graphs them to STDOUT. Input will take the form f1(x)=x^2-x-1. There will be an f followed by a number 0-9 (inclusive), followed by (x)=, followed by the formula to graph. Your program should be able to take input, graph, take more input, graph, etc.

This is code golf.

Your graph should have the X-axis range from -5 to 5, with a resolution of at least one point every 1/2 unit. Y-axis requirements are the same. This may seem like a small range compared to modern calculators, but it will most likely be trivial in increase this. The graph should have the axis drawn on them, with tick marks in the form of + on the integers.

The formula should be evaluated with the normal order of operation. There will not be any vertical asymptotes/undefined regions in these formulas. The variable will always be x. If two formulas are entered with the same equation number, the oldest one should be erased and replaced with the new formula. Blank formulas should evaluate to zero. Since it is likely that the formula will not always give a nice multiple of 1/2, you are to round to the nearest 1/2.

When a formula is graphed, its line should be formed out of the number of the formula. When a line crosses an axis, the axis should be drawn on top. When two lines cross each other, it does not matter which is shown.

Example Input

f1(x)=x+1


Output

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


Input

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


Output

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


Input

f1(x)=-x


(note, it is acceptable for your program to reject this input and only except 0-x or x*-1, but this should be documented)

Output

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


### Ruby, 200 characters

f={}
r=0..20

### Python 2: 320 characters

N=20
r=range(N+1)
d={}
while(1):
l=raw_input()
d[l]=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)


Could probably be made shorter, but I'm a bit of a newbie at this :)

Making N a variable wastes 9 chars but I like it better that way.