You are now a Polymer

Ever since I started writing, I’ve been just a little concerned over the name of the blog: Polymath Programmer.

I want to write on topics that I’m familiar with, that I’m fairly good at, that is interesting. Programming formed the main focus, and slowly mathematics as well. I want to bring in other disciplines as well, even if I’m not very good at them, because they’re interesting or somewhat related to programming. Thus was born my main quivers of articles.

Polymathy perfectly encapsulates what I’m trying to get people to understand, to bring together seemingly disparate topics and synthesise them into a solution. Since I’m passionate about coding and its related subjects, I came up with “Polymath Programmer”.

Even though it’s just two words, the first one is big (who knows what “polymath” means anyway?), and both are 3 syllables each. Add them together and I get a long URL. Not very conducive to spreading the word.

Yet it feels right. So I left it as it is. You’ll have to imagine the kinds of typing acrobatics I perform whenever I comment on another blog, or key in my URL. I remember I was registering for a local bloggers’ event, and I made 3 mistakes (3!) while typing in my own URL. I don’t like laptop keyboards…

I want to shorten it. I hope to get people following this way of thinking, of coding, of solving problems. It’s hard to say “I’m a Polymath Programmer”. Doesn’t roll off the tongue easily.

So I put forth all my linguistic skills into play, cutting words up, switching them around and joining them.

  • Polyrammer
  • Polygrammer
  • Programath
  • Polyprog

Finally, I came up with one. It’s even an actual word. This word actually has similar meanings to what my grand idea is.

Thou art now a Polymer.

What do you think? Hopefully, the chemists don’t hammer me…

Swing doors reopened – Flawed assumption

After all the brilliant math calculations I did while studying the math, science and psychology of opening double swing doors, I had an awful realisation in the pit of my stomach. Something’s not right.

I pored over my calculations, checking each symbol, diagram and math theory. All were correct.

I read through my deductions, following through the logic and found them to be in order.

Then I found it. It was small, almost insignificant, yet it changed everything about the article. Well, I’ve already written the entire article. I’ve spent hours coming up with the solution, and the arguments accompanying it. I’ve even prepared some funny remarks to break up the monotony.

So no way in the pits of fiery lava was I going to scrap the whole thing and rewrite it. Besides, I thought it would make an excellent fool of myse… , I mean, an excellent example of critical thinking.

“What is it?” you ask exasperatedly.

Patience, my friend. My original assumption was flawed, in that the goal of opening swing doors was to maximise the space between the tips of the doors (or door gap distance as defined from before). I should be concerned with maximising the space through the wall relative to the person opening the door, or (henceforth defined as) wall gap distance. Let’s bring our hypothetical stranger Bob back.

Swing doors, Bob and me

There’s another reason that could explain why we push swing doors in. Suppose each door is 1 unit wide, and I pull open one of the doors to 90 degrees as before. If Bob pushes the door on his side, he immediately gets 2 units of wall gap distance.

Swing door wall gap distance

As Bob continues to push the door and move in, the wall gap distance shrinks. Because Bob is still pushing the door open, it doesn’t shrink very fast. And you know what? Bob will probably open the door the full 90 degrees anyway, and end up with 2 units of wall gap distance. By then, he will be fully in the room.

I still think Bob should have used this solution:

Swing door subtle solution

He will have a temporary 1 unit wall gap distance, pass through the threshold, and then BAM! 2 units of wall gap distance (more actually) all the way, because he will be fully in the room.

And that should end my (temporary) obsession with swing doors.

Random Quote – Program X not social networking site

Today, my users got into a tangle. All of them got into a database deadlock.

Now my users have this habit of opening multiple windows so as to “appear busy”. Granted, my application wasn’t designed and programmed with many concurrent users in mind. Still, if more than 2 of them happen to access the same table, or heaven forbid, performing an update or delete operation on that table, the database throws up its hands in defeat and promptly denies further access. This includes other users accessing other tables.

So I did an sp_who (it’s a Sybase database) and found out the perpetrators. Then I wrote an email telling those who were doing non-critical tasks (and not still performing database transactions) to get the heck out of my database and log out of the application. And not return until half an hour later. Nicely coached in diplomatic language of course.

One of them asked if another colleague could continue, since that person was still performing a transaction. I said “Of course.” I also added something in the email that I thought was interesting (on hindsight):

Program X is not a social networking site. Log in, do your thing and log out.

Yes, I was a bit peeved and slightly mischievous at the time.

A typical month work load

Climber by Bettina Ritter
[image by Bettina Ritter]

I don’t really have a typical work day. It doesn’t mean I have an exciting job. It just means I can’t tell you what I’ll be doing the next day, because I don’t know for sure what I’ll be doing. What I can tell you is what I do in a typical month, generally speaking. There’s a point to all this, and I’ll start with…

From 8:30 am till 6 pm

Those are my work hours. Except Friday. On Fridays, I get to go off at 5:30 pm. My current job title is IT Analyst, changed from Systems Analyst. And if you think that’s vague, you’re right. My job scope is quite varied. Basically, my contractual terms require me to “do whatever the boss tells you to do”.

The current company I’m working for isn’t a software company. I just work in the IT department. What it means is, programming isn’t as highly regarded as I want, as what I read about in those programming blogs and sites. It kinda sucks, but it keeps me fed.

Let me tell you about the tools I use at work. I’m the “online guy”, which means any user interface related development comes to me. I use Visual Studio 2003 (C# and VB.NET) for all the web applications, console programs and a few software tools I create to help me. I also use Visual Studio 2005 for one particular application, with a graphical user interface. It’s too tedious to explain why I use both versions. It’s enough to know that I do.

I also use PowerBuilder for some Windows applications. It’s really, really painful to work with PowerBuilder code. I tell myself it’s the previous programmer’s skill that’s to blame, not the language, but I frequently fail. Tracing and debugging PowerBuilder code takes a lot of work for me. I really hate PowerBuilder… I think this calls for a separate rant article.

I’ve been asked to investigate C and C++ code on Unix machines too. So yes, I understand make files, shell scripts and cron jobs. I even know how to use the vi editor! I used to telnet to the Unix machines with TerraTerm, which is now abandoned for a more secure client application. Can’t remember the name because I rarely use it, because I rarely need to telnet.

Database admin, server admin and LAN admin

Despite the fact that I’m completely ignorant of SQL and databases in my formal education, I’m thrust full force into it at work. I’ve worked with the Oracle, SQL Server and Sybase databases, know most of the nuances between them on SQL syntax, and understand how to use stored procedures. I handle them all.

I am also completely in charge of a few Windows servers and the SQL Server databases running on them. Server maintenance, backup schedule and tapes, security patches, SSL certificates, IIS configuration, server performance.

Then I’ve got to know about the opening of ports for security purposes, who to notify when there are application or server changes. I need to know ping and tracert and ipconfig and other network related stuff.

All of that maintenance and administration is on top of my development work.

I don’t need to connect to Oracle databases now, but I used to do so with TOAD. There’s a limit to the number of licenses, so I wrote my own database connector program. It only does retrieval of data, basically the select statement, but it’s enough for current tasks. The Oracle databases belong to another team, and they’ve only needed me to help out rarely.

I use the Enterprise Manager and Query Analyzer for the SQL Servers. They’re great tools, and they come with the database installation, which is cool. There’s also another tool that has saved me many times. It’s the DTS, Data Transformation Services. I’ve used it to transfer data interchangeably between Oracle, SQL Server, Sybase and get this, Excel. Users take to Excel much better, so I need to use their form of “database”.

Designers, comparers and reflectors

I’m also a web designer. I suck at it, but I’ve been lucky enough to muddle through, and my users and their customers think my user interface looks awesome. I use Paint.NET (and sometimes the inbuilt Windows Paint program) for my image editing tasks. Plus I’ve got some colour tricks up my sleeve.

Some time ago, I had to verify some old code by another programmer. He can’t remember what he changed, and I obviously don’t know what could possibly be changed. I needed help! Fortunately, I found CSDiff. It allows you to compare two files (or even folders) and lists down differences between them. Much better than checking line after line of code by inspection.

And if you do .NET work, you must get the Reflector by Lutz Roeder, which had been taken over by Red Gate Software. It allows you to get back code from compiled .NET DLLs and programs. The result might not be the prettiest code, but with sufficient talent and patience, you can get something out of it.

I’ve used it on my own code and other team members’ code to check for disparity. Sometimes, you forget which version you’ve compiled that code into… Sometimes, it’s for self study, to understand what others have done.

The phone calls. Oh the phone calls.

My phone rings a lot. There are over 10 people in my immediate vicinity. I can tell you that, if you add up all the phone calls all of them ever receive in a month, it would still be less than what I alone receive in that same month.

Remember I told you I’m the “online guy”? That means a lot of users know me, and I don’t know all of them. Since they usually interact with the application interface, any problem is routed to me. Whether it’s data inconsistency, business logic query, application error or failure, all of them come to me. I’m a one-man helpdesk I tell ya.

It was so bad that sometimes, I’ve had to solve and handle user queries for entire days on end. Due to the nature of my work, the start and end of the month are particularly busy for my team. The number of times my phone rings goes through the roof. Maintaining decent phone etiquette starts to be a strain…

Wait, there’s something missing…

Where’s the source control software I’m supposed to be using? Well, I’m the source control. My team is very small in size. Company directives dictate we send work to our offshore colleagues. I think those (typically recent graduate) colleagues have some problems of their own, let alone set up a source control system that works across geographic boundaries.

I’ve not been with development teams at other IT departments, but I think we would totally fail at the Joel Test. Totally.

Despite these circumstances, I still manage to do development work, sometimes with surprising and outstanding results. I believe good task management is crucial to my balancing act. Which brings me to…

Holistic approach to programming

If you’re working at a software company, or on something focused on software and programming, I envy you. I really do. You’d probably get to talk with other programmers on interesting topics. Your work is really appreciated, because it goes to the bottom line.

I might not be programming exclusively, but I get to see the bigger picture. I get to liaise with people from sales, marketing and customer service. I get to talk with upper management and even the actual customers. I get to see the kinds of products and services offered, and how it’s implemented and supported by software.

Programming is kind of … an elite thing. When I was studying C programming in university, I was surprised that many of my fellow students struggled with it. I took to it like a fish in water. After a while, I realised that most people cannot grasp the thinking required in programming, even if they opted to study it themselves.

So I’m going to state this. Many people are not going to understand how great that piece of code you’ve written. Many people think software can make their lives easier, but fail to realise that not everyone can write good software.

This is where all your other skills come in. You have to sell what you’re doing to other people. Convince them that it’s useful, that it’s awesome, that it’s relevant, that what you do and what you propose is important.

Sell your ideas. Market your ideas. Your software is more useful if you see it from a bigger-picture point of view, from other people’s point of view. That requires you to understand other concepts. Concepts that aren’t related to programming at all. And you synthesise them together to make your code better.

And that, is my point.

The math of swing doors

Have you seen those bidirectional swing doors (as I’ll call them)?

Swing doors

They’re usually transparent, made of glass, and used in clinics, fast food restaurants, offices and department stores. Something weird happens when two people arrive at the swing doors on opposite sides at the same time. Have you ever walked along a street and happened to nearly bump into another person, and both of you were trying to figure out which way the other was going to go?

“Is he going to move to his left? Then I’ll move to my left. Wait! He’s moving in the same direction as me! Ok, I’ll go to my right. What?! He’s moving to my right too!”

I usually just stop, step to one side and let the other person choose a direction, and both of us will be on our merry way. Why are we talking about this again? Oh right, swing doors.

Swing door dilemma

So this stranger Bob is on the outside and I’m on the inside. Bob’s thinking if he should quickly push the door on his side and come in, but is scared of knocking me. I’m thinking if I should quickly pull the door on my side and go out, but is scared of him knocking me. It’s a dilemma, I tell ya.

So what do I do? Being the gentleman that I am, I pull the door open and I stay on the inside, silently beckoning Bob to come in. I don’t mind being a doorman for a while. Besides, I get to train my bulging biceps from pulling the door and holding it open.

Me as a doorman

Apparently, Bob is taken aback at being treated like a hotel guest. And stays shocked still for a couple of seconds. Could be stunned by the sight of my bulging biceps though, I’m not sure…

At this point, I have to digress and talk about the finer points of opening a swing door. To open a swing door with the least effort, you should use your full body weight to help. This can be done by fully leaning onto the door and push. Or you can straighten your arms, locking at the elbow and pull.

For some reason, people like to push. I also noted that few people actually straighten arms, whether it’s pushing or pulling. Maybe it doesn’t look natural? Or it looks funny?

Anyway, I attempted to fathom this, and concluded with 3 reasons. Based on the embarrassment factor, you’d probably bend your arm instead of straightening it. Pushing involves more of the triceps, whereas pulling involves more of the biceps. Since triceps are a larger muscle group than biceps, your triceps are probably stronger than your biceps. Hence pushing is easier. Doctors and physiologists, please feel free to correct me. That’s the first reason.

The second one is sight. You can’t see behind you, and you might knock someone over if you pull without looking back. The third is momentum. You’re striding towards the swing door, and you don’t want to stop and pull. The natural flow is to push the door.

So what does Bob do? He pushes the door.

No, no, no, no, no, no, NO! And I’m going to mathematically prove to you why that’s a bad decision.

First, let’s define the door gap distance as the shortest distance between the tips of both doors. So when both doors are closed, the door gap distance is zero. So opening swing doors means maximising the door gap distance so you can pass through. And what’s the shortest path between two points? A straight line.

Let’s consider the case where I open the door on my side 90 degrees. Let the doors each be 1 unit wide. Thus we have the following diagram.

Swing door minimum distance

What’s the door gap distance in this case? Using Pythagoras’ Theorem, d = sqrt(2).

What’s the angle if you open the other door such that the door gap distance is the smallest? Remember the shortest path? There should be a straight line.

Swing door minimum angle

So using Pythagoras’ Theorem again, we have
d = (length of hypotenuse) – 1 = sqrt(2^2 + 1^1) – 1
= sqrt(5) – 1
This is less than sqrt(2), which is when the door was closed.

The angle theta is calculated by taking the inverse tangent of 1/2. At this point, I have to digress into some basic trigonometry in case you can’t follow.

Angles in trigonometry

The hypotenuse is the side opposite the right angle in a right-angled triangle. The opposite and adjacent sides depend on the angle you’re looking at. And now, I’m going to give you a mnemonic.

toa cah soh

In the Chinese dialect, Hokkien, it translates to “big foot lady” or some such. At least, that’s how my teacher taught me to remember. So “toa” is tangent equals opposite over adjacent. “cah” is cosine equals to adjacent over hypotenuse. And “soh” is sine equals to opposite over hypotenuse.

What’s that got to do with the inverse tangent? Well,
tan(theta) = (opposite) / (adjacent) = 1 / 2
Therefore, theta = inverse tangent of 1/2, which is roughly 26.5651 degrees.

Notice that at this angle, the door gap distance is smaller than when the door was closed (that is, the angle is zero). This means opening the door actually shrunk the door gap distance. What were we trying to do with opening the door? Maximising the door gap distance. Peculiar, isn’t it?

Which leads me to the next question. At what angle would we have the door gap distance to at least be as when we left the door closed?

Next angle with same closed door gap distance

You’ll have to study the diagram carefully for the following discussion. From the sides formed by p, q and d, we have
p^2 + q^2 = 2 (Pythagoras’ Theorem)

We also have
p + r = 2 (convince yourself of this by inspection)

We also have
sin(theta) = (opp) / (hyp) = (1-q) / 1 = 1-q

We also have
cos(theta) = (adj) / (hyp) = r/1 = r

From a trigonometry property (I can’t remember what it’s called), the sum of squares of sine’s and cosine’s of an angle is 1. So
(sin(theta))^2 + (cos(theta))^2 = 1
(1-q)^2 + r^2 = 1
=> 1 – 2q + q^2 + r^2 = 1
=> -2q + q^2 + r^2 = 0

Note that p + r = 2, so r = 2-p.
We also have p^2 + q^2 = 2, so q^2 = 2 – p^2

Substituting, we have
-2q + 2 – p^2 + (2-p)^2 = 0
=> -2q + 2 – p^2 + 4 – 4p + p^2 = 0
=> 6 – 2q – 4p = 0
=> p = (3-q) / 2

Substituting into p^2 + q^2 = 2, we have
((3-q) / 2)^2 + q^2 = 2
=> 5q^2 – 6q + 1 = 0

Using the quadratic formula, we solve for q,
q = [ -(-6) ± sqrt( (-6)^2 – 4(5)(1) ) ] / 2(5)
= 1 or 1/5

Since q should be less than 1, therefore q = 1/5. With that, remember that
sin(theta) = 1-q = 4/5
Using the inverse sine, we have theta = 53.13 degrees.

There’s actually an easier way to calculate theta. I was puzzling through the arcane math formulae that I’ve not touched for a long time and gotten a wrong result (both my q’s were greater than 1). I needed to bathe anyway, so I took a break.

As soon as the water from the shower head hit me, it hit me. There’s a simple and more elegant solution to this!

Swing door mirror angle solution

The angle to reach at least the door gap distance when the door was closed, was double the angle when the door gap distance was the minimum! It’s a mirror image! Just look at the diagram above and convince yourself of that. So the angle is 2 * 26.5651, which is roughly 53.13 degrees.

Yeah, I’m a dunce. Goes to show that sometimes, taking a break really does give you a new perspective on things. Elegant solutions can pop out of the most obscure circumstances. Well, at least I got some practice with algebra and trigonometry functions. Oh right, I nearly forgot why we’re doing all this.

Are you telling me you’re going to push the door 53 degrees in, when you could have the same door gap distance without doing anything in the first place?!

The other obvious solution to this is to open the door the other way, so the door gap distance becomes larger immediately. But we’ve already established that most people don’t like to pull on doors. And now, I’m telling you there’s a subtler solution without using much more energy. Check this out.

Swing door subtle solution

Some people can’t just accept a polite gesture, can they?

P.S. There’s a flaw in the argument I’ve presented in this entire article. Can you spot it?

Quivers, RSVP and the Singaplogosphere

This will be one of those writings with no particular direction. Feel free to go read something else that might be more interesting, like the stock market or something.

Archery, Bows and Clairvoyance

I’ve always found bows in RPGs kind of … quaint. It feels to be one of the flimsiest weapons available. It’s practically useless in close combat. And you need two components for it to work, the bow itself and arrows.

It works great for long ranged attacks though. It also brings with it other factors to consider. Wind speed, speed and direction (or velocity for the physics-inclined) of a moving target and angle of trajectory.

You also need to keep in mind the number of arrows you have at hand. I’m so afraid of running out of arrows in games that sometimes, I don’t shoot them at all. I would save them for more important battles, such as boss fights. Of course, the character was usually physically weak (like Rosa in Final Fantasy IV), so the character ends up using other skills like magic to wreak havoc. And I ended up with a lot more arrows than I expected.

There are also different types of arrows in the games. Like fire-based ones for fighting yetis, snowmen and other fire-fearing enemies. Or lightning-charged ones for fighting water monsters.

I too have different types of arrows and I keep them in separate quivers. There’s the quiver of mathematics, quiver of programming and I usually shoot arrows from my quiver of curiosita.

I encountered this term curiosita from the book How to Think Like Leonardo da Vinci by Michael Gelb. The author defines it as

An insatiably curious approach to life and an unrelenting quest for continuous learning.

That might explain my fascination with puzzles recently, such as the one on digital clocks and the math puzzle in a game.

The thing is, I feel like I’m shooting all those arrows into the future, and hoping that when it’s the present, someone, like me, and hopefully you, will find these articles useful, interesting, thought-provoking and preferably funny and downright entertaining too. I don’t always hit the target. I just try very hard to be on the mark.

So I could use some help here. If you have anything you want to talk about, math or programming or even general fun stuff to think about, send them to me and I’ll write something on it. Like puzzles. I love puzzles. Not too hard though… Oh what the heck. Send them to me anyway (original ones please, or cite their source.). I need to look publicly foolish once in a while, trying vainly to solve a puzzle or write on a subject … and failing. Humility’s good for the soul, I’ve heard.

Which brings me to…

Repondez s’il vous plait

I left all the accents alone. R.S.V.P. is short form of a French phrase that means “please respond”. I’d love to hear something from you. In fact, I’m so desperate, I’d love to hear anything from you.

My colleagues don’t really talk about programming very much. Unless they’re in trouble. Then they’d sometimes ask me for suggestions. So I don’t get a lot of intelligent conversation about programming. Not that my colleagues aren’t intelligent. Just nothing about programming. The weather, current affairs and how the latest corporate management rule is going to mess up our lives pretty much fills up our conversations.

By the time this article you’re reading is published, the material is probably about 18 hours old. By the time you actually read it, it’s probably about a day old. I use the scheduling feature of WordPress. Typically, I write the articles the night before and set them off to be published at 5pm the next day. That’s 5pm Singapore time, which is 8 hours ahead of UTC (+0800). That’s about 5am in the morning for America and 9am for United Kingdom.

I do my web site stuff at night, around 8pm to 12 midnight. So if I respond late to your comments and emails, it’s because of the time zone difference. But please feel free to talk to me. You will make a lonely programmer very happy.

You don’t even have to type out a comment or email if you don’t feel like it. Just think of it in your mind. I’ll receive it, because amongst my many talents, I’m also psychic. I’ve already received a few comments in this manner. They usually pertain to enlarging some male body part, so I ignore them. I might even have to set up an ethereal spam filter soon. Do you know of a service like this?

And I want to thank all the wonderful people who’ve commented here or emailed me. I’ve even got a notable visit from the eminent Raymond Chen from The Old New Thing. I jumped out of my chair when I saw his name. I kid you not.

The Singapore blogosphere

Because of my lacklustre attempt at reaching out to people in a geographically agnostic way, I’ve decided to see what I can do closer to home. My impression of the Singapore blogosphere or Singaplogosphere (you know, that’s actually quite cumbersome) is dominated by the technological, political and the personal genres.

I know it’s much more than that now. I found out about this event called Social Media Breakfast, Singapore version, and I attended its 3rd event. It was awesome! I met lots of wonderful people. Then I attended the 4th event (with the practical modification to brunch instead of breakfast. Singaporeans do not like waking up at the unearthly hour of 8am on a Saturday morning to attend an event). It was just as awesome!

Sadly, I didn’t find any programmers there. Everyone’s eyes glazed over when I mentioned math and programming in the same sentence. They’d probably glaze over even if I mentioned math or programming in its own sentence. But everyone’s passionate about something. They’re energetic, opinionated and generally nice people to be around with.

They are so friendly, they managed to get me into Facebook. Yeah, friend power! It’s also why I left Twitter and joined Plurk instead. I think social media sites mean nothing to you if you can’t find a way to have interesting conversations there, whether you invite all your friends or you make new ones.

With that, here are some of the interesting people I know:

  • Daryl Tay, a social media enthusiast and founder of Social Media Breakfast Singapore
  • Claudia, who is in love with her Nikon camera. Check out her spinning photos.
  • Tech65 on technology in general. Check out their podcasts.
  • Sheylara. She’s famous. Seriously. Her face is plastered all over the XBox poster ads in Singapore.
  • Darryl Kang (not to be confused with the Daryl above) or DK as he prefers to be known, had a recent aversion to McDonalds.
  • Krisandro, and his recent pwnage by a 2.21 metre giant.

And that’s that. Back to regular topics. And I’ve got a kicker coming up…

The confounding digital clock puzzle

Recently, I played Professor Layton and the Curious Village on the Nintendo DS. It’s basically a game filled with puzzle after puzzle for the player to solve.

There are 3D questions testing your visualisation skills (the IQ question on the painted cube for my job interview also came up). There are the logic questions such as “Only 1 of the 4 kids is telling the truth”, and you have to figure out the answer from their statements.

I can solve most of the puzzles in my head. The only time when I needed to write something down was where the puzzle can be distilled into a pair of simultaneous equations. You know the kind, the father is x times as old as the son, and after y number of years, he’d be z times as old as the son, and how old are both of them currently. Or some kind of puzzle with some math variables I need to keep track, but don’t want to do that mentally.

Digital clock by claylib
[image by claylib]

Then comes this one puzzle. I was stuck on it for over an hour. I thought, I categorised, I simplified. It’s too mentally taxing to hold all the pieces mentally, and I’m too lazy to write everything out on paper. Here’s the puzzle, paraphrased:

You have a digital clock, displaying the hour and the minute only, with hours in the 12-hour format. How many times during an entire day will 3 or more identical digits appear consecutively in a row? For example, 03:33 is counted as once.

My brother solved it by using Excel to generate all the combinations, and eliminating each combination by inspection. I didn’t want to do that. After some time, I did the only sensible thing. I wrote a program to solve it. Muahahahaha…

// any date will do, as long as the time is set
// to zero for the hour and minute (and second?)
DateTime dt = new DateTime(2008, 10, 1, 0, 0, 0);
string s = dt.ToString("yyyyMMdd");
string sTime;
char[] ca;
int iCount = 0;
// while still the same day
while (s.Equals("20081001"))
    // small hh for 12-hour format
    sTime = dt.ToString("hhmm");
    ca = sTime.ToCharArray();
    // check if first three digits are identical
    // or if the last three digits are identical
    if ((ca[0] == ca[1] && ca[1] == ca[2]) || (ca[1] == ca[2] && ca[2] == ca[3]))
    dt = dt.AddMinutes(1);
    s = dt.ToString("yyyyMMdd");

That took me a couple of minutes to whip up. I added the comments so you can follow the thought process easily. Note the “hhmm” format for 12-hour versus “HHmm” for 24-hour format. 2 seconds to compile and run, and BAM! I got the answer. No, I’m not telling you. Go figure it out yourself.

So I solved the digital clock puzzle with programming. Somehow, it felt like cheating. Anyway, my challenge to you is, can you solve it in a non-programmatic, non-exhaustive-list-writing way?

Stack Overflow is hard

I tried. Not with as much effort as I could muster, but I really tried. I can’t answer a single question at Stack Overflow!

There was this one where I could answer, and someone already gave the answer I’d give (if I did write a reply). So I decided to vote that answer up instead. Not enough reputation to do it.

To earn reputation at the beginning, I’m practically left with two options: ask a question or answer a question. We’ve already established that I’m incapable of answering any of them. I looked at the questions tagged with C# and sql. Maybe I didn’t look hard enough…

Anyway, I didn’t want to ask a question for the sake of getting reputation. If I’m asking one, it better be because it’s bugging me. And I eventually asked one.

It’s something to do with the Month function in Visual Basic. The code I’m maintaining mixes traditional Visual Basic code with VB.NET code in an ASP.NET web application. On the web server, Month("10/01/2008") returns 10 (October). On developers’ machines, it returns 1 (January). Note that a string is passed as a parameter instead of a date.

I created a test web application with a similar setup and deployed it on that server and … I got 1. Aarrgghh! For some reason, I’m unable to replicate that behaviour.

My best guess is that some setting on the server specific to that web application is set, and I don’t know where. The machine.config? The web.config? Some IIS setting?

If I added this to the globalization tag in the web.config file on my machine:
culture="en-US" uiCulture="en-US"
I am able to replicate the return of 10. But the server’s web.config doesn’t have those attributes in its globalization tag.

I can solve the problem by forcibly using DateTime.ParseExact() with “dd/MM/yyyy” format all over the place. I just want to know why the Month() function is inconsistent. If you know, please tell me your answer. I’d appreciate it very much. Send your answer in a comment, or visit the Stack Overflow’s question page for it. Thank you.

The truth about fog

What do you need to know about fog? You know it as the condensation of water vapour in the air at low heights. That’s the scientific explanation. Little do you know there’s a more … evil reason behind it’s existence…

So you can’t see squat in front of you!

That quality of obscuring objects serves a more important purpose in computer games and 3D renderings. Because of finite calculations, outdoor scenes need to be “contained”. The trick is to use clipping planes, a near plane and a far plane, to restrict the amount of visible information.

Due to this restriction, objects that are really far, but you know is there, aren’t rendered. This has the effect of objects appearing suddenly when you move forward in the scene. As you move, objects meet the visible requirement and are thus rendered.

To help assuage this effect, we add fog to the scene. Objects that aren’t visible can now be partially explained by the presence of fog. At least to your brain.

That was to improve the aesthetics of the rendered scene. In some games, particularly of the horror genre, fog’s main purpose is to hide practically everything from sight. If you can’t see a monster, but you can hear heavy breathing and footsteps, the scare factor goes up (hopefully).

This is illustrated with the use of fog in the game Silent Hill 2.

So now you know the truth about fog.

Featured demo – dopplerdefekt

Today’s featured demo is dopplerdefekt (video link) by farbrausch. It’s about 47.8 KB and 3 minutes in length. (download page at Pouet)

The demo’s prominent feature is the 3D effect; you need 3D glasses to watch it. The technique is called stereoscopy.

The entire demo has two copies of every object, one for each eye (or colour). With the help of 3D glasses, you’ll see objects popping out. Which reminds me, I’ve got to go get one of ’em 3D glasses.

Enjoy the demo!