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 »
4 Comments |
algorithms, bit twiddling, C, C-plus-plus, hacks, Mathematics, programming, Python | Tagged: bit blenders, bit twiddling, Encryption, MAC address, Modular Arithmetic, xor |
Permalink
Posted by Steven Pigeon
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
pool players that will form “teams” with
league players (usually real players from the real leagues, with their standardized scores) from a total of
league players.

To form the
teams, the
players put their numbers
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
of those rounds so that each pool player has his team of
league players.
Read the rest of this entry »
1 Comment |
algorithms, hacks | Tagged: Hockey, Hockey Pool, Pool, Zipf |
Permalink
Posted by Steven Pigeon
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
) 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 »
8 Comments |
algorithms, bit twiddling, C, hacks, Mathematics, programming, Python | Tagged: Gödel, Gödel Number, Gödel Numbering, Integers, pairing function |
Permalink
Posted by Steven Pigeon
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 »
Leave a Comment » |
algorithms, bit twiddling, data compression, data structures, embedded programming, hacks, programming | Tagged: Dragon Warrior, Map, Map representation, Quad-Tree, Tunnels of Doom, Wumpus |
Permalink
Posted by Steven Pigeon
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 »
Leave a Comment » |
hacks, Mathematics | Tagged: Analog, Analog Computers, Ancient Egyptian, archeology, Egypt, Great Pyramid, Oolong, Pyramid |
Permalink
Posted by Steven Pigeon
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 »
13 Comments |
algorithms, hacks, Mathematics, programming | Tagged: Calendar, epagomenal days, leap year, Mars, Martian |
Permalink
Posted by Steven Pigeon
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 »
36 Comments |
algorithms, bit twiddling, C, embedded programming, hacks, programming | Tagged: Arithmetic, Integer, Luma, rgb |
Permalink
Posted by Steven Pigeon
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 »
3 Comments |
hacks | Tagged: Books, Used Books |
Permalink
Posted by Steven Pigeon
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 »
3 Comments |
hacks, Mathematics | Tagged: cdf, cumulative density function, Density Function, Fisher-Yates, Inverse, Inverse Method, pdf, PRNG, Random Variable, Rejection, Rejection Method, Ziggurat |
Permalink
Posted by Steven Pigeon