A Polymath Programmer survey, because I can’t read minds

The stars have informed me that (closes eyes and places fingers of right hand on forehead), unbeknownst to my inattentive mind, Polymath Programmer had gained quite a few new readers over the past few months. … Alright, fine, the stars had nothing to do with it. I was looking through some of my web stats and analytics information.

So if you’re a new reader, welcome! As a short introduction, you will find articles on math, programming and other (hopefully intellectual) points of interests here. A few articles you might be interested in:

If you’re a long time reader, I’m *sniff* very thankful for your support. *single tear* You’ve been an invisible strength to me during those lonely hours of coding, research and writing.

Now for the main crux. I’m conducting a survey. Even though I can solve programming errors by simply being near them, I can’t read minds. I’m still working on that…

All I ask is your name and email address, and to answer 3 questions. That’s it. All 5 parts are optional, so you don’t have to fill it if you don’t want to (it’ll be nice if you do though).

[UPDATE: Your name and email address is used only for the survey. They are kept confidential, and are not shared with nor sold to anyone. I just want to thank you personally for helping with the survey, that's all. The survey is intended to let me know more about you, so I can write articles better suited to your interests. Polymathy may encompass many subjects, but it's easier to start somewhere.]

And here’s the survey link:

[SURVEY CLOSED]

I’m using the service from Survey Monkey. I also notice that their web pages are .aspx. Yay ASP.NET! Ok, that was random…

Parsing date formats with dd/MM/yyyy or MM/dd/yyyy?

I was angry and frustrated. The developer tested his code, and it failed. When he sent it to me for help, I tested it, and it worked. Isn’t it supposed to be the other way around? Someone writes the code and it works for them, but when it’s reviewed by you, it fails?

That developer couldn’t get the date selection right. I wrote a web control library which includes a date selection widget. When I designed it, to simplify things, I hardcoded the date parsing to be dd/MM/yyyy format (I’ll explain my choice later on).

What happened was, the developer either got the yellow screen of death (if you’re working in ASP.NET, you know what I’m talking about), or the day and month were swapped.

Finally, I asked him if his computer settings had MM/dd/yyyy as the default short date format. And if it was, to change it to dd/MM/yyyy. It was, and he changed it, and the code worked.

The default date setting on computers running on Windows is MM/dd/yyyy format. I change it to dd/MM/yyyy format because Singapore uses that format. And my users’ main business involves a big company residing in United Kingdom, which also uses the dd/MM/yyyy format.

Here’s how you change the settings. Go to Control Panel, and click on “Regional and Language Options” or something named similarly. You’ll get something like:

Regional and Language Options

Click on the “Customize” button to get:

Customize Regional Options

In the “Short date format” dropdownlist, enter “dd/MM/yyyy”. You may not find it under the dropdownlist options. This is what some people don’t know: You can type “dd/MM/yyyy” in the dropdownlist. Click “Apply” button, then “OK” button, and you’re set.

Here’s some code to test your changes:

System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("en-GB", true);
DateTime dt1 = DateTime.ParseExact("05/08/2009", "dd/MM/yyyy", null);
DateTime dt2 = DateTime.Parse("05/08/2009");
DateTime dt3 = DateTime.ParseExact("05/08/2009", "dd/MM/yyyy", c);
DateTime dt4 = DateTime.Parse("05/08/2009", c);
Console.WriteLine(dt1.ToString("D").PadLeft(30) + " | " + dt1.ToString(c));
Console.WriteLine(dt2.ToString("D").PadLeft(30) + " | " + dt2.ToString("dd/MM/yyyy"));
Console.WriteLine(dt3.ToString("D").PadLeft(30) + " | " + dt3.ToString("MM/dd/yyyy"));
Console.WriteLine(dt4.ToString("D").PadLeft(30) + " | " + dt4.ToString());

Did you get the values you expected?

Here’s the comparison output from the American MM/dd/yyyy and British dd/MM/yyyy format:
Regional settings test output

Note that the code remained the same. Only the regional settings were changed.

So what I found out was that, as long as you explicitly state the date format (or use a culture setting with your desired date format), it works whether you’re parsing in the date string, or printing out the date.

Despite changing the settings, I still had a date format issue which I asked on StackOverflow. It was some time ago, but I didn’t get a satisfactory answer. Then again, it was my colleague’s problem and he’s fine with the weird behaviour… The problem could be because he didn’t explicitly set the output format, which displayed the wrong date on the screen, even though the regional settings are correct on the web server.

Are corporate programmers also polymath programmers?

I’ve been writing for more than 2 years now, and I realised that I never told you much about my professional job. Let’s start with a brief summary of how I started…

Beginning of professional career

I started working a few months after I graduated in 2002. I had a science degree in applied mathematics and computational science, but that didn’t stop me from applying for the software engineer, software developer, application programmer, systems analyst and other confusing variants of the job title. I like programming.

Once, I worked in a startup company, writing software to deal with patents. One of the requirements was “must know regular expressions”, used for searching through the patent text, so I put my mind to learning it. I got the job. The funny thing was, the CEO handed that part of the coding to an intern. Oh wait, a PhD intern. Maybe I wasn’t qualified to touch regex…

Somewhere in that career history of mine was a software development house. The team I was in, was assigned to develop an enterprise product for a Japanese company. It’s an internal website, and handled work flow processes, task assignment and other enterprisey functions.

Half the time, I was helping to complete some sections of a business class. A third of the time, I was doing the testing, because I seem to be the only (expendable) one with more than coding skills. Because I had experience talking with users, coming up with specifications, database design, setting test environments and oh yeah, coding.

They even offered me a role in translation, after they heard I knew Japanese. Correction I told them, I knew a little teensy bit of Japanese. They had an overflow of programmers I guess… (it was a team of 10 programmers. Or was it 12?).

In the present

Currently I’m working in a telecommunications company in Singapore. Actually, I started my first job in the same company too. After the first few years, I joined the startup. Then left and joined the software house. Then left, and rejoined my current company, but in a different team (still in the billing support department though).

The interesting thing is that I’m dealing mostly with satellite data, not mobile phone data (one of the core business of telecommunications companies). And my users are like a complete company, albeit on a small scale.

They have their own departments on customer service, marketing, sales, and to a certain extent, their own IT team. And that IT team is composed of 3 people. And I’m one of them. I have a supervisor and a colleague who handles the backend programs (mostly C and C++ on Unix).

Me? I’m the frontend guy, and the everything-else guy.

Because of the unique service (compared with the rest of the company) dealing with satellite data, my team is involved with everything from the call records of the customers, to the configuration of their price plans, to billing the customers, to settling profit with the satellite providers. The satellite business is quite interesting, and I’ll tell you more in a future article.

The other team mates focus on collection of the raw file containing the call records, processing them, calculations of the bills and other backend stuff. I handle all the stuff that users will see and interact with, like Windows applications and web applications. And I manage the Windows servers the web applications are running on. And there’s the updating of the SSL certificates for the web applications. Once I was at the data centre during a power maintenance, because someone needed to be there to flip the on-off switch of the servers and check on the equipment.

My work is seen by a lot of people, which includes the customers, the sales staff, the marketing staff, the product managers, the administrative staff and the customer service officers. This means I get a lot of queries.

If a number doesn’t tally with the total, someone sends me an email.
If the font size is too small, someone sends me an email.
If the Excel download fails, someone calls me.
If the data cannot be found, someone calls me.
If they can’t open an FDF file, they call me.
If the offshore Chinese colleague have questions on business logic or web design or code design, he/she calls/emails me.

If [something happens], someone [calls/emails] me.

In short, I get interrupted a lot. Nice private offices? Not a chance.

And I still have to write code so the projects actually ship before deadlines.

There was once where I had 1 month to come up with a new website for the customers to view their call records (brand new .NET web application, new user interface, completely new database schema). That was a December (the sales people had to move fast to get that contract before the start of the next year, which meant I had to work fast). And another colleague from another team was reassigned, and his work was handed to me (basically I was covering for 2 teams). And I received calls and queries from the users of both teams.

And the new website was out in the world on time. *whew*

Do programmers who work in a corporate environment go through similar experiences? Do they handle many non-programming related work? Are corporate programmers also polymath programmers?

I’m stumped, since I probably have this naive notion of programmers just programming (to a large extent). My friend once asked me what I do at work. I didn’t know how to answer, so I rattled off a few tasks mentioned above, and he’s surprised I do so many different tasks. Particularly when I sometimes have email correspondence directly with customers, which I try to avoid for business reasons. The sales and customer service teams are supposed to be the frontline, not me.

Helping corporate programmers on time management

This brings me to a personal project. I’m creating a product about time management for corporate programmers, working title “Time management for corporate programmers – Handling interruptions, removing distractions and getting the Flow”. Or some such.

All the writings and articles on this site will continue to be free. I’m writing an ebook to help fellow corporate programmers (maybe even programmers in general) with what I know. And this endeavor might just be able to support this site. The articles are fun to write, and I love the brilliant comments by you (even the ones that tell me I’m wrong. Those are awesome).

Actually “time management” is too specific. I’ll be writing on discipline, control and health. There will be some quick tips on data migrations and doing your miscellaneous tasks with free tools (because you know, companies are always cutting the budget). My notes actually look like a jumbled mess, but maybe that’s the nature of polymaths… or just me.

So do you have any questions about time management in a corporate setting? Or even time management in general? What are the typical tasks you do? How can I help you do your job, the tasks you really want to do (it’s coding and shipping software, right?), better?

*whispers* Psst, it’s ok if you’re a student/coder. I was a student/coder once. Just ask.

Let me know in a comment, or if you’re shy, use my contact form to email me privately. You can also talk with me on Twitter (@orcasquall).

I’m really excited about this project.

The monkey and negative number of coconuts

Coconut trees

There’s this math puzzle that I recently heard from my friend. Here it goes:

The puzzle

In the not so distant past, there was this small island. And there’s this monkey… what? Yes, it’s alone. Ok, fine, he’s alone. Yes, poor thing.

So, on this island, there were many many many coconut trees. And each of them bore enough fruits to collectively and breath-of-a-hair-barely escaping the sinking of the entire island. These palms were fertile, I tell ya.

And there were them these pirates, ya know. Arrr! And they were five in all. Ok, you can stop arrr-ing now. Huh? What were these pirates doing on the island? Uh, they got stranded? How do I know? (*whispering to myself* the filthy swashbuckling buccaneers…)

Anyway, they saw them these coconuts just hanging there, and they thought they were in coconut heaven. They proceeded to gather all the coconuts they could get their hands on. Hmm? They might have some food on them. Uh, maybe they had cravings for coconut?

The monkey saw what they were doing, and went to help them. Finally, at sundown, they… what? It took maybe a day… Yes, that means the pirates arrr-ived in the morning. Alright, let me continue the story, will ya?

So at sundown, they were exhausted, and decided to divide the coconuts the next morning. And they went to bed. Or sand. Or whatever they used as makeshift beds.

During the night, one of the pirates woke up, fearing the others would betray him. And so he started dividing the pile of coconuts into 5. While he’s busy counting and dividing, the monkey came to the pile, took a coconut, opened it up and started eating. The fearful pirate, afraid of startling the monkey and making more noise, just let the monkey be. It turned out well, for he divided the pile evenly into 5. And then hid his share of the coconuts. And he went to sleep.

And another pirate, fearing the same thing, woke up just after the first pirate went to sleep. And he divided the rest of the coconuts into 5. And the monkey also took a coconut and ate it, bemused at the stealth tactics employed by the counting pirate. This second pirate was satisfied that he counted correctly and that he divided the pile evenly into 5, so he let the monkey go. Besides, he was busy hiding the coconuts and trying to be quiet.

A third pirate did the same thing, dividing the remaining pile of coconuts into 5. And the monkey did the same thing, eating a coconut while the pirate was having trouble because he didn’t have enough fingers on his left hand to help him.

And a fourth pirate did the same thing. And the fifth too.

At each quiet division of coconuts, the pile was divided evenly. And the monkey ate a coconut at each division. So, how many… Yes, the monkey ate a total of 5 coconuts. You’re so clever. So, how many coconuts were there in the original pile?

The solution (sort of…)

I am going to work backwards.

Let y be the number of coconuts left over.
Let x be the original number of coconuts.
Note that x and y must be integers.

At 5th pirate division:
He hid his pile, so we add his pile back.
What’s left would be 4 parts for the rest, so we get 5y/4 to get all the pirates’ share.
Oh yeah, we need to get the monkey to regurgitate his coconut.
Ok, maybe not…

So before the 5th pirate divided, we had
5y/4 + 1
= (5y + 4)/4

At 4th pirate division:
It’s 4 parts for the other pirates, so we do the 5/4 multiple again to get
5( (5y + 4)/4 )/4
And we add 1 from the monkey to get
5( (5y + 4)/4 )/4 + 1
= (25y + 20)/16 + 1
= (25y + 36)/16

Note the recursive nature.

At 3rd pirate division:
5( (25y + 36)/16 )/4 + 1
= (125y + 180)/64 + 1
= (125y + 244)/64

At 2nd pirate division:
5( (125y + 244)/64 )/4 + 1
= (625y + 1220)/256 + 1
= (625y + 1476)/256

At 1st pirate division:
5( (625y + 1476)/256 )/4 + 1
= (3125y + 7380)/1024 + 1
= (3125y + 8404)/1024

And so we have
(3125y + 8404)/1024 = x
=> 1024x = 3125y + 8404

Now, my first thoughts had something to do with the Chinese Remainder Theorem or the GCD or something. And I searched for the solution, because I have no idea how to start. And I came upon Diophantine equations.

And I have absolutely no idea how to solve the equation.

Now my friend did tell me that 3121 was a solution for the number of original coconuts, which would mean 1020 coconuts were left over. And something about modular arithmetic.

What is more interesting, is that he told me -4 is also a solution. I plugged it into the equation, and lo and behold! There were -4 coconuts left over.

Wait, what? So there were -4 coconuts originally, and after all the sneaking and counting of the pirates, and the monkey eating it’s, ok, his, (presumably) non-existent -1 coconut, we have -4 coconuts left over?

The only reason why that solution was confounding us, ok, me, no wait, you, arrr, whatever, is that an assumption was flawed. We can’t have negative numbers of coconuts. Not in this reality dimension anyway. Arrr.

But it’s interesting. -4 is a stable solution, in chaos theory parlance. I mean parrrlance. Arrr.

Final thoughts: Why would each pirate fear that the others would betray him, but was honest enough to divide the coconuts evenly? And how would the first pirate divide 3121 coconuts into 5 while keeping quiet (that’s a lot of coconuts)? And keeping his head straight? And keeping the monkey quiet?

This is why, sometimes, just because you can solve a math problem, doesn’t mean you should. Because it might not make sense in the first place.

P.S. This was inspired by my friend who told me about the puzzle, and the International Talk Like A Pirate Day. Arrr.

[image by akurtz]

Dramatising the Three Beacons of Twilight

In my ongoing quest to expand my repertoire of skills as a polymath, I have embarked on acting. Specifically, role playing. It takes a bucketload of courage to speak, for I am used to conveying words through my fingers to the screen, not from my mouth to my audience’s ears.

It’s even harder role playing a fictional character.

So I’ve resolved to include some roleplaying, some acting, some short speeches, that kind of stuff into my regular D&D gaming sessions. I want to see D&D as more than just dice rolls and statistics. The experience will also help, you know, in case I get invited on television or do videos *cough cough*.

There is this power that’s really awesome. It’s called “Three Beacons of Twilight”, a level 15 Invoker power. The flavour text reads, “In the darkest days of the war against the primordials, the gods used…” oh who cares about the flavour text? It does a fair amount of damage, and creates a zone that allows me to teleport people willy-nilly.

Fighting the elder blue dragon
My invoker’s the nearest to the top. The little hand-thingy represents the origin square of my Three Beacons of Twilight. Just in case you’re wondering, that’s the bad-ass elder blue dragon we’re fighting. We’ve got props too. The silver ring means it’s cursed by the warlock. The gold ring means it’s marked by the paladin. And the red ring? Means it’s half way dead (thank goodness!).

I sort of imagined the three beacons as stars in the sky. So during this last encounter for the day, I decided it was an appropriate move, and I launched fully into my dramatic pose and dramatic voice.

I call upon the Three Beacons of Twilight, named Waffles, Tea, and Fudgecake. I invoke their power word pronounced “WUHTUHF”, which is an acronym formed from their initials. Or WTF for short. WTF!!

My DM nearly fell off his chair laughing. I got a few smiles from my comrades-at-arms too. Success!

Then I rolled my d20 to determine if I hit.

And I rolled a 1.

My DM laughed even harder.

After the dramatic performance I put up, I failed to hit abysmally. Like I said before, I can’t roll to save my own life