# Bronze Challenge. What's the best way

#1

Hi all,

With regards to the Bronze challenge, most of the solutions posted in the forum are based on random colors. Can anyone recommend a good way to make the colored circles uniformed, ie. red, green, blue, red, green, blue, red, green, etc, etc)?

I’ve tried the folowing, but am getting an error saying “terminate called throwing an exception” on the currentColor = [presetComponentColors objectAtIndex:i]; line:

```int countOfColors = [presetComponentColors count]; int i = 0; UIColor *currentColor; for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) { while (i <= countOfColors) { currentColor = [presetComponentColors objectAtIndex:i]; [self setCircleColor:currentColor]; [[self circleColor] setStroke]; CGContextAddArc(ctx, center.x, center.y, currentRadius, 0.0, M_PI * 2.0, YES); CGContextStrokePath(ctx); i++; } }```

#2

take a look at my bronze solution below. arc4random is your friend

– oops just read what you said at the beginning. nevermind then if you dont want to do random

#3

Looking at your loop structure, you never reset i to 0 so that it can reiterate through the array again and the end of the while loop will increment the i value past your last array index. Without testing this myself, I would guess you are trying to access your array beyond the available index.

#4

There is a coding error.

Compare this to yours (note the while statement’s test expression):

``````    int countOfColors = [presetComponentColors count];
int i = 0;
UIColor *currentColor;
while (i < countOfColors) {
currentColor = [presetComponentColors objectAtIndex:i];
[self setCircleColor:currentColor];
[[self circleColor] setStroke];
CGContextStrokePath(ctx);
i++;
}
}``````

Arrays are indexed using zero-based indexing; that is, first element is at index 0, second at 1, and last elements is at N - 1, where N is the size of the array.

Also consider replacing the wile statement with a for statement, which enables you to increment the index variable right next to the test expression.

``````for (int i = 0; i < countOfColors; ++i) {
...
}``````

#5

Hello all, I use hue and saturation which makes nice raibow.

``````    float h = 0.0;
float s = 1.0;