12
Introduction:
(Source: Wikipedia)
When we look at a rainbow it will always have the colors from top to bottom:
Red; orange; yellow; green; blue; indigo; violet
If we look at these individual rings, the red ring is of course bigger than the violet ring.
In addition, it's also possible to have two or even three rainbow at the same time.
All this above combined will be used in this challenge:
Challenge:
Given a list of integers of exactly size 7, where each value indicates the color-particles available to form rainbows (where the largest index indicates red and the smallest index indicated violet), output the amount of rainbows that can be formed.
A single integer-rainbow has to have at least 3x violet, 4x indigo, 5x blue, 6x green, 7x yellow, 8x orange, 9x red. A second rainbow on top of it will be even bigger than the red ring of the first rainbow (including one space between them), so it will need at least 11x violet, 12x indigo, 13x blue, 14x green, 15x yellow, 16x orange, 17x red in addition to what the first rainbow uses. The third rainbow will start at 19x violet again.
Example:
Input-list: [15,20,18,33,24,29,41]
Output: 2
Why? We have 15x violet, and we need at least 3+11=14 for two rainbows. We have 20 indigo and we need at least 4+12=16 for two rainbows. Etc. We have enough colors for two rainbows, but not enough to form three rainbows, so the output is 2
.
Challenge rules:
- The integers in the input-array are guaranteed to be non-negative (
>= 0
). - The input-list is guaranteed to be of size 7 exactly.
- When no rainbows can be formed we output
0
. - Input and output format is flexible. Can be a list or array of integers of decimals, can be taken from STDIN. Output can be a return from a function in any reasonable output-type, or printed directly to STDOUT.
Minimum amount of colors required for n
amount of rainbows:
Amount of Rainbows Minimum amount per color
0 [0,0,0,0,0,0,0]
1 [3,4,5,6,7,8,9]
2 [14,16,18,20,22,24,26]
3 [33,36,39,42,45,48,51]
4 [60,64,68,72,76,80,84]
5 [95,100,105,110,115,120,125]
etc...
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: [15,20,18,33,24,29,41]
Output: 2
Input: [3,4,5,6,7,8,9]
Output: 1
Input: [9,8,7,6,5,4,3]
Output: 0
Input: [100,100,100,100,100,100,100]
Output: 4
Input: [53,58,90,42,111,57,66]
Output: 3
Input: [0,0,0,0,0,0,0]
Output: 0
Input: [95,100,105,110,115,120,125]
Output: 5
Input: [39525,41278,39333,44444,39502,39599,39699]
Output: 98
The
0,0,0,0,0,0,0
edge-case though :( (it does not fit with the 1-gap logic) – Jonathan Allan – 2018-08-14T17:32:00.383