Submit | All submissions | Best solutions | Back to list |
PLOT - Plotting functions |
Given a function y=f(x) plot it with stars (*) and then (!) its derivation with crosses (+) for 0<=x<=20 with Δx=1 in a diagram with 21*21 points (0<=x,y<=20). Empty fields are marked with dots (.). For plotting the real number y should be rounded to integer (-0.5 -> -1, -0.4 -> 0, 0.4 -> 0, 0.5 -> 1). The function and its derivation are continuous between 0 and 20.
The function definition uses only the following characters: 0123456789x.+-*/()
'**' means 'power of'.
See also this similar task.
Input
In the first line the number N of functions, then N lines with one function.
Output
The plot of each function and its derivation in 21 lines.
Example
Input: 2
x
20/(x+1) Output: ....................*
...................*.
..................*..
.................*...
................*....
...............*.....
..............*......
.............*.......
............*........
...........*.........
..........*..........
.........*...........
........*............
.......*.............
......*..............
.....*...............
....*................
...*.................
..*..................
+++++++++++++++++++++
*....................
*....................
.....................
.....................
.....................
.....................
.....................
.....................
.....................
.....................
.....................
.*...................
.....................
.....................
..*..................
.....................
...*.................
....*................
.....***.............
........*****........
.............********
......+++++++++++++++
Added by: | HWK |
Date: | 2011-03-01 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: SCM qobi |
hide comments
|
|||||
2011-04-20 12:12:52 HWK
@hallvabo: You haven't to wait a long time. There's your well known competitor again.:-) |
|||||
2011-04-15 09:54:58 Piotr KÄ…kol
I think it's because new users choose first the tasks which most people has done and if they enjoy shortening (which often means succeed) they will try the harder ones, with the last added at the end (because they don't realise that last tasks don't have to be difficult if they have been solved only by few users and it's just because they're new). |
|||||
2011-04-10 17:56:50 HWK
Yes, there's little interest for the tasks on problem page two. Perhaps should the last problems appear first. |
|||||
2011-04-10 15:44:31 Hallvard Norheim Bø
169 bytes of Python now, but no competitors!? |
|||||
2011-03-31 16:42:04 Hallvard Norheim Bø
At least until numerix solves this too. Remains to be seen if I can defend my new rank... |
|||||
2011-03-31 15:51:03 HWK
@hallvabo: Congratulation! By solving the problem you reached the 4th rank. |
|||||
2011-03-31 13:32:04 Hallvard Norheim Bø
Rounding -0.5 correctly fixed it. Now it just remains to find a shorter way to do the rounding :-) |
|||||
2011-03-29 21:36:43 Hallvard Norheim Bø
Thanks for the hint! I didn't think that rounding negative numbers would be an issue since the values to be printed are >= 0, but now I see the problem. |
|||||
2011-03-29 20:29:07 HWK
Done! But look at the rounding rules above: int(round(-0.5, 3) + 0.5) == 0 != -1 (Python 2.5) Last edit: 2011-03-29 21:09:16 |
|||||
2011-03-29 18:21:52 Hallvard Norheim Bø
Due to rounding issues, this looks very hard to get right. Maybe you could provide some harder test cases? |