Lifelong Learning

Via HN. Interesting article on rules to follow for lifelong learning by Richard Hamming, widely known for Hamming code, an error-correcting code used in telecommunication industry.

For a software developer, lifelong learning is crucial if you want to sustain your passion and extend your career. Similarly to fashion modelling or idols, ageism in software development is real and unavoidable. For non-technical people point of view, is always cheaper and easy to manage (ahem manipulate) young blood. This is true where the organization have limited budget and the developed system is just non-critical plain CRUD app.

The first rule resonates with me. Knowing the fundamental is understanding how things works as compare to get things to work. For example, using any programming languages to build a website is getting things to work. Knowing how the HTTP protocol works with all its intricate parts is understanding how things works. Many years ago, in FOSS world, Perl was the default choice to build any website. Later it was dethroned by PHP, and in a short while, Ruby due to Rails, and now Javascript which is ridding on Node.js popularity. Regardless the current trending programming language used for building a website, the fundamental part still remains the same. Hence, to stay relevant, focus on the fundamental.

Judging by my current career detour right now, this is the best time to pick up the fundamental again.

Solving Project Euler's 1st Question Using Nim Programming Language

Nim is the trending programming language in the HN which bears similarity to Python. I was intrigued with it and decided to learn it by solving the first question of Project Euler. This programming language felt like a mixture of both Python and Ruby but that too early to tell as I haven't explore the other distinct features of the language.

To reduce the verbosity, which was set to default 1, during compilation, I've created a Bash alias compile(c) a Nim source and run(-r) it but set the default verbosity level to 0. You will see nimc alias being used in the subsequent examples.
alias nimc='nim c -r --verbosity:0'

First, let's loop from 1 till 999 and print all the number. Type the below code
and save it as p1.nim.
for i in 1..999:
  echo i

Compile and run it. You should see an output as shown.
$ nimc p1.nim
1
2
......
998
999

Next, we filter and print only number which are either a multiples of 3 or 5.
for i in 1..999:
  if i mod 3 == 0 or i mod 5 == 0:
    echo i

Compile and run it again.
$ nimc p1.nim
3
5
......
996
999

Lastly, to find the sum of all numbers which are the multiple of 3 or 5 below 1000.
var 
  sum: int;

for i in 1..999:
  if i mod 3 == 0 or i mod 5 == 0:
  sum = sum + i

echo sum
assert(sum == 233168)

Alternately, a different solution using Arrays.
type
  IntArray = array[1..999, int]
var 
  total = 0 
  x: IntArray

for i in low(x)..high(x):
  if i mod 3 == 0 or i mod 5 == 0:
    total += i

echo total
assert(total == 233168)

Result of the both solutions.
$ nimc p1.nim
233168
233168