Square any number in less than a second

26-09-2015 | Posted in Problem solving

This week’s interview of Arthur Benjamin in the Huffington Post gives an excellent illustration of quick problem solving.

In this video, he explains the trick to quickly square a number.

This problem-solving strategy is called Analogy.

How does Analogy work?

When faced with a problem, try to find a similar problem that is simpler. Solve that. Now you’re left with the question of how to go from there to a solution for the original problem.

The example in the video is to square 498. A quick way to do that it to apply Analogy twice:

  1. Find a similar problem that is simpler: 500 × 496 (two up; two down).
  2. That’s still not obvious, but a simpler problem exists: 1000 × 496 = 496,000
  3. From that solution, you quickly find 500 × 496 = 248,000 (by dividing by two)
  4. We’re left with the question: how to move from that to 4982? Benjamin has that memorized: by adding the square of two: 4982 = 248,004
    In case you were wondering, the reason for that is that x2 = (x – n) × (x + n) + n2

So use the Analogy problem-solving strategy to make your problems simpler. It requires some creativity, but it can lead to extremely fast results!

Proud to be lazy

18-01-2015 | Posted in Professional

I’ll admit it: I’m lazy. I don’t like doing boring things I can avoid. And you know what? I’m proud of my laziness. And you should be, too.

Let’s take an example. Read the rest of this entry »

Free Xamarin training when you have a MSDN account

21-11-2013 | Posted in C#, Professional

I was quite amazed when I heard that Xamarin offers free online training and certification – that is: when you have an MSDN account.

With Xamarin, you can develop native applications for iOS, Android, Mac and Windows, without having to learn the different programming languages that these native apps are usually developed in: it’s all C#.

Several of my colleagues have used Xamarin, and it appears to be a great option for delivering native apps without having to deal with all the quirks of the different platforms.

So make sure to check out xamarin.com/university!

Programming in HTML5 with JavaScript and CSS3 – Training Guide

27-09-2013 | Posted in CSS3, HTML5, JavaScript, Professional

Over the last weeks I’ve been reading Programming in HTML5 with JavaScript and CSS3 – Training Guide by Glenn Johnson. On the back, it states that it “Creates a foundation of skills which, along with ont-the-job experience, can be measured by Microsoft Certification exams such as 70-480.”

For Exam 70-480, Microsoft gives a very specific list of skills measured. To help you study for that exam, I have created an overview of the chapters of the Training Guide, and which skills they cover. Read the rest of this entry »

Auto-increment with a yearly reset

25-09-2013 | Posted in Professional, Software Archtecture, SQL

Working with end-users on a day-to-day basis is very satisfying. You get to know the people that will benefit from your application. But every now and then they come up with requirements that I don’t immediately know how to implement. A challenge! Let me share such a challenge with you. Read the rest of this entry »

Count the number of commas in a string in C#

17-12-2010 | Posted in C#, LINQ, Professional

How do you count the number of commas in a string in C#?

When you search the internet for this, you’ll quickly find the two obvious answers:

1. Iterate through the characters of the string, and add 1 when you find a comma:

int total = 0;
for (int i = 0; i < s.Length; i++)
   if (s&#91;i&#93; == ',')
      total++;
&#91;/csharp&#93;

2. Use a regular expression:

&#91;csharp&#93;
int total = Regex.Matches(s, ",").Length;
&#91;/csharp&#93;

3. My solution, however, would be to treat the string as an array of characters. Arrays are IEnumerable, so we can use LINQ:

&#91;csharp&#93;
int total = s.ToCharArray().Count(c => c == ',');

Why do I prefer this solution? Read the rest of this entry »

Tesla was a thinker, just like us

01-12-2010 | Posted in Professional, Professional Development

If work is interpreted to be a definite performance in a specified time according to a rigid rule, then I may be the worst of idlers.

– Nikola Tesla in The Strange Life of Nikola Tesla

Nikola Tesla

Nikola Tesla

Today I stumbled on an autobiography of Nikola Tesla, the inventor of AC power and, on a cooler note, the Tesla Coil. He was far ahead of his time, even suggesting world-wide wireless communications in the early 1900’s.

But in reading this quote I found he was far ahead in thinking about work as well. In his time, work was mostly manual labour. The rich did not have to work, so they could afford to be the thinkers. If you wanted to be productive, thinking wasn’t enough. You had work.
Read the rest of this entry »

How to create easy-to-remember, secure passwords

23-11-2010 | Posted in Professional, Security

Follow these two steps to create passwords that are secure, but easy to remember.

As more and more of our lives happens online, the thought of someone accessing our online accounts becomes more and more frightening. If someone gets a hold of your password, they can do a lot of damage.

There are three major ways for someone with ill intent to get hold of your password

  1. Guess it
  2. Ask you for it
  3. Watch you type it in
  4. Snoop it by monitoring the network

The second one, Ask you for it, may surprise you. But how many sites have you visited that ask you to type in a password? And for how many of those do you use the same password?

It’s quite easy for someone with bad intentions to set up a site asking you for an email address and a password, and using the password to access your accounts.

And even when you trust the site, it still may not be safe. Over the years I’ve administered lots of websites, and I’m astonished to see how many databases contain the user’s passwords. Anyone who gets access to such a database can use all of the passwords in it.

Issues 3 and 4 will be addressed in a separate post.

1 and 2, however, can be easily prevented by having a good password. I will show you how to create a password that is difficult to guess, difficult to reuse, but still easy to remember.

Read the rest of this entry »

Using LinqDataSource WhereParameters with composite keys

15-11-2010 | Posted in C#, LINQ, LINQ to SQL, Professional

I am working on a master/detail page with LINQ to SQL, displaying people’s information. With the person’s name as a key, this is a straightforward thing to do. But it took me a while to figure out how to combine ‘Name’ and ‘Year of birth’ to form the key together. According to my Manifesto, I post my solution here. Take advantage of it.
Read the rest of this entry »

LINQ to SQL Quickstart

11-11-2010 | Posted in C#, LINQ, LINQ to SQL, Professional, Visual Studio

Let’s look at some of the advantages of LINQ to SQL. We will generate a database and objects, all from a simple model.
Read the rest of this entry »