La Salle Debain

Open Source @ Consolidated Braincells Inc.

Search for:

Show past days of news

About La Salle Debain

This is a weblog I'm keeping about my work on Debian and any other useful Debian related info I come across. It is not meant to compete with other news sources like Debian Weekly News or Debian Planet. Mostly it is just a way for me to classify and remember all the random bits of information that I have floating around me. I thought maybe by using a blog it could be of some use to others too. Btw. "I" refers to Jaldhar H. Vyas, Debian developer for over 8 years. If you want to know more about me, my home page is here.

The name? Debain is a very common misspelling of Debian and la salle de bains means bathroom in French.

If you have a comment to make on something you read here, feel free to write to me at jaldhar@debian.org.

You can get an rss 0.91 feed of the blog here.

Saturday, March 4 2017

Harshad Numbers

Today while looking up something in my productivity nemesis Wikipedia, I was waylaid by an article on Harshad numbers. (Link goes to Wolfram Mathworld out of spite.) This was interesting to me because Harshad is my patronym. Harshad numbers are also known as Niven numbers but what kind of a crazy name is that? A Harshad number is a positive integer that is divisible by the sum of its' digits.

1-10 are obviously Harshad numbers in base 10. 11 is not because 1 + 1 = 2 and 11 is not divisible by 2. 12 is because 1 + 2 = 3 and 12 is divisible by 3. And so on...you get the picture. Things get even more interesting when you deal with other bases.

Here is a perl one-liner to get the base 10 Harshad numbers from 1 to 100.


$ perl -E '$i=0+shift;for$n(1..$i){$t=0;map{ $t+=$_+0}(split q{},$n);print $n%$t==0?"$n ":q{};}say' 100
1 2 3 4 5 6 7 8 9 10 12 18 20 21 24 27 30 36 40 42 45 48 50 54 60 63 70 72 80 81 84 90 100

posted at: 01:14:27 | #