Slashdot Mirror


Singapore's Prime Minister Shares His C++ Sudoku Solver Code

itwbennett writes: Several weeks ago, during a speech at the Founders Forum Smart Nation Singapore Reception, Singapore's prime minister Lee Hsien Loong said that he used to enjoy programming, and that the last program he wrote was a Sudoku solver in C++. To back that up, earlier today he announced (on Facebook and Twitter) that his code is available to download. He wrote on Facebook that he wrote the program 'several years ago' and that the code does 'a backtrack search, choosing the next cell to guess which minimises the fanout.'

2 of 230 comments (clear)

  1. Free Amos Yee by Anonymous Coward · · Score: 2, Interesting

    Hey, The guy released his Sudoku solver code, and that's great!
    Now how about using the same logical prowess to release Amos Yee?

    https://youtu.be/dD4y3U4TfeY

  2. From his Facebook post on his Sudoku solver by cciRRus · · Score: 5, Interesting
    He posted this on his Facebook.

    For techies: the program does a backtrack search, choosing the next cell to guess which minimises the fanout.

    Here’s a question for those reading the source code: if x is an (binary) integer, what does (x & -x) compute?

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

    ===========

    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.

    Nice!

    --
    w00t