Mild Obfuscation

08/11/2011

Sometimes, you have a small bit of data, may something like a GUID (for which there are many possible solutions), that you may have to store in a plain-text file, nothing crucial, not sensitive, but that you don’t really want your users to poke with, even if they really mean to. In such cases, you could use encryption, but it may be that mild obfuscation is quite sufficient and dissuasive.

So, if you don’t really want strong encryption, what can you do to provide a machine-efficient encryptionnette?

Read the rest of this entry »


On Hockey Pools

18/10/2011

If you have ever played in Hockey pools (or any other kind of pools) you know that if you do not get a good drawing rank, your chances of winning anything are greatly diminished. So, here’s how a typical pool works. There are n pool players that will form “teams” with k league players (usually real players from the real leagues, with their standardized scores) from a total of m league players.

To form the n teams, the n players put their numbers 1,2,\ldots,n in a hat, and the numbers are drawn one by one, determining in which order, in each round, pool players will get to choose their next pick in the remaining league players. That is, if the order drawn is, say, 5, 3, 4, 2, 1, then pool player number 5 gets to choose first, picking one league player, then goes pool player 3, and so on, until all pool players picked a league player, thus completing one round. There are k of those rounds so that each pool player has his team of k league players.

Read the rest of this entry »


Pairing Functions

27/09/2011

Sometimes you have to encode reversibly two (or more) values onto a single one. The typical example of a pairing function that encodes two non-negative integers onto a single non-negative integer (therefore a function f:\mathbb{Z}^*\times\mathbb{Z}^*\to\mathbb{Z}^*) is the Cantor function, instrumental to the demonstration that, for example, the rational can be mapped onto the integers.

In a more pragmatic way, it may be necessary to encode two values onto one for data compression purposes, or to otherwise exploit a protocol that does not allow many distinct values to be sent separately. The simplest way of pairing two integer is to interleave their bits, for example, with something like:

Read the rest of this entry »


Learning Python (II)

20/09/2011

One thing I really like about Python is how it makes manipulating lists quite easily, especially via slices and list comprehensions. List comprehensions, especially in generator notation form, are an easy way to create lists with specific content. Other functional programming languages (such as Mathematica, amongst others) have taught me to use “map” to transform lists. But is it always the clearest and fastest way?


Read the rest of this entry »


Coding Maps (Part I)

30/08/2011

Quite a while ago, I discussed map generation in the classic 80s-era game Tunnels of Doom. After a short correspondence with Kevin Kenney himself (who kindly answered my questions; and I hope he is aware that he contributed to the fascination of great many kids in computer science), I manage to, not exactly reproduce his algorithm, but create a number of fun variations.

Tunnels of Doom Combat Screen.

This raises the question as to how do we encode maps efficiently in the computer’s memory, not only for Tunnels of Doooooom but also for any number of other games.

Read the rest of this entry »


Analog Thinking

23/08/2011

About five years ago, I found an old book, probably now an introuvable, Korn and Korn’s Electronic Analog Computers (D-c Analog Computers), 1956 [1].

Well, that mostly unrelated to today’s post, except that in some cases, relatively crude analog methods may give surprisingly good results in numerical problems (the topic came up while I was discussing the golden ratio and its place in art with friends, trying to make a point that it was mostly heuristic, bordering on the numerological). Take the pyramids, for example. The Ancient Egyptians did not have GPSes and laser guided telemetry. Yet, they managed to get some of their buildings incredibly well aligned with the celestial north.

Read the rest of this entry »


Programming Challenge: Martian Calendar

16/08/2011

This week, another programming challenge, but this time considerably tougher than the previous.

His Imperial Majesty, Xórgü of House Nand, decrees that the martian imperial court is in need of a new calendar. The current martian calendar counts 668 days, but it accumulates errors. The martian year, according to His Imperial Majesty’s most illustrious astronomers, is in fact 668.60 (martian) days long.

Read the rest of this entry »


Programming Challenge: Luminance

09/08/2011

A few years ago, I posted on my personal web page a number of programming challenges for my friends. This week, I present one of the old challenges: computing luma from RGB triplets using integer arithmetic only.

Read the rest of this entry »


Building a Personal Library (Part II)

19/07/2011

Quite a while ago, I blogged about how to find used books to fill your personal library on a budget. But used books have a major drawback compared to new books: they’re used. Well, yes, of course, but that means they may be in less than perfect state. They can be scratched, missing a few pages, have a damaged cover.

Fortunately, minor defects are rather easy to fix with a little creativity and surprisingly little material.

Read the rest of this entry »


The Inversion Method (Generating Random Sequences IV)

28/06/2011

In the first post of this series, I discussed how to generate permutations of sequences using the Fisher-Yates method and I explained (although indirectly) how a linear congruential generator works. In a second post, I explained how to generate 2D points uniformly and randomly distributed a triangle, discussing the method of rejection. In a third post, I’ve discussed how to generate points on a sphere.

All these methods have something in common: they are based on the uniform (pseudo)random generator, and they map uniform numbers onto a shape (or move numbers around, in the first case). What if we need another density function than uniform?

Read the rest of this entry »