Skip to content

Teaser Hints

Try to use hints only when you really need help! The hints are arranged in order.

Hint 1 This looks like a sorting problem. It might help to understand what sorting algorithms are out there. You can compare the speed of the algorithms by looking at their time complexities. But wait! There might be better solutions! Many programming languages actually have their own standard implementations to help you to sort lists!
Programming Language Implementation
Python list.sort() or sorted()
C++ std::sort from algorithm standard library
Java Collections.sort()
The real problem is these standard implementations usually only sort single numbers, but we have to sort a tuple of r, g and b... is there some way around that?
Hint 2 Consider the followings notes/questions:
  • Usually sorting allows us to sort lists of single numbers
  • Is it possible to convert the tuple for r, g and b into a form that is more friendly for sorting?
  • Or perhaps do the standard implementations allow you to use your own method to compare between two elements?
Hint 3 Consider the following questions:
  • Is there a way to combine r, g and b into a single number? (Maybe some arithmetic? Addition?)
  • But how do we combine them in such a way that we can get the exact same r, g and b values back after sorting?
  • Maybe we can think about how we can combine them to a number that reflects the relative importance of each colour component (i.e. r is more important than g and b)?