It's enough work for most government leaders just to get on with their day jobs of running a country properly, but Singapore's prime minister has put them all to shame by posting on Facebook the code for a computer program he wrote in his spare time.

Singapore PM Lee Hsien Loong has become well known in the last two years for being one of the most social media savvy politicians in the world. On 4 May he told his 765,000 Facebook followers that he coded a computer program a few years ago to solve the Japanese number puzzle Sudoku using C++.

He posted a screenshot of the programming code on his Facebook page together with a link to a Google Drive folder containing the source code, the program .exe file and a sample printout.

PM Lee decided to share the computer program after mentioning it in a speech he gave on 20 April to the Founders Forum – a private network of leading international digital and technology entrepreneurs – who were in Singapore for the Smart Nation conference.

"I told the Founders Forum two weeks ago that the last computer program I wrote was a Sudoku solver, written in C++ several years ago. Someone asked me for it," PM Lee wrote on his Facebook page.

"The program is pretty basic: it runs at the command prompt, in a DOS window. Type in the data line by line (e.g. 1-3-8---6), then the solver will print out the solution (or all the solutions if there are several), the number of steps the program took searching for the solution, plus some search statistics.

"Hope you have fun playing with this. Please tell me if you find any bugs!"

The prime minister even posed a programming riddle to his followers, and then provided the answer in the comments with a smiley face emoticon, almost like a teacher chatting to his class: "Here's a question for those reading the source code: if x is an (binary) integer, what does (x & -x) compute?"

"Answer: As several of you noted, (x & –x) returns the least significant '1' bit of x, i.e. the highest power of two that divides x. This assumes two's complement notation for negative numbers, as some of you also pointed out. e.g. if x=12 (binary 1100), then (x & -x) = 4 (binary 100). I didn't invent this; it is an old programming trick. :)"

PM Lee mentioned in his speech that both of his children are working in the IT industry and both of them graduated from MIT: "One of them browsed a [computer programming textbook] and said, 'Here, read this.' It said 'Haskell – learn you a Haskell for great good', and one day that will be my retirement reading."

PM Lee has a first class honours degree in mathematics as well as a diploma in computer science (with distinction) from Cambridge University, and a Master's in public administration from Harvard University.

Singapore, which has historically had a much higher rate of computer ownership and internet penetration, is increasingly focused on developing next-generation technologies.

The Singapore government wants entrepreneurs and inventors to use the small island nation as a test bed for new solutions to help the world, whether it be using drone waiters to deliver food in restaurants, 3D printed cars and exoskeletons, or technology to help the elderly live independently.