The T-Files


Mon, 13 Dec 2010

Can I break batteries by putting them in the wrong way?

If I put in batteries the wrong way (+ and - sides reversed), is there a risk that I will break them? Or the device? Or start a fire?

In particular, I am talking about rechargeable Ni-MH eneloops and cheap electronic toys for kids, and most of the time not all of the batteries are put in the wrong way, just some of them are reversed (which is probably even worse, right).

Answers over at StackExchange.

Tue, 28 Sep 2010

Shuffle Kerfuffle

One of the most important lessons to learn from cryptography courses is that nothing is as simple as it looks (especially if it does not look so simple), and if you use ad-hoc methods instead of publicized and proven algorithms you will not get it right. And I rightfully got slammed a little when somehow asked how to shuffle an array and I suggested the procedure I came up with when I was twelve and have been using ever since:

Loop a couple of times (length of array should do), and in every iteration, get two random array indexes and swap the two elements there.

Of course, using something established such as the Knuth-Fisher-Yates Shuffle would be better, and I can see that my algorithm is flawed in that it has a (marginal) bias for keeping the array elements in their original positions. However, it'd like to be able to understand why, and be able to quantify the bias.

My current proof is based on two observations:

  1. An element that has not been touched by a shuffle will remain in its original position
  2. An element that has been touched by at least one shuffle will end up in a completely random position (even if that position is the original).
With these two observations in place, I think I can deduce that the probability that the shuffle is not ideal is the same as the probability that not all cards have been touched, which is easy to calculate and declines as the number of iterations increases. The first observation is obvious, the second one needs a proof (that includes the fact that the random position is also independent of other elements' positions, see the rotation paradox).

The proof still eludes this poor math-school dropout (who did do very well on Elementary Statistics in his day, though, and has studied Pseudorandom Number Generation for an unbelievable four semesters). I have brought it up with the experts.

Fri, 13 Mar 2009

Verticals

Not really a "tech" question. Maybe I need tags more orthogonal than Blosxom's hierarchical categories.

This question is more or less directed directly at Charles Hodgson, even though (or especially because) he has already discussed the adjective vertical.

Business types in their presentations like to talk about their verticals, by which they seem to mean industries. Where does that come from, when did it start, and are there horizontals (or diagonals), too?

Fri, 19 Aug 2005

Sort with stop key? Anyone?

I wonder if I can just post tricky questions on my blog and expect answers. Probably not. Anyways, this one is for the algorithm gurus (I cannot even remember how quick sort works anymore, and my Knuth Bible is about eight timezones away right now):

I want to sort a rather largish amount m of items, but because I only need to first n items, I would like to terminate the algorithm once these n items have been found and not bother to sort the whole rest (because n << m).

That would be Step One. Step Two would be an algorithm that can be put in streaming mode, so that I can iterate over the items in order, without knowing how many I need in advance (because the items will go through a filter that discards some of them. Running the filter before the sort is not an option, as the filter is very heavy and should only be invoked for n' << m items).

Thanks.