Lyperhinks

There were some considerable announcements made this week and last week:

First of all, there was a buzz on the Postgres list that Sun was going to buy up MySQL. The official announcement at MySQL mentions that it went over the counter for the price of 1 billion US dollars. And then, at the same time, I was thinking of the US president’s last ditch effort to kickstart the troubling US economy.

Apple had some news too: they announced the newest MacBook Air, which they claim is the thinnest laptop ever made. Uh, notebook. Or whatever the current fashionable name is for ‘compact computer’. The announcement eventually had me end up at this comic, which explains how the MacBook Air can save the world.

Via Burningbird, I found out that the US’s Library of Congress has a blog, plus, that they are working together with Flickr to bring pictures and photos to the public domain (let me rephrase this cautiously: they’re going to publish pictures with no known copyrights restrictions). For now ‘only’ 3,000 pictures have been made available, more may come in the future. This is good news for hard-drive manufacturers!

Posted in Hyperlinks, Ordinateurs, We-reflect-news | Tagged , , , | Comments Off on Lyperhinks

Is there a statistician in the house?

I downloaded the Visual Studio 2008 Express Edition ISO from the Microsoft site and discovered that specific stuff I was looking for isn’t supported in that special edition. I guess there is (or rather was) a huge difference between ‘Orcas’ and the Express Editions (Earlier at xsamplex).

That said, there was a time for looking through code and then I discovered that at Microsoft’s WPF site somebody had uploaded a Peer-2-Peer version of Sudoku (see also this post, or rather, this photo). This reminded me that a couple of weeks ago, I was asked to help with an algorithm that generates a complete filled out Sudoku puzzle. This I did and after that I moved on. So, that Peer-2-Peer version apparently has an algorithm that does the same, so when I opened the particular source file, I was shocked to find the following code (see my tag):

for (int iRow = 1; iRow < = 9; iRow++)
{
    for (int iCol = 1; iCol <= 9; iCol++)
    {
        iNum = rnd.Next(1, 10);
        while ((IsInColumn(iNum, iCol) 
                  | IsInRow(iNum, iRow) | 
                   IsInThreeByThree(
                      iNum, 
                      GetThreeByThree(
                         GetThreeByThreeIndexFromRowCol(
                             iRow, iCol)))) 
                  == true)
        {
            // Generate a number to be put on the grid..
            iNum = rnd.Next(1, 10);
            iAttempts++;

            // AH01 -- OH NOES...
            if (iAttempts == 100)
            {
                bStuck = true;
                break;
            }
            // AH01 -- Ends.
        }
        if (bStuck)
            break;
        iAttempts = 0;
        arrPuzzle[iRow - 1, iCol - 1] = iNum;
        if (iRow == 9 && iCol == 9)
            bDone = true;
    }
    if (bStuck)
        break;
}

Let me go back a couple of steps. In Sudoku, a 9 by 9 grid is divided in nine 3×3 grids: the numbers in each 3×3 grid MUST be unique and between 1 and 9. Additionally the same rule applies to each horizontal and vertical line in the grid. A fairly good description can be found at Wikipedia.

The main algorithm for filling out a 3×3 grid with 9 unique numbers, is a statistical routine that should have came up during math classes as the ‘coloured balls in a basket problem’. There’s 10, no, lets say 9 different coloured balls in a basket. What are the chances of (blindly) picking out the red ball in the second turn?

Back to that source snippet: Random generating a number from 1 to 9 The author randomly draws a number between 1 and 9, checks if the number has already been drawn. If so, he keeps generating a random number until he gets a number that fits the needs. Here’s where the problem starts: the more numbers you have picked, the less chances there are going to be that your random generator is going to pick one of the numbers that has not been drawn yet. Take a look at the example on the right (an animated gif, opens in separate window): If the stars are aligned right and your computer is in a bad mood, it may just take a while to randomly generate those last numbers. Certainly, you could throw in a 8-core computer to speed up the random number generator but the problem will still be there. The programmer knew this too hence the reason for that ‘jailbreak condition’ (“After 100 attempts I think I should break it off otherwise it looks like the program has crashed”).

Randomly drawing numbers from 1 to 9The right way to do this is, by actually drawing these numbers from either a list or an array as shown in the animated GIF (click on the image on the left). This effectively means that your randomize Next routine needs to adjust dynamically after each draw: after all, every time you draw a number, the amount of available numbers decreases by one. There’s a minor catch here, but that’s up for you to figure out.

So: what’s the point of bringing this up? The Sudoku Peer-2-Peer application is a great showcase of the latest and greatest .Net technologies but fails horribly on the basics: using math to solve a complex problem. I do (for example) have more respect for this guy who threw in a genetic algorithm to solve the problem. This is overkill for sure because it can take up to 10 minutes to fill out a complete grid. At least he understands (and showcases) how genetic algorithms work.

Update (01/21/08): Related: Who killed the Software Engineer?

Posted in Programming | Tagged , , | Comments Off on Is there a statistician in the house?

Around the world

A couple of Rosie Swale Popedays ago, the local news paper had an article about a lady from Wales who’s walking around the world. Rosie Swale Pope started her run in 2003 and is scheduled to finish her travels this year. She passed by Truro, I think and is on her way to Halifax now.

The Daily News also has a short video clip, which shows her walking through one of our famous (Canadian) Winter storms (I bet that the clip won’t be archived and will go in the Halls of 404 in a couple of years, so I’d say hurry and watch it, before it disappears). Looking at the footage, I keep thinking how dangerous it is to actually walk on the road with that big of a cart behind you.

That said: good for her for doing this on her own. Stay safe and stay clear from the snowplows, ma’am.

Posted in Provincial-Scotia, Truro NS | Tagged , , | Comments Off on Around the world

Oh, wait.

You cba-button4thumbnail.jpgmay have noticed that the Canadian Blog Awards have started: the first voting round is open until January 21st. Xsamplex has been nominated in the Tech category: If you want to vote for me, go ahead. Last year, we ended up at a respectable 4th position (I think. No maybe we just didn’t. I don’t remember. No comment. I need to call my lawyer). Yo, what happened to Amber (actual link to website goes here)?

That said, I hope you consider voting on Alan’s blog (Category: Personal Blog), The Internationalist (Category: Local Blog) and TopLeftPixel (Category: Photo/Art). And if you really don’t feel like voting for xsamplex, you can vote for Eastern Blot. I can’t speak for the other categories so if you have extra time and feel like exploring some (good) Canadian blogs, go ahead. For now, congratulations to all nominees for making it on the shortlist.

You may have noticed that this year’s voting process has changed: the polling software tracks votes per IP address, meaning that your loved one (who might be on WiFi) can’t (officially) vote. I fear a revolution is brewing. The other thing I thought was curious is, that it appears that the previous award years seem to have disappeared from the Interweb. I think this is a conspiracy.

Previously on xsamplex (CBA 2006): 16.What, Quelle Surprise, There , Sidenotes, Not even tech and Dump, snow. The best quote of the 2006 awards comes from a user called ‘alfons’ who singlehandedly reduced my chances of becoming president of Votingstan:

Hopeless.
I’ll vote for giggling Amber.

Posted in Hyperlinks | Tagged | 6 Comments

Lied des Lotterieagenten

People Brecht and Weillwho are familiar with this blog, know that I like early 20th century classical music, particular the music from the early 20s to the 30s. In this time of turbulence (the socio-economical problems in the Thirties and the rise of fascism), the (former) Weimar Republic suddenly became the cultural center of Europe. Classical composers experimented with dissonants, foreign music styles (North/South American music styles like jazz, blues, tango) and some of their material even ended up being used during protests, demonstrations and that. In a country that moves to a confrontation between political parties and everybody in between and where the rule of law is slowly being dictated by one party, unlikely friendships are struck, most of them to protest the order of the day.

One of the most successful collaborations was the one between the poet Berthold Brecht1 and (Jewish) composer Kurt Weill: their ‘The Three Penny Opera’, an opera with a critical look at society and morals, heavily accented with jazz melodies and rhythms (‘un-german music’), became such a huge success that their works soon attracted the attention of the Nazis who eventually forbade the performance of many of their works.

In this precarious situation, Weill eventually turned to an old friend (Georg Kaiser) with who he writes a ‘less confrontational’ opera, ‘The Silverlake’. Although being presented as a ‘volks oper’ (people’s opera), so to appeal as to many people as possible, Nazi-party members and followers manage to cause riots during its performance. A couple of days after, the Reichstag fire breaks out and, well, the rest is history.

Which brings me to today’s ‘Past-The-Bridge’ posting with a sound fragment of the earlier mentioned opera ‘The Silverlake’: it’s a portion from the ‘Song of the Lottery agent’ (fragment 30+ seconds), in which a (lottery) salesman suddenly announces that the main character has won ‘the big money prize’ and begins his song in (surprise, surprise) tango style.

Posted in Past-the-bridge | Tagged , , | Comments Off on Lied des Lotterieagenten

And then some more

I ran into a couple of surprises this week: First, I noticed that Mozilla now has their own video outlet/pod cast, Air Mozilla (Requires Flash 9). The video cast is spearheaded by Asa Dotzler. Older footage can be found at YouTube, at the Air Mozilla channel (warning, it appears that the YouTube channel is not really up-to-date, but it does have footage of interviews with the Chief Mozilla Wrangler, Mitchell Baker).

Also, much to my surprise, I found out that MTV apparently has a multiplayer blog, which brings you everything from ‘Halo 3 to Desktop Tower Defense’. I generally don’t read these kind of gaming blogs (for obvious reasons).

This reminds me that I ended up at that MTV blog via this Joystiq posting (‘Do you want a Portal 2?’): However, the posting there doesn’t really link to MTV’s blog. I guess it’s either hard to create hyperlinks to 3rd party sites or that hyperlinking isn’t usual anymore.

Posted in Hyperlinks | Tagged , | Comments Off on And then some more

SoundEx

A couple of days ago, it was the 70th birthday of Donald Knuth (or rather, his webpage), who as you found out, is hero to many programmers around. I think he’s still working on completing his masterwork, ‘The Art Of Programming’. Anyway, his birthday has not gone unnoticed in the blogosphere. It’s almost like everybody knows each other. No, really. Really.

That brings me up to something (slightly) related: I was using DailyMotion to find older clips of the 80’s band Blondie and the search result of that site always seem to include references to movies with blondes; some of them quite, lets say, exquisite. I won’t link to a URL of such, but I encourage you try it out. Obviously, DailyMotion is using a ‘soundex’ routine: this is an algorithm that indexes keywords by sound based on (language-specific) rules. This works brilliantly for looking up people’s last names (or even first names) but not for searching specific terms like the example I mentioned earlier.

Seriously:If I’m searching for ‘Blondie’, I’m expecting results for Blondie and not ‘Blond’, ‘Blonde’, ‘Blondes’, ‘Bland’, ‘Britney Spears’. And definitely not ‘2 h0t bl0nd3s k1ss1ng 3ach 0ther’1.

1 Obviously, I used ‘some encryption’ there to ensure that your kids don’t end up on this kids-safe website when they google for ‘Blondie’. You’re welcome.

Posted in Programming | Tagged | Comments Off on SoundEx

Passwords

A couple of months ago (around the same time that I was looking into the sources of the .Net version of KeepPass) I ran into this page: an algorithm to generate pronounceable passwords1. Well, at least a bit more pronounceable than the ones generated by password generators like the one that is used in KeepPass.

The original code was written in Java (by Thom van Vleck, if I’m not wrong) and it appears that there’s also a C++ version available.

Not to be outdone by these formidable programmers, I converted most of the code to C#: I don’t dare to say ‘porting’, which it obviously isn’t. However, I made drastical changes to how the GPWData class is being called: all of the functionality now is IN this class (including password generation and initialization). This makes more sense and it’s also a bit more elegant to use, as shown in the following example:

            GPWData npdata = new GPWData();            
            npdata.GeneratePasswords((int)numPasswords.Value , 
                (int) numPasswordL.Value);
            
            foreach (string s in npdata.Items)
            {
                textPasswords.Text += s + "\n";
            }

I dumped the code in the Public Domain which means that you can use it for whatever you wish to use it as long as you credit me and the original authors. Go grab the sources. The zip-file only contains the sources: I generally don’t add executables to full-source projects. Also, the target platform is .Net 2.0.

1 From that Multics page: The routine was modeled after Morrie Gasser’s ‘Random Word Generator for Pronounceable Passwords’. The original routine was then standardized (adapted might be a better word) by the NIST

Posted in Programming | Tagged , | Comments Off on Passwords

Round

Last night, I decided to follow the Iowa Caucus thing: Apparently Obama and Huckabee are now considered (repectively) Democratic and Republican front runners. I also tuned into to hear their speeches and thought they were dull and boring. This brings me to the actual topic of this posting: over at the BBC, readers discuss the surprising win of the two White House hopefuls and the following comment just stuck out (and trust me, I didn’t take it out of context). I took the freedom to highlight the ‘offending’ portion:

As a Ron Paul supporter, I feel neutral about the Iowa results. We weren’t expecting to do well there, we beat Guiliani, and were only 3% away from 3rd place. On the other hand, 5th place people don’t get talked about. I am optomistic[sic] about Wyoming and to a lesser extend New Hampshire.

This is like saying that I was born 10% earlier than my twin brother. And I’m 45 grams sure he would protest to that fact, since he has always claimed that it was him who kicked me out of my mother’s womb because he thought ‘I needed to grow up and get a life’ (which I eventually did for 73% of my life, which is 3 grams more than him).

3 Percent of what is that again? Maybe some people should be barred from using statistics and percentages.

Way earlier, I read this brilliant UnCov commentary about Pownce, which is a Web 2.0 site that allows you to send ‘stuff’ to your loved ones. Which is sort of less similar like sending mail with attachments, nonetheless. Too bad the Pownce’s lead programmer pulled the post about ‘how to do rounding of floating point numbers’: it be interesting to know why a lead programmer would round floating point numbers using strings (the pulled article had interesting comments how to do this nicely using simple math, but alas).

Posted in Hyperlinks | Tagged , | Comments Off on Round

Call Of Duty 4

A Pripyat sniper missioncouple of weeks ago I ended up buying ‘Call of Duty 4: Modern Warfare’ (Wikipedia). The game, as the title suggests, is situated in today’s world (instead of the usual WWII setting): the single player portion delivers a slightly unrealistic story about a revolution in an (unspecified) Arab country and ties that together with a storyline about a nationalist faction in Russia. You play two officers: a staff sergeant in the USMC and an SAS operative and (obviously) your job is to stop the terrorists at all cost (no, really).

Before I continue to elaborate on the single player missions: I was pleasantly surprised about the hardware requirements: I had no problems running it on my current preferred setup. The game has excellent frame rates at a 800×600 resolution: with a higher end duo-core 2 processor (5600 and higher) and a better graphics card (Nvidia 7200 and greater) you should be able to run COD4 comfortably on 1024×768 or higher, that is, including shadows and that. So: if you bought a computer just recently (lets say, a half year to a year ago) you should be able to run this game provided that it came with a 3D capable card (NVIDIA or ATI that will be). Parents, do notice that this game is rated ‘M’ (17 years+ older).

Continue reading →

Posted in Ordinateurs, Video Games | Tagged , , | Comments Off on Call Of Duty 4

Another one then.

For all: a good new year. At xsamplex, 2008 will be ‘more of the same’: we’ll bring you the bad, the good and (if I can make some more time) more code.

You may have already read about this one: The Edge’s yearly question to scientists, authors and others. This year’s question is ‘What has changed your mind and why?’. If you’re bored for a couple, it may probably take you a couple of hours to get through all the submissions (Metafilter thread and Slashdot thread). Additionally, more commentary at the Guardian.

There were two astronomy articles that caught my eye, last night. The first one is about the mysteries of our (outer) solar system, specifically about the Kuiper belt and the Oort cloud. The second one is actually a MetaFilter post about giant diamonds in space. The post links to an excellent site about stars.

The last link, is the one about the discovery of a 2500-year-old civilization in Russia. Actually, the find is at the bottom of Lake Issyk Kul (Wikipedia) in the Kyrgyz mountains. For a moment, I was thinking that it would be neat if news articles provided actual topography for these kind of locations.

Posted in Scientifically | Tagged , , | Comments Off on Another one then.

More snow

Maybe it’s too early to call it a day (Weather Canada issued snowfall warnings for the next 24 hours), but, I was just outside and noticed that the sky is almost cloudless. Or maybe this is the typical ‘calm before the storm’.

We had quite the share of snow a couple of days ago and then some more this morning (and early noon), which didn’t stop us from venturing out to the mall, and way before that, the traditional shoveling. I was smart enough to shovel most of the snow last night.

Talking about that mall (the Truro Mall, that is, and yes, they’re online too): I noticed that two major stores are relocating to elsewhere in town, making the mall a perfect location for the zombie movie series ‘Dawn of the Dead: Alive in Hubtown (part IX)’. Soon in a theatre near you, I hope.

Update (01/01/08): No extra snow for this region. Apparently plenty of snow in Cape Breton.

Posted in Truro NS | Tagged , , | Comments Off on More snow

Bird’s eye view

You may have heard about the death of Benazir Bhutto, who was prime-minister of Pakistan in the Eighties and Nineties. The shocking thing I thought was the fact that this was the second assassination attempt after she returned from exile. I’m not sure what to think of the tributes around the world: she and her husband were trailed by aplenty of corruption charges.

Earlier I read an article about some correlation between cities and the amount of intelligent people living in those cities: the article concluded (if I recall correctly) that the amount of libraries and newspaper circulation helped lift up those statistics. So: if you parents tell you to go to the library or read the paper, maybe you really should listen. If you thought the Internet was going to make you smarter then you’re probably wrong.

And then there was this (well-linked) article at Rolling Stone about the quality of sound in the music industry. I thought this was old news (I’m positive that I’ve read this story somewhere earlier).

Posted in Hyperlinks, We-reflect-news | Tagged , | Comments Off on Bird’s eye view