Learntofish's Blog

A blog about math, physics and computer science

Archive for November, 2012

More programming puzzle websites

Posted by Ed on November 22, 2012

Jagadeesh from SkilledMonster posted a nice collection of programming puzzle websites.

I mentioned another collection earlier here.


Posted in computer science | Tagged: , , , | Leave a Comment »

How to get started with Topcoder

Posted by Ed on November 22, 2012

If you want to improve your programming skills, I highly recommend Topcoder. Unlike projecteuler which is heavy on number theory Topcoder focuses on algorithm design. In the live competitions you are given three problems that you can try to solve within a time limit. There are two divisions. Division 2 is for beginners whereas Division 1 is for those with a higher ranking.

Here are some nice tutorials on how to get started:
Getting Started on Topcoder
TopCoder Quickstart Tutorial

You do not have to participate in the competitions. You can also just use the archive to practice:
– Go to the problem archive.
– Click on Div2 Success Rate. This will sort the problems from easy to hard. You can then start working on the problems where the difficulty gradually increases.
– After compiling, testing and submitting your solution don’t forget to run the system test. For this, click on Practice Options -> Run System Test.
– Browse through other people’s solution and learn new tricks. This is a nice feature on Topcoder.

After some practice you should compete in one of the live competitions. First, it is very exciting and fun. Second, you learn to write correct code fast. Third, you read other people’s code during the challenge phase.

By the way, Mark Zuckerberg also has a profile on topcoder.

Posted in computer science | Tagged: , , , | 1 Comment »

How to draw regular polygons

Posted by Ed on November 20, 2012

In this blog post we will derive a formula for the interior angle \alpha of an n-sided regular polygon. We will examine how \alpha depends on n. This allows us to draw the regular polygon.

Regular polygons
A regular polygon is a figure whose sides have the same length (equilateral) and whose interior angles are equal (equiangular). Let’s draw one with 3 sides. We can easily construct it if we know the interior angle \alpha. For the triangle it is \alpha = 60°.

Let’s do the same for a square, for which the interior angle is \alpha = 90°.

Now, can we do the same for a pentagon (5 sides)? What about a 13 sided regular polygon?

Obviously, we could if we knew how to choose \alpha. Before you continue reading you may want to ponder how to determine the internal angle. So, spoilers ahead.

Derivation of interior angle

We have two equations.
\alpha + \beta = 180^\circ (1)
n \cdot \beta = 360^\circ (2)

We solve (2) for \beta: \beta = \frac{360^\circ}{n} (3)

Plug (3) into (1): \alpha + \frac{360^\circ}{n} = 180^\circ (4)

Multiply (4) by n: n \alpha + 360^\circ = n \cdot 180^\circ (5)

Substract 2*180° on both sides: n \alpha = n \cdot 180^\circ - 2 \cdot 180^\circ = (n-2) \cdot 180^\circ (6)

Divide by n: \alpha = \frac{(n-2)}{n} \cdot 180^\circ (7)

This is the interior angle for an n-sided regular polygon.


1) Show that the formula is correct for the triangle and the square.

2) What is the interior angle for the pentagon?

3) What is the sum of all interior angles in a 7-sided regular polygon?

4) What is the sum of all interior angles in an n-sided regular polygon?

5) What happens with the interior angle if you make n bigger and bigger?


1) Before we derived the formula we already knew that the interior angles are 60° and 90° respectively for the triangle and square. Let’s check if the formula gives us these values.

For the triangle we set n=3 and get \alpha=60^\circ.
For the square we set n=4 and get \alpha=90^\circ.

2) For the pentagon we set n=4 and get \alpha=108^\circ.

3) and 4) The sum of all interior angles in an n-sided regular polygon is n\alpha = (n-2)\cdot 180^\circ. For a 7-sided regular polygon we set n=7 and get 7\alpha = (7-2)\cdot 180^\circ = 5 \cdot 180^\circ = 900^\circ.

5) If we make n bigger and bigger, the value for \alpha approaches 180°. We can express this with the limit:

\lim_{n\rightarrow \infty} \alpha
= \lim_{n\rightarrow \infty} \frac{(n-2)}{n} \cdot 180^\circ
= \lim_{n\rightarrow \infty} \left(1-\frac{2}{n}\right) \cdot 180^\circ
= 180^\circ

Posted in mathematics | Tagged: , , , | Leave a Comment »

Wallstreet Journal articles

Posted by Ed on November 9, 2012

Recently, I’ve been reading the Wallstreet Journal. I particularly enjoy reading the section on life, health and work at the end. Here are two articles that I like:

Some Don’t Live to Earn, but Earn to Live By RHEA WESSEL
Self-Help for Skeptics By ELIZABETH BERNSTEIN

Posted in Education | Tagged: | Leave a Comment »

Test your Java and Python skills

Posted by Ed on November 8, 2012

CodingBat offers some nice problems to test your programming skills in Java and Python. They are particularly suited for beginners. Some harder problems deal with recursion.

Posted in computer science | Tagged: , , , | Leave a Comment »