02/07/2013
So in previous installments, we looked at how to use the euclidean algorithm to devise a Las Vegas-type algorithm for primality testing. We also found that, in general, simply testing factors one after the other is much more efficient (but that doesn’t mean that there are not better algorithms to test for primality!).

We also considered only relatively small primorials (the products of the first
prime numbers) since they rapidly exceeded
. But just how fast do primorials grow?
Read the rest of this entry »
1 Comment |
algorithms, Mathematics, programming | Tagged: GCD, prime, primorials, relatively prime, SAGE |
Permalink
Posted by Steven Pigeon
25/06/2013
Last time we had a look at using the greatest common divisor and Euclid’s algorithm to devise a Las Vegas algorithm for primality testing. We also had a look at how the inclusion exclusion principle helps us determine the proportion of the numbers correctly tested.

However, we finished by asking ourselves if the method is actually efficient compared to, say, simply testing small divisors, one by one. Let us now find out.
Read the rest of this entry »
2 Comments |
algorithms, Mathematics, programming | Tagged: algorithm analysis, Euclid, GCD, prime, relatively prime |
Permalink
Posted by Steven Pigeon
18/06/2013
Last week we had a first look at a simple path finding algorithm with application to games. This week, let us have a look a the relative performance of the implementations considered: C# with a naïve implementation that scans the whole map multiple times; a C# implementation that uses lists to maintain and visit only the border of the solved region (affording massive speed-ups, one hopes); and C++ versions of these two variants, plus a C++ variant that uses set (as bitmaps) to maintain the border list.

In any quantitative study, the first thing to do is to collect data. The best way is to automate the collection, by, for example, adding a function that puts the player in all legal positions on the map, compute all the shortest paths, and measures how long it takes. One may also consider disabling the on-demand power policy as the CPU may jump (progressively?) in high gear as the data collection progresses, introducing bias.
Read the rest of this entry »
1 Comment |
algorithms, C-plus-plus, csharp, embedded programming, hacks, programming | Tagged: Comparing speed-ups, Map, optimizations, quantitative approach, shortest path, speed-up |
Permalink
Posted by Steven Pigeon
11/06/2013
The other day in class I was telling my students that sometimes simple strategies simply do not cut it. As an easy-to-understand example, I discussed the behavior of baddies in video games. If your game asks for the baddies to chase the player, the first thing you might try is to move the baddies in the direction of the player, without any other sophistication.

So the algorithm in this case is that you move the baddie closer to the player (or try to, as there might be obstacles), and this translates to something like two lines of code:
Read the rest of this entry »
6 Comments |
algorithms, Artificial Intelligence, C-plus-plus, csharp, embedded programming, hacks, programming | Tagged: baddies, Dynamic Programming, Map, maps, real time, tiles, video games |
Permalink
Posted by Steven Pigeon
04/06/2013
In a few previous entries, we looked at how to capture, parse, and evaluate the precision of a NMEA-capable GPS. The next step is to take it on a test drive.

The setup is simple: a laptop, a USB GPS, a car, and a map. The map is provided by Google Maps, of course. The car and the laptop do not really matter (as long as one of the two runs Linux and has a USB port); the USB GPS is the Columbus V800.
Read the rest of this entry »
1 Comment |
Data Visualization, hacks, programming | Tagged: dilution of precision, DOP, GPS, PDOP, position, position error, road trip |
Permalink
Posted by Steven Pigeon
28/05/2013
The Euclidean algorithm, the algorithm to compute the greatest common divisor, or
, of two numbers, dates back to antiquity (obviously). We can use it to make a fast test for primality, at least up to some confidence—and that’s where the inclusion-exclusion principle comes in.

Let us begin by the Euclidean algorithm. Originally, the algorithm was done by successive subtraction (and becomes quickly tedious as numbers grow), but the modern version, at least the one that I know of, uses divisions and remainders (modulo), and computes the
of two numbers
and
in
(counting division as an
operation), which is very fast.
Read the rest of this entry »
4 Comments |
algorithms, Mathematics | Tagged: Euclid, GCD, Inclusion Exclusion Principle |
Permalink
Posted by Steven Pigeon
21/05/2013
In previous installments, we looked at how to read data from a serial-over-USB GPS, then how to parse the data. However, getting data isn’t everything, we must also ascertain it’s valid

The first thing that comes to mind to test the device’s precision (while I don’t really know how to check for the accuracy) by plug it in, leave it stationary, and collect the readings for a good while
Read the rest of this entry »
3 Comments |
hacks, programming | Tagged: BU-353, Columbus V800, drift, GPS |
Permalink
Posted by Steven Pigeon
14/05/2013
While doing something else I stumbled upon the interesting problem of computing the average depth of nodes in a tree. The depth of a node is the distance that separates that node from the root. You can either decide that the root is at depth 1, or you can decide that it is at depth zero, but let’s decide on depth 1. So an immediate child of the root is at depth two, and its children at depth 3, and so on until you reach leaves, nodes with no children.

So the calculation of the average node depth (including leaves) in a tree comes interesting when we want to know how far a constructed tree is from the ideal full tree, as a measure of (application-specific) performance. After searching a bit on the web, I found only incomplete or incorrect formulas, or stated with proof. This week, let us see how we can derive the result without (too much) pain.
Read the rest of this entry »
2 Comments |
algorithms, data structures, Mathematics | Tagged: average depth, Binary Tree, full tree, path, path depth, Tree |
Permalink
Posted by Steven Pigeon
07/05/2013
Last time we looked at how to get the data to the GPS and now we will have a look at how to parse the data. Turns out that except for the check-sum, everything is pretty straight forward, even in Bash.

So, why bash in the first place? Well, there’s not real reason except that for the something else I’m working on, it’s the ideal glue-code language, allowing me to invoke simply other programs that I do not want to re-code (or take parts of) to do what I want. I must say that I even have a C# version of the GPS data grabber, but while fancier, it does not bring much more than the Bash version.
Read the rest of this entry »
8 Comments |
Bash (Shell), hacks, programming | Tagged: cut, GPS, grep, NMEA, sed, tr |
Permalink
Posted by Steven Pigeon
30/04/2013
I am presently working on something that requires geolocation. Not knowing much about GPSes and related topics, I decided to get a USB GPS. This week, let’s have a look at how we can extract information from the USB GPS using Bash.

The first step is to locate your USB GPS as a device. If it’s NMEA compliant, it should mount automagically as a USB serial port. You would think that lsusb -v would show you the device, but it does not always. Sometimes it shows as “Brand X GPS”, sometimes it only shows as a generic device, say “MediaTek Inc.”, or even as a modem. It will typically show up as /dev/ttyUSB0 or /dev/ttyACM0.
Read the rest of this entry »
4 Comments |
Bash (Shell), hacks, programming | Tagged: GPS, serial port, usb gps |
Permalink
Posted by Steven Pigeon