sigh A message box telling me what I already know since I initiated the action.
To reproduce:
Seems to work as well for other errors (or messages worth showing) in the “Show log” dialog. The “Update” dialog, however, shows errors directly in the window, without needing a message box (which I highly appreciate):
One-dimensional elementary cellular automata are very simple. You just got a single row of cells which have one of two states: On or Off (0 or 1, living or dead, whatever you want to call it), so they can be nicely represented by a simple two-color bitmap.
States in cellular automata change according to the neighbourhood of a cell in the previous (global) state. Let's say you're a living cell (On, 1) and your neighbours in both directions are dead (Off, 0). Suppose you also have a table that states that your state in exactly this case changes to dead (might happen, maybe you just were too lonely to exist, don't blame me). But in another configuration your left neighbour might still be living and in that case you get to live on. Or in yet another configuration you are a dead cell and regardless what your neighbours are you change state to living.
Such a table essentially needs only a few things: State of a cell, state of all neighbour cells (two in this case) and the state of the cell in the following generation. We can visualize this as follows:
In the top row we have a cell with two neighbours, one left, one right, so three cells each. The bottom row gives the following state for each configuration. As you may have noticed, there are only eight possible configurations. And we can impose an order on them as I have done here. And the relevant part, once that order is established is simply a string of eight zeros and ones—so essentially eight bits. We can simply write this rule as a number. What wonderful way of shortening things. This numbering was conceived by Stephen Wolfram, a British mathematician and thus it's called Wolfram code or a Wolfram rule.
The rule pictured above is rule 30.
So we now know that such a cellular automaton might be described by a single number and that it can change states. What good is that?
Well, we might display a certain state of the automaton as a series of either black or white boxes:
and then we might display each of these states below the previous one:
et voila, we got a nice picture. Slightly chaotic, but that's usual for rule 30 and we got some nice recurring triangle formations in there.
So the point of all that was to generate a weird-looking image. Now for the fun part of this. Programming such a beast.
It isn't exactly complicated to do this, so lets start at the top:
We obviously need some control over how much is calculated and rendered. I put a single cell with state 1 in the center of the first row (initial state) so it's advisable to choose an uneven width because many patterns fan out to both sides (as seen above) and then they reach the left and right edge simultaneuosly. Height might be chose for a similar reason, since as the pattern fans out and reaches the sides it gets meaningless pretty quickly.
If the rule is given as the first parameter we only ask for it if it lies outside the permitted range (0–255), else we ask anyway until a correct rule is given.
Following that I wrote a simple subroutine which dissects the numerical rule into its eight parts:
We then initialize the area in which we store the states of each cell for each generation:
Basically we just initialize everything with zero and add a single one in the center of the first generation.
We have a problem with this approach, however, since when states are computed they need a neighbourhood. But how does the neighbourhood look for the first and last cells in each row? At first I simply put another cell to the left and right of the row, containing a zero. This works fine for most rules and we leave it as that for now. How one would implement this I leave as an exercise for the reader.
We might need a subroutine to display the whole area:
As you can see, that are actually two subroutines. They come in handy later.
What is still missing, however, is the calculation of successor states. So let's do that now.
Nothing fancy here, we just delegate the computation of a single cell to another subroutine. As you may note we display the calculated row immediately after we calculated it, this makes the watching experience while the batch file runs a bit less boring as we see a new line every few seconds (yes it is that slow).
Here we calculate the new state for a given cell, by using another helper subroutine which looks up the specific case from the table. We make use of the fact that the configuration of a cell and its neighbours are essentially three-bit numbers and the table is laid out in such a way here that we can access it simply by converting the configuration into a number between 0 and 7. The code for that looks a little ugly, since lots of escaping is needed (I escaped the parentheses just out of fear they might break something, as they often do when nesting structures).
But that was it, essentially. Running the batch without arguments produces the following prompt:
entering, say, 54 in there, yields the following picture:
The actual source code is a bit longer, since I offer an option how the sides of the area are handled (all zero, all one, wraparound and copy, the last of which is now the default which seems the most sensible to me—rules like 169 look very different when calculated with the edges being zero).
I am now working on SVG export from within the same batch file and I hope I found all major bugs by now. But the first working version was just 54 lines long. I think, had I been using Java instead (which was the other choice here), I would have needed significantly more.
UPDATE (2008–12–26 16:21): SVG export is now done and works as it should. At the moment I am mis-using the terminal server in the uni to compute all 256 rules simultaneously:
The taskbar resides usually at the bottom of the screen (at least for 98.4 percent of users). But as widescreen displays become more prevalent (and since I usually have many windows open) it's tempting to put the taskbar either to the left or to the right of the screen. That has the benefit that you usually have longer window captions visible on each taskbar button, especially when there are lots of windows. And at least for me a wide monitor doesn't add much value over one with an aspect ratio of 4∶3. Things like browsing the web and writing code are inherently vertical activities and don't need as much space horizontal (ok, for IDEs like Eclipse or Visual Studio it's nice to have more space but I'd take more overall resolution over more horizontal resolution any time).
Now the taskbar displays tooltips for window captions that are too long to fit:
It does so for a vertical taskbar, too:
Now here lies the problem. While the tooltip on a horizontal taskbar doesn't get in the way very much since it would only overlay a status bar or similar the tooltip for a vertical taskbar intersects with the window content. This usually happens not in a location reserved for auxiliary purposes but rather in the main view of an application:
This is particularly nagging if you restore a minimized window that was maximized before so it begins immediately right of the taskbar. As seen above the tooltip overlays parts of the content of the window just restored. The tooltip appears about the instant the window comes up after a click so it sometimes appears right into content I'd like to see.
Since websites are usually scanned in an F-shaped pattern many websites have a navigation on the left. And I can see that on some regular software, too. The folder list in my e-mail client is on the left and gets neatly overlayed by the tooltip, for example. Since I restore it usually to look for folders with new mail this is particularly nagging, since I need a moment to get the tooltip out of the way. Doesn't sound much and is probably not nearly significant, but still, it bugs me.
Maybe it gets even worse with Aero enabled since then not the tooltip shows up first but rather the thumbnail view of the window which is even larger.
Probably the taskbar would be better off at the right of the screen, since there is seldom information one wants to scan immediately after restoring a window (at least I think so and can't think of counter-examples right now).
UPDATE (2008–11–08 13:56): Activating Aero seems to be a better option than I thought. The window thumbnail doesn't appear when restoring a window and the thumbnail only appears after the usual time, although after the click and not after hovering the mouse over the button as it does when the Windows Classic theme is active.
Recently I discovered that the suggestions that are built into the search bar of Internet Explorer and Firefox expose results from the Google calculator:
So I fired up Fiddler to look where those suggestion requests where going to and found the following URL (for the request 1+1):
http://suggestqueries.google.com/complete/search?output=firefox&client=IE8&hl=en&qu=1%2B1
The answer to that request was a little JSON which looked like the following:
I pretty-printed the output a bit, since it comes out as one long line. As you can see, there are two nested arrays, the first element of the outer one being the search query and the inner one containing the suggestions. If the query was processed by the Google calculator the first element of the suggestions is the result.
Knowing that I hacked together a little program that sends its arguments as a search query to Google and prints the first suggestion (which hopefully is a calculator result):
Mostly I like the ability for unit conversion. Although not everything works. And unfortunately requests for physical constants don't yield a result, which they do, however, when using Google search directly. So that may be an area of improvement.
The program was written in C# 2.0 and uses LitJSON for JSON parsing. It runs on Mono as well, though I haven't tried to build it there, but since it's all .NET 2.0 it should work without problems.
Executable as well as source code is attached.
UPDATE (2008–10–26 00:34): I have updated source and executable as follows:
It's fun somehow … I look for a very specific issue with .NET currently, namely how to get Unicode output on the console. Searching turns up the following (in decreasing order of frequency):
While the result does not please me that much (because I like Unicode and can't really stand applications that still live in 1960), what bothers me more is that there is so few helpful stuff on the web.
Now that I complain about it I have to admit, I read Joel Spolsky's blog as well as Jeff Atwood's. Both mentioned and founded stackoverflow.com, for exactly the same reasons. Now I just need to remember that the site is there and go there instead of Google when I need help. Might take a while to change my habits there.
UPDATE (2008–10–26 00:48): I found out how to use Unicode on the .NET console: Just use UTF-8 as output encoding. I was so naïve to assume since .NET strings use UTF-16 and Win32 uses UTF-16 Console.OutputEncoding should be UTF-16 as well. I was wrong and didn't even bother to try UTF-8.
I found that elliotth's blog has some pretty interesting articles I skimmed over some of the very old ones and came across the following: Humans pay for context switches too. It certainly made sense in some way, although I think numbering pages backwards is a bit awkward for most people.
However, I wondered whether there might be an easy way to get backwards page numbers in Word. Page numbers are just fields and you can do all kinds of fancy stuff with those. So I poked around. There was just one problem: I couldn't find where to insert a field. And that with the glorious new Office 2007 where everything is neatly organized and no cluttered menus or layers upon layers of dialogs remain (to be fair, the menus are gone, the layers of dialogs are still there, though somewhat hidden for most of the time). This marks the first time I didn't find something I looked for in Office 2007 (which I use since March 2007).
Let's take a look at the why: The Ribbon has a nice tab called “Insert” (which is for pretty much anything that needs insertion, except citations and the like which reside in “References” section [granted, in English it suddenly makes sense, German … not so much]), consisting of the following sections:
Of all those sections Pages, Tables, Illustrations and Symbols make no sense so I skipped them entirely. Headers & Footers might have been something because document and section titles (which frequently go into the header) and page numbers (which frequently go into the footer) are also fields, but nothing there. Links: Well, nothing here, either. Which leaves Text. Where I never bothered to look into the “Quick Parts” drop-down which not only contains the (expected) document title, section title, author, date, etc. fields but also the more general field item:
I found that half a minute before writing this entry but about an hour after looking for it …
Funnily enough, I found it almost instantly in Word 2003:
As for the reverse page numbers, the following gets you page numbers that are counting down instead of up: {= {NumPages} – {Page} + 1}. Note that the opening and closing braces have to be entered using Ctrl+F9.
I came across an interesting series of posts today (via Linux Hater's Blog): Desktop Linux Suckage on Elliot Hughes's blog.
I'm about halfway through the series now. It is fun to read and not as offensive as the usual Linux hater posts (which I don't mind but others do).
I am still a Windows user and will continue to be so but some of the things he points out are not solely applicable to Linux and software on that platform.
Something very un-computer-like today. I am an avid reader of George R. R. Martin's A Song of Ice and Fire series. I read the first three books some years ago and just finished reading them all again as well as A Feast for Crows, now eagerly awaiting A Dance with Dragons.
In the recent months I also did many vectorizations of flag images on Wikimedia Commons and due to that read a bit on heraldry and blazonry. Not much, but enough to guess what a blazon would look like given its description and I even can describe simple blazons myself.
Anyway, I noticed a slight change in GRRM's series with A Feast for Crows. His descriptions of coat of arms of the numerous major, minor and lesser houses of Westeros were pretty simple in the past (i. e. up to A Storm of Swords) with their descriptions seldom more than “charge on a colored field” and usually not using heraldic terms for tinctures and charges. This changed, however, with A Feast for Crows where more complex coat of arms emerged as well as usage of certain heraldic terms, like barry, gyronny, countercharged, etc. I probably should have marked the pages as I noticed the occurances so unfortunately I can't give examples here but I think it might have been better for GRRM to stay with the tone of the previous books here. Not that I mind in particular but most people are not proficient with heraldic language and for them the simpler descriptions would serve better.
Although maybe I am nearly the only one to notice, at least I have been told by others that they didn't notice. But for me it's a slight stylistic break that was unnecessary.
Yesterday, shortly after finally setting up my other machine again, I decided to give Winamp another try. I used it as my main audio player back when I still used Windows 2000 but since I switched to Vista I converted to Windows Media Player, because I liked the look and feel of having my music collection with cover images, etc. all in one place. It proved to be somewhat slow on my old Pentium 4 2.53 GHz, though.
Enter Winamp. On Windows Vista. First start, it displays a nice dialog with skin selection (I didn't install any skins, so why that part in the dialog), the possibility to select file associations and whether or not you want to send anonymous usage statistics.
Fun thing here is: After wading through that dialog Winamp requests administrative privileges. Twice! And once every time you start Winamp again. I just wonder why. Neither file associations or anything else I found in the options Winamp would do needs administrative privileges. Nothing. Granting the request once (as was needed for Eclipse 3.3 to work properly) didn't change anything, Winamp still pesters me every time I start it.
And since I only have one keyboard, one mouse and one monitor here I either have to switch input devices or use Remote Desktop Connection. I went for the latter, for the most part and I figured since some command line work and music playing doesn't need many colors I could well use 8 bit color depth.
Well, turns out that Winamp likes to crash with only 256 colors. I don't know whether the music if should play is that colorful, but it reproduceably died right at startup. Only when I changed to a higher color depth the problem went away. Weird.
And as a side note: Winamp's media library is (at least to me) much more confusing than the Windows Media Player one and not exactly faster, so maybe I drop Winamp again.
UPDATE (2008–09–04 18:24): The UAC thing is solved now. There is a well-hidden option “Restore file associations at Winamp start-up” that was responsible for that. Unticking the box solves the issue. However, I have to stress that maintaining file associations is something you can do without adminstrative privileges.
A fellow student unearthed the following /. signature:
“Anyone else notice what x+k+c+d adds to? 42! :) [x=24,k=11,c=3,d=4]”
Interesting discovery. I wonder whether that was intentional. And it goes on: When adding up ASCII representation values of the characters you get 120 + 107 + 99 + 100 = 426 which includes 42 as a substring.
Said fellow student then discovered even more similarities between those two numbers:
<sh> sebastian@madlax:~$ factor 426 <sh> 426: 2 3 71 <sh> sebastian@madlax:~$ factor 42 <sh> 42: 2 3 7 <sh> This is a *bit* creepy for a coincidence.
So both numbers are even sphenic numbers and the prime factors of 42 are a substring of the prime factors of 426.
Scary. So xkcd seems to be linked to 42.