16
1
Tallying is a simple counting system that works in base 5. There are various different tallying systems used around the world, but the one that is used in most English-speaking countries is perhaps the most simple - count units by marking vertical lines, then for each 5th mark put a horizontal line through the previous collection of four. This clusters the tally marks in groups of 5 (and makes them easier to quickly count).
You are going to write a program that displays tally marks up to a given value. But, tallying in only base 5 is boring! Therefore, your program should also be able to display tallies in different bases.
Input
The input will be either one or two non-negative integer values separated by a comma (e.g. 9
or 8,4
). The first number is the value that should be displayed by the tally. The second value is the base of the tally. If the second value is not given, use base 5.
Output
The output will be the inputted value represented as ASCII art tally marks. Here are some examples you can test your program against - your output should match them exactly!
Input: 12
or 12,5
| | | | | | | | | |
-+-+-+-+- -+-+-+-+- | |
| | | | | | | | | |
Input: 7,3
| | | | |
-+-+- -+-+- |
| | | | |
Input: 4,2
| |
-+- -+-
| |
Input: 6,1
or 6,10
(notice the leading spaces)
| | | | | |
| | | | | |
| | | | | |
Note also that base 1 is intended to be inconsistent - only vertical lines should be used.
If either of the inputted values is 0, there should be no output whatsoever (and your program should end gracefully).
Rules
- This is code-golf, so the shortest correct implementation (in bytes) wins.
- Input/output can be in any suitable medium (e.g. stdin/stdout, file...).
- Input can be in the form of multiple command-line arguments or separated by spaces, etc. if it is more suitable for your target language.
- Trailing newlines are allowed in the output. Trailing spaces are not. This rule only applies when there is an output (i.e. not when the inputted value is 0).
- Your code must default to base 5 when no base is input.
3Shouldn't the output of
6,1
look more like-+- -+- -+- -+- -+- -+-
? – Peter Taylor – 2014-08-20T12:38:50.8903If you state "The input will be either one or two positive integer values separated by a comma (e.g. 9 or 8,4)." then we should be able to take that as a given, and not have to worry about "Your program should be robust - you should validate the input..." beyond handling one or two numbers. – AndoDaan – 2014-08-20T12:42:32.017
1@PeterTaylor
-+-
would represent two, because there's a vertical line and a horizontal score through it. Base 1 would only have vertical lines. @AndoDaan ammended. – Sean Latham – 2014-08-20T12:45:30.577Ok,
--- --- --- --- --- ---
then. For consistency with the other bases you should be putting a horizontal strike throughb-1
vertical lines. If it's intended to be inconsistent you should state that explicitly. – Peter Taylor – 2014-08-20T12:54:32.453I've done that. Sorry, I thought it was implied. – Sean Latham – 2014-08-20T13:03:38.640
is there any leeway in the input format (comma-separated values are much less helpful than two separate command-line arguments, or even just space-separated standard input)? – None – 2014-08-20T13:27:33.343
Yes, I'll add this to the rules. – Sean Latham – 2014-08-20T13:40:06.453
Are trailing newlines allowed? – None – 2014-08-20T14:03:54.640
Yes, added. I need to find more ways of surpassing the 15 character minimum... – Sean Latham – 2014-08-20T14:10:27.620
But are trailing newlines allowed if
n==0
? Or does the "n=0->no-output" rule overrule the trailing-newline rule? – Falko – 2014-08-20T14:12:06.127The no output rule overrides it. Ideally your program will spot that
n = 0
and exit before any printing is done (or just skip it altogether). – Sean Latham – 2014-08-20T14:14:40.003Is there a maximum value for the numbers? Can I assume they're less than two billion? – Ypnypn – 2014-08-20T15:57:52.053
I said "positive integer", so I guess the maximum depends on your implementation. I'm not evil enough to want to test any inputs that high though :^) – Sean Latham – 2014-08-20T16:02:18.497
@ipi I was about to abuse a mistake you made when I decided I'd better correct your post instead. Zero is not "positive" yet it is a valid input, so I changed it to say "non-negative". – Kyle McCormick – 2014-08-21T00:59:30.693
With regard to the "no trailing spaces" rule, does this forbid trailing spaces at the end each of the 3 lines of output, or am I missing the point completely? – VisualMelon – 2014-08-21T11:32:40.343
If input is two numbers separated with a comma, like
7,2
, can I implement this as receiving input between the parentheses of a function call likef(7,2)
? – FUZxxl – 2014-08-21T14:13:26.960Can we assume 2¹⁵ - 1 as an upper limit for the numbers you test? – FUZxxl – 2014-08-21T14:22:58.637