Good morning! I have a very particular problem. I’ve come at it from a lot of angles, but I realized this is something the Arduino could do.
I have a painting, and there are 31 beach umbrellas. I have seven umbrella colors, and I want to give every umbrella a color at ~random.
I tried dice, but the distribution was way off.
I want 30% of the umbrellas to be Cerulean Blue, 20% are Cobalt Blue, and the rest are Teal, Purple, Orange, Yellow and Rainbow. So 50% among those five.
How would one go about this?
I want to end up with this:
Umbrella# Color
1 Cerulean
2 Cobalt
3 Purple
4 Cerulean
5 Rainbow…
I have twelve of these to do.
This is a trivial math problem solvable with python or matlab or anything else really, why exactly are you trying to program it onto an arduino ?
1 Like
This is how I choose to live my life. If you don’t like it, I don’t know what to tell you.
Hi Joe,
I’ve no idea whay this would be a good thing to do on an Arduino, but are you aware of the 4 colour theory? It states that no more than 4 colours are required to shade in a map, so that no two areas, which share a common boundary, will have the same colour?
Wikipedia has details here.
This implies that you should easily be able to use your 7 colours and fill in your umbrellas accordingly.
Getting the Arduino to do it for you well, I suspect a brute force “try it and see” algorithm would be the easiest here. But it involves recursion! You would scan the umbrellas looking for the first uncoloured one, and place a legal colour into it. Then check if you have completed all the umbrellas. If so, return a value that shows success.
If not, then recursively call the same function with the new “picture” with one less coloured umbrella and have the function try to resolve that new picture. If it finds that it can’t fit a legal colour in then it must return a value to indicate this. This will allow the calling function to realise that its guess was incorrect, rub out that umbrella and try again with another.
I wrote a similar program to “brute force” a Sudoku puzzle which might be of some help as this is very similar except you are using colours not numbers. Unfortunately, it’s written in MC68000 assembly language (don’t ask!) and you can download a PDF here. Obviously it might need the algorithm adjusting to account for your pot of colours and the numbers of each. Section 5.3.5 Solving the Board on page 37 of the PDF, is the algorithm you can examine and modify to suite your needs.
Oh, and beware, the stack on an Arduino uses some of the Static RAM. The Arduino Uno has only 2 KB (2048) bytes of Static RAM, so if your recursion goes too deep, all sorts of weird and “wonderful” things will happen, not many of them good!
Good luck!
Cheers,
Norm.