31
2
(This is my first code-golf question)
When I was a child, my dad and I invented a game where the license plate we see on cars can give certain points based on some rather simple rules:
X amount of the same letter or number give X-1 points, examples:
22 = 1 point
aa = 1 point
5555 = 3 points
The numbers must be next to eachother, so 3353
only gives 1 point, as the 5 breaks the sequence of 3's.
A sequence of X numbers in ascending or descending order, at a minimum of 3, give X points, examples:
123 = 3 points
9753 = 4 points
147 = 3 points
The point system only works for 1-digit-numbers, so 1919
doesn't give points, and 14710
only give 3, (147).
Sequences can be combined to make more points, examples:
1135 = 4 points (1 point for 11 and 3 points for 135)
34543 = 6 points (3 points for 345 and 3 points for 543)
You are however not allowed to chop a larger sequence into 2 smaller sequences for extra points: 1234 = 123, 234 (6 points)
is not allowed.
Your task is, given a sequence, to determine the number of points the license plate gives.
In Denmark, the license plates are structured like this: CC II III, where C is character and I is integer, and thus my example inputs will reflect this structure. If you wish, you may make the sequence fit your own structure, or, if you feel really adventurous, let the program analyze the structure of the license plate and thus have it work on any type of license plate around the world. Explicitly state the structure you decide to use in your answer though.
You may take the input in any way you please, either a string or an array seem to make most sense to me.
Test input | output:
AA 11 111 | 5
AB 15 436 | 3
OJ 82 645 | 0
UI 65 456 | 6
HH 45 670 | 5
YH 00 244 | 5
AJ 00 754 | 1
Due to the nature of choosing your own structure, or even covering all structures, I dont necessarily see how a winner can be explicitly determined. I suppose the winner will be the shortest bytes on the structure one has decided. (And don't take an input like C I C I C, just to make it easy for yourself)
EDIT:
Due to comments asking, I have a few extra pieces of information to share: A sequence of ascending or descending numbers refers to an arithmetic sequence, so X +/- a * 0, X +/- a * 1, ... X +/- a * n etc. So 3-5-7 for example is 3 + 2 * 0, 3 + 2 * 1, 3 + 2 * 2. The sequence does not, however, need to start from 0 nor end in 0.
MORE EDIT:
You may give the input in any way you please, you dont need to input spaces, dashes or any other thing that makes a license plate more readable. If you can save bytes by only accepting capital letters or something like that, you may do that aswell. The only requirement is that your program can take a string/array/anything containing both characters and numbers, and output the correct amount of points according to the rules stated.
Loosely related. Welcome to PPCG and nice first question! – Mr. Xcoder – 2017-09-05T10:01:57.173
Suggested test case:
XX 87 654
. I came up with something that was correct for all your test cases but somehow incorrect for this one.. Working on fixing it. – Kevin Cruijssen – 2017-09-05T11:35:33.0477I strongly suggest you fix a certain structure (I suggest
CCIIIII
, no spaces), or else this problem lacks an objective win criterion, which we require around here. As-is, “(And don't take an input like C I C I C, just to make it easy for yourself)” is very subjective. What is and isn’t an admissible structure? – Lynn – 2017-09-05T11:37:29.5631@Lynn An admissible structure is one that can actually yield points, CICIC will never have a sequence that yields any points, therefore it is not admissible. And on top of that, why is 'shortest answer in bytes on the chosen programming language and chosen structure' not a clear, objective win criteria? This win criteria has a straight, easy to follow rule, yet gives the developer freedom to choose what kind of structure they want it to work with. Granted it may have a lot of different winners, but, really, so what? – Troels M. B. Jensen – 2017-09-05T11:41:33.670
3Test case:
IA99999
(contains a decreasing sequence of code points, but not numbers). – Zgarb – 2017-09-05T13:10:03.367RE: allowing us to choose any input "that can actually yield points":
– Jonathan Allan – 2017-09-05T19:37:11.887CC
would be acceptable and has a very simple 2-byte Jelly answer and perhaps even just 1 byte in another language. It just feels like abusing the specification to me though. Hence I also suggest fixing the input format asCCIIIII
....just to add that if we also need to have characters and numbers in the input like in the "MORE EDIT" we may still do something like this for
– Jonathan Allan – 2017-09-05T19:52:32.443CCII
. (Also not that adding addenda like "EDIT" and "MORE EDIT" is a poor alternative to changing the specification in the body of the post itself. )@JonathanAllan If someone wants to make a CC or CCII answer using 2 or 1 byte, they are welcome to do so, as that is a legitimate structure that they may choose, I honestly dont see the point in limiting what the developer can choose to develop. This is a challenge, it has rules and it has answer-variants, if you solve the problem within these rules, it's an accepted answer. It is not my task as a question-giver to make the question as complicated as possible, it's the challenged developer who may choose how difficult he wants the task to be. By letting the goal be a bit more open than ... – Troels M. B. Jensen – 2017-09-06T07:12:07.767
@JonathanAllan ... just
CCIIIII
, the challenged developer may choose the path to success, if you find a solution such as the ones you have linked satisfactory for how challenged you were by the question, thats completely fine, but as the answers below show, people like to take the more challenging path to this question than just the easiest solution. I honestly dont see the point in restricting a question, as opposed to give the challenged developer free-roam over where they want to take it – Troels M. B. Jensen – 2017-09-06T07:14:32.623