This is a simple one: print an ASCII Gantt chart.
Given tasks' ranges (start-time - end-time Tuples), print a Gantt timeline in the form of
- characters for each task duration - each task in a new line.
Say my tasks ranges are
28->35, 34->40, 39->44, the Gantt will look like this:
------- ------ -----
- You can write a full program, a named function or an anonymous function.
- Your program/function should accept the tasks via STDIN or as arguments.
- Each task should be represented as a string of
[start,end]- this is allowed).
- Any non-negative number of tasks (arguments) should be supported.
To make it clear, a single argument of tasks collection is not allowed. You can either parse a single string argument, or support zero-or-more tasks arguments. Where task is a tuple or a collection of size 2.
- You can assume only valid input will be given. That means, each task has a positive duration.
- Return value does not matter, your code must print the timeline on STDOUT.
- Output: per task,
startspaces followed by
(end-start)dashes and a
- Needless to say, output lines should be ordered correspondingly with the input (tasks) order.
- Trailing spaces before the
\nare allowed, if that helps you.
Input: (empty) Output: (empty) Input: 0->7,5->6,3->6 Output: ------- - --- Input: 5->20,5->20,2->10,15->19 Output: --------------- --------------- -------- ----
- This is code-golf so the least code length (in bytes) wins.
- Traditionally, tie breaker is earlier post.
- "Standard loopholes are no longer funny".
As many of you understood that it is allowed to have a single tasks collection argument, and since there's no much different between that and the original varargs requirement, it is now allowed to have a single collection argument, if you don't want to use the varargs option, or in case your language does not support varargs.