Ousted by the network router

For the past few weeks, my home network router had been acting funny. Or my wireless network adaptor. The main computer plugs directly into the router. My computer connects to the router wirelessly.

The main computer has no problems surfing the Internet. My computer connects to the Internet in a hit-or-miss fashion, seemingly working only when the moon is in alignment with Saturn or a sparrow flaps its wings in exact accompaniment to one of Mozart’s musical compositions. After some troubleshooting, I found I could connect to another unencrypted router in my apartment block (that generous soul should be slightly worried about security). So my adaptor should be working fine. Well, I’m confused. I was never much of a hardware kind of guy…

Since my iPhone can only do so much in mitigating this Internet-less situation, I’ve decided to take a break in writing articles while I go fix this up (no Internet, harder to write articles). Say until… *looks at calendar* 10th May. You’re strong. You can handle not reading anything from me for about 3 weeks.

This isn’t the only reason for the break. Writing articles still doesn’t come easily to me, despite doing it for the better part of the past 2 years. There are also some stuff I have to sort out, which I can’t do if I’m doing stuff on the Internet at my current level of involvement.

Lately, I’m feeling a bit overwhelmed by social media and attending some of the social events and “socialising” in general (yes, I see the irony in the double quotes…). My friends on Twitter, Facebook and Plurk are about 100 on each of those networks. Feel free to add me! Wait, didn’t I just say I was overwhelmed… Does it always take being overwhelmed to really appreciate close, face-to-face, honest, and fun meetings with friends?

I’ve been trying to reclaim some personal time. I remember reading books and playing video games. I’m not doing much of each these days. Through an introduction on Plurk, I got to know someone who’s a Dungeon Master for Dungeons and Dragons! Awesome! Try listening to a D&D podcast to understand how it’s played.

There’s some preparation I need to do, and hopefully I’ll get to play a session or two during this break of mine. Hopefully at least one session. Then I’ll tell you all the captivating details of how I nearly died bringing down the orc king Brull the Numbskull. If it means anything to you, I plan to play an eladrin wizard.

“But what am I going to do during this ill-conceived break of yours?” you ask.

Uhm, uh, let me introduce a few of my friends to you then.

I will still answer email and be on the social networks, albeit slower in response and less frequently. If you have any ideas you want to discuss, feel free to contact me. I might be so interested that I’m compelled to write something on it!

Now to fix my network router…

Exploring dungeons and slaying dragons

Medieval dungeon
[image by David Kerkhoff]

I just went through a period of nostalgia, of the pencil and paper role playing game type. To understand more, read Wil Wheaton’s posts of his experience as a Dungeon Master in Part I, Part II, Part III, Part IV and some concluding thoughts. Thanks to Scott Beale for this.

Done?

Ok, I haven’t played much of Dungeons and Dragons (although I certainly owned a few of the books. Just for reference), or any of the other types of pencil and paper RPGs. But I’m absolutely fascinated by them. My first encounter was when I was 12 years old. I bought these books of the Dragon Warriors series.

For some reason, I only bought the first and third of the series. Oh right, the second one wasn’t available. My 12 year old mind didn’t think it was important. Besides, I didn’t know about the genre then. There was a book sale held at my school, and I was browsing when I chanced upon them.

They were totally awesome! There was mysterious magic, dank dungeons, hateful hobgoblins and tantalising treasure. They were different from the choose-your-own-adventure type of books, because anything can happen! The games master (the term used) can devise any manner of story plot to suit the players. The books’ content are a guide, but the games master is free to use the imagination to make the game fun.

Because I was so excited by this, I had to play it. The problem? No one’s around to play it with me. It doesn’t matter if I’m the games master or a player. I just want to play it.

Somehow I managed to drag my friend and my brother into the game. Creating character sheets was fun. Explaining some rules of combat took some time. And basically there wasn’t much of role playing, or creative use of imagination. But it’s ok. Remember, I was 12 then. Those 2 were even younger than me.

I think one of them was a Knight (or a Barbarian) and the other a Sorcerer. Now only the 2nd book (which I didn’t have) details the mechanics of Sorcerers and Mystics. But I went ahead anyway. I mean, the main attack mechanism was the Attack stat for Knights and Barbarians. There was a Magical Attack stat. Not hard to put one and one together.

The magic casting system was based on magic points. Low level magic spells cost less, higher level spells cost more. The first book provided character sheets for Sorcerers, so I had the number of magic points for a 1st level Sorcerer.

What about spells? Well, I made them up. I played enough RPGs to know the basics. There’s always some kind of fire spell, maybe a healing spell. Well, I was 12. Cut me some slack, will ya?

So my party of 2 was starting out in a basic dungeon, the one in book 1. As rookie adventurers do, one of them inevitably fell into a pit. They’re so rookie, the Sorcerer was in front of the Knight in their battle formation, so the Sorcerer fell into the trap first. No!! Spell casters behind front line attackers! *sigh*

They didn’t even think to use the coil of rope in their equipment to try to climb out. Since their role playing skills and creativity were worth squat then, I gently nudged and suggested that maybe a point of magic would allow the Sorcerer to levitate out.

I know, I know, the levitation spell is non-existent. They would also be stuck there for eternity if I didn’t intervene. Their first encounter with a pack of rats almost did them in. Then this pit. I’m no psychic, but I’m pretty sure they would abandon playing the game very soon if things didn’t pick up.

In another instance, my classmate (I’m still 12) held a game session. With 5 players. Or 7. My memory’s hazy on that. And I got to play! He used the same Dragon Warriors book 1 to play. Because I’ve already read my book to tatters, and I was a games master before, I was allowed to play, but I couldn’t make decisions until after other players did. This was to avoid spoiling the fun for others. I was basically in it to slash rats and batter goblins, which was still loads of fun.

His method of games mastering was different than mine. Maybe it’s because of the larger party, so he followed the book almost to the letter. My point is that, in this fantasy world, he controls everything.

He could add another ghoul if the going seemed too easy. He could “cheat” by making the enemies target the more prepared and healthier players, thereby allowing the weaker players to continue. He could drop hints for puzzles. He could add red herrings. He could do anything.

Then the games stopped. As in no one plays with me on Dragon Warriors anymore (or any other pencil and paper RPGs). A year or two later, I rediscovered a kindred soul… and I’ll tell you more in another article. Stay tuned.

Shinkansen Sway

Shinkansen door

Recently, I went to Japan. One of the highlights was the “bullet train” or Shinkansen. No, it doesn’t travel at the speed of a bullet (much to my dismay), but it’s still fast.

So I was sitting down, enjoying the 2 hour train ride. I can’t read or do much else while travelling (I get headaches), so I closed my eyes to rest… when suddenly the whole train rocked! I flashed my eyes open, and saw another Shinkansen on the right, coming in from the opposite direction. When the two trains “separated”, my train swayed another time.

This happened whenever I travelled by Shinkansen. So I started to keep track. It’s hard, since one never knows when another train will pass by. But I was vigilant. My efforts paid off, and I noticed that my train swayed in a certain direction when the trains meet up. And my train swayed in a certain direction when the trains separated.

Shinkansen sway

So my question to you is, which direction does the Shinkansen sway in, when the trains approach each other, and when the trains separate from each other? Some basic knowledge of physics and a bit of deductive logic should prove useful.

First impression of Japan

Recently I went on a vacation. Destination? Japan. I decided that the day by day recount of my experience (such as when I described my New Zealand trip) is too much (for me and you). So I’m going to just drip feed the stories.

It was a self-prepared itinerary. My brother was the one planning everything. The hotels my brother and I stayed at (there were 2) are based in Tokyo. I also learnt that Tokyo is a very big place. There’s no formal boundary. So let me be more specific. We stayed near the Tokyo train station (2 stations away) for the first part of my vacation. The second part? Let me tell you some other time.

Today, I’m going to just tell you some of my first impressions. In no particular order:

Single digit temperatures

In Singapore, I’m like a heat generator powering a small city. In Japan, I’m nothing. The chilly wind was biting, and the cold seeps into my clothing. My hands were in my wool clothes’ pockets and I’m still bordering on shivers.

The morning temperatures range between 7 to 10 degrees. The highest temperature was 12 and at night, dropped to 3 degrees. Well, it’s a break from Singapore’s steaming weather…

Smoking

Japan seems to simultaneously promote smoking and ban it at the same time. There are vending machines selling “tabaco” (tobacco) or cigarettes. And on the sidewalks, there are signs painted onto the floor that translates roughly to “no smoking while walking on pavement”.

Some restaurants also permit smoking within its premises, even if it’s air conditioned. There was once where we went into an Italian restaurant (Italian food is seemingly quite popular), and there were people smoking. I had decided to experience the Japanese culture, so despite my distaste for the tainted air, I told my brother (who shares my distaste) that we’ll just quickly finish our food and be on our way. I’d never be able to see Japanese in their normal environment otherwise.

Litter bins

Despite the extremely small number of litter bins, Japan streets are relatively clean. This is in contrast with Singapore, where litter bins are placed quite generously about.

My brother told me that their litter bins are outside of convenience stores (there aren’t a lot of them), and are usually recycle bins. Oh yes, Japanese are big on recycling. I didn’t dare buy any foods or drinks to consume on the streets for fear of the inability to dispose of the wrappers and papers.

Few plant life

Except for parks, the major parts of residential and business areas are sparsely covered with vegetation. Again, in contrast with Singapore, where streets are lined with trees.

My first hotel was in Ochanomizu, which is roughly “tea and/or/of water”. When I first came out of the subway, the first blast of cold air scraped over my bare arms (I was wearing just a normal shirt). There’s a faint whiff of factory-produced smoke. And there’s a slight wash of grey over the entire place. No greens at all. But it’s still winter going into spring.

Face masks

I haven’t seen face masks since the SARS period. There’s a higher than usual occurrence of people wearing face masks. So after some discussion with my brother, and some thinking on my own, I came up with 4 reasons:

  • Person is sick, and this avoids transmitting disease to others
  • Person is protecting himself/herself from getting diseases transmitted
  • Keep the mouth area free from the biting wind
  • It’s a fashion statement

My brother found it so intriguing that he bought a set of face masks himself. Then promptly remembered on our last day that he didn’t wear one at all as a fashion statement…

Is math important to programming?

It depends.

Now that we’ve gotten the short answer out of the way, let’s discuss this further. Recently, Jeff Atwood asked Should Competent Programmers be “Mathematically Inclined”? I don’t get the need for the quotes, but never mind…

The summary of his article is that the problems involving math that most programmers deal with are the “balancing your checkbook” kind. Meaning simple math is required, meaning you don’t need to be a math whiz to solve that problem with programming. And I agree with him.

My work currently puts me in contact with a lot of numbers. As in quantities in the 10 digits range, with values also in the 10 digits range. And the finance and credit departments of my employer are very interested in those numbers…

Anyway, the manipulation of those numbers require very little math, despite their math origins. How hard can it be to sum up figures, do discrete prorating, calculate percentages or find out the price based on existing rates?

The initial reading of Jeff’s article made me feel indignant (goes off to check that I indeed write about math and programming). How dare he view math as frivolous to programming! How dare he reduce math to insignificance! (wipes spittle from mouth)

Then the cold hard truth of my professional programming experience knocked my senses back into place. I had to remember that the work I did back in university just wasn’t… useful (directly) to my present work. I worked with 3D, image rotations and optimising an airflow simulation. Not quite the business related programming I do now.

I still believe math is useful to programmers. Just as you should learn C, even if you don’t use C in your regular work. I’ll tell you how math and C are related in a bit, but first…

Math is elegant

I agree with Steve Yegge. They teach math all wrong in schools. This is despite his American background and my Singaporean background. I guess errant math education has no borders

The earlier parts of math education focus on calculations and memorisations. Oh, there are some proving questions (much to my distaste) alright, but there’s not a lot of them. In university, my math education started to take on a distinct shift; there were fewer numbers in the questions.

I remember there was this linear algebra tutorial. There were only 4 questions in it. I took a grand total of 4 hours to complete it. Even then, I didn’t fully answer the questions. It was proving this, or ransacking notes to find out which theorems were applicable, or wandering into higher dimensional linear spaces (I think I hated the professor at one point during my struggle). I think I even skipped 1 (or 2!) question. That’s how different the questions became.

With this shift, I found math to become more … elegant. Suddenly, plugging in numbers into calculation formulas aren’t important anymore. Even remembering proofs and theorems take backstage. Figuring out which method, proof or theorem to use to solve a question in the simplest manner is paramount.

I started to solve problems elegantly, be they math or programming.

And for me to find elegant solutions, I needed to think more. Much more. Sometimes this fails, and I end up with a less-than-ideal-elegance solution. But that’s ok. If I don’t aim for elegance, I’ll never reach it.

In my earlier stages of education, math was binary. Either my solution was right, or it was wrong. Later on, it was right. And there’s another solution that’s also right, and shorter. Or easier to understand. Math solutions became a little fuzzy.

What I’m saying is that although math isn’t directly useful to my programming, it certainly shaped the way I solve programming problems. Because programming solutions are also a little fuzzy.

Many programming solutions are sub-optimal. And they don’t need to be optimal. They already solve all normal occurring cases, and maybe the edge cases don’t matter that much. Or maybe there isn’t an optimal solution. In which case trying to find the optimal solution is a waste of time. So much for elegance.

So is math really important? I can’t say for you (despite writing an article on it), but C isn’t that important for programmers either.

Learning C makes you think

It’s sometimes hilarious to see Jeff and Joel argue about the importance of learning C. Joel does have a point. Learning C makes you think harder about solving programming problems (pointers and all). It doesn’t mean you’ll ever use any of the solutions (or C for that matter), but it trains your mind to think.

And in this respect, that’s what C and math are to a programmer. Learning both makes you think. You’ll think about just solving the problem. You’ll think about a more elegant solution. Maybe coming up with a less convoluted solution but eminently understandable by your fellow programmers.

But if you never go through the extremes of “slap messy but amazingly it works” and “elegant one liner but takes forever to understand”, then you might find it hard to find a happy in-between state. Because you just don’t know what’s possible.

“So is math important to programming?” an obvious exasperation in your question.

Well … it depends. On you.

In-flight entertainment user interface … difficulty

I just returned to Singapore from Japan. It’s because of this that I found a fellow traveller’s experience of his in-flight entertainment system hilarious, both as a traveller and as a programmer. I wanted a stronger word than “difficulty” in the title (such as “hell”) but thought I’d tone it down to distract the dragonflies.

If you ever want to punish a user interface designer, make sure they get to use an airline’s long-haul inflight entertainment system. It must be like hell on earth for them.

My experience was a bit less distraught than James’. I flew on Singapore Airlines, the Airbus to Japan, normal plane back to Singapore. The entertainment system on the Airbus was good, and the one on the normal plane was ok. And I’m not just saying that because I’m Singaporean.

The only complaint I have is the seat was uncomfortable for me. The seats are not designed for tall people… My neck was sore for most of the flight. I’ll tell you more of my trip later.

The composite space between prime products

Previously, I gave you a puzzle on prime numbers.

Let F(n) be (1st prime) * (2nd prime) * … * (nth prime)
The question was to describe the group of numbers between 2 and F(n)-1 that F(n) cannot divide.

And the answer is… all composite numbers between 2 and F(n)-1 with repeated prime factors. Hmm… I guess that doesn’t quite fit the “as plain an English as possible”, but it is concise.

For example, F(n) cannot divide 4, because 4 = 2*2 (repeated 2).
But F(n) divides 6, because 6 = 2*3 (no repeated primes).
F(n) cannot divide 18, because 18 = 2*3*3 (repeated 3).

The proof (sort of)

If a number A in [ 2, F(n)-1 ), is prime, then F(n) divides A by definition because F(n) is a product of primes.

Let A be a composite number in [ 2, F(n)-1 ) with no repeated prime factors. Then F(n) divides A because F(n) is a product of primes where the prime factors form a superset of the prime factors of A.

Can you complete the proof?

Let A be a composite number in [ 2, F(n)-1 ) with repeated prime factors. Let p be a repeated prime.

[Can you complete the proof?]