The other day we had a very nice oriental-style BBQ at my place. Susi made a Couscous salad, while I made some hummus, a bell pepper salad, a salsa with Habanero chilis, and some marinated olives. On the meaty side, we had lamb chops and chicken wings. Very nice food indeed!

The evening ended with us all sitting still in the semi-dark of my terrace watching out for shooting stars. And we even saw some. Even one, which we will remember forever ðŸ˜‰

In the other life (work), I’ve written an algorithm for finding the bordering elements of contiguous ranges in a given array of ordered values. I’ve used rapid prototyping in Python before transferring the solution to C++. The Python code goes like this:

n = [1, 2, 3, 4, 5, 6, 7,Â Â Â 9, 10, 11, 12,Â Â Â Â Â 14, 15, 16] end = len(n) - 1 ranges = [] def get_right(left, step): Â Â Â if left == end: Â Â Â Â Â Â Â return left Â Â Â leftmost_r = None Â Â Â i = last_i = end Â Â Â while True: match = n[i] - n[left] == i - left Â Â Â Â Â Â Â if (i == end and match) or i == leftmost_r: Â Â Â Â Â Â Â Â Â Â Â return last_i Â Â Â Â Â Â Â last_i = i Â Â Â Â Â Â Â if match: Â Â Â Â Â Â Â Â Â Â Â i += step Â Â Â Â Â Â Â else: Â Â Â Â Â Â Â Â Â Â Â leftmost_r = i Â Â Â Â Â Â Â Â Â Â Â i -= step Â Â Â Â Â Â Â if step != 1: Â Â Â Â Â Â Â Â Â Â Â step /= 2 left = 0 while True: Â Â Â right = get_right(left, (len(n) - left) / 2) Â Â Â ranges.append((n[left], n[right])) Â Â Â if right == end: Â Â Â Â Â Â Â break Â Â Â else: Â Â Â Â Â Â Â left = right + 1

The basic assumption for the algorithm to work is that `n`

contains sorted values. This allows us to do a kind of binary search, if the currently looked at range (from `left`

to `i`

) does not fit the criterion for a match (namely that `n[i] - n[left] != i - left`

). Maybe this is useful for someone!

NP: Agnostic Front – Gotta go