12 ms·
PM of Singapore Shares His C++ Sudoku Solver Source Code
- doppp 12y agoI've put it on GitHub in case this is ever removed. :) https://github.com/Doppp/LHL-Sudoku-Solver https://github.com/Doppp/LHL-Sudoku-Solver
- onderkalaci 12y agoYeap, great idea :)
- michael_h 12y agoCode without a license on it is not public domain. In this instance, he probably won't care, but it's a bad habit to get into.
- kenrick95 12y agoRemarkable. He uses lots of bitwise operations in the application.
- efaref 12y agoHe's using integers as sets of (small) integers, int Possibles = Block[BlockIndex] & Row[RowIndex] & Col[ColIndex]; while (Possibles) { int valbit = Possibles & (-Possibles); // Lowest 1 bit in Possibles Possibles &= ~valbit; Entry[Square] = valbit; Block[BlockIndex] &= ~valbit; Row[RowIndex] &= ~valbit; Col[ColIndex] &= ~valbit; is more generally: set<int> possibles = block[block_index].intersect(row[row_index]).intersect(col[col_index]); while (!possibles.is_empty()) { int value = possibles.pop(); entry[square] = value; block[block_index].remove(value); row[row_index].remove(value); col[col_index].remove(value);
- nothrabannosir 12y agoI like this one a lot: Entry[Square] = BLANK; // Could be moved out of the loop Maybe I'm reading too much into it, but this type of thinking makes me smile. The guilty perfectionism, "this can be improved." Were I from Singapore, I'd be happy to see it in the person in charge of my country.
- casion 12y agoWhile I find the code to be interesting, I wouldn't exactly claim to want this person as my PM. Great, he used to program and displayed a handful of positive character qualities in doing so. A lot more than that is required to be an effective leader of a country.
- delinka 12y agoCertainly a lot more is required. But this demonstrates that he's not some high-level politician that's completely out of touch with today's reality. It shows he's capable of logical thought. Two qualities I'd prioritize over all others in my leading politicians.
- Kurtz79 12y ago"But this demonstrates that he's not some high-level politician that's completely out of touch with today's reality" It demonstrates he can write a sudoku solver in C++, I don't see how this has anything to do with being in touch with reality.
- delinka 12y agoToday's reality that Software Code Is Everywhere. There are other aspects of reality that are most assuredly not addressed by the PM's programming prowess.
- EliRivers 12y agoIt shows he's capable of logical thought He is a senior wrangler.
- xwintermutex 12y agoLooks more like C than idiomatic C++ at a first glance.
- experimental- 12y agoA very quick glance suggests to me that the only thing C++ specific there is the filename extension (although a C compiler would do a more thorough check than I do; and faster, even!)
- unscaled 12y agoAnd the single-line comments, if not using a C99-compliant compiler. I wouldn't be surprised if he was using Visual C++ and had to change the extension to support a comment syntax that doesn't make you want to strangle yourself.
- tcholas 12y agoWas going to comment exactly the same thing
- kachnuv_ocasek 12y agoBy the way, supposedly, he wrote this "years ago".
- Keyframe 12y agoGlobals and, more serious offense, braces on newline!
- mmahemoff 12y agoContext from his speech: http://www.pmo.gov.sg/mediacentre/transcript-speech-prime-minister-lee-hsien-loong-founders-forum-smart-nation-singapore http://www.pmo.gov.sg/mediacentre/transcript-speech-prime-mi... Previously on HN: https://news.ycombinator.com/item?id=9419035 https://news.ycombinator.com/item?id=9419035
- hiby007 12y agoCool PM to have :)
- Spooky23 12y agoMeanwhile, in the U.S. a president barely has the ability to access a computer due to the ridiculous regulations surrounding them.
- lugus35 12y agoBuffer overflow on line 83. Input length is not checked but it must not be more than 79 characters long.
- lugus35 12y agoSudoku2.cpp: In function 'void PrintStats()': Sudoku2.cpp:98:12: warning: unused variable 'j' [-Wunused-variable] int i, j, S; ^
- Theodores 12y agoClinton could play the Saxophone, after that I am struggling to think of any politicians able to demonstrate a useful skill. Programming might not be that hard to pick up if you had done it before, couldn't this code have been written on a 25 year old computer to compile with a Borland era compiler? Because the wider population don't understand programming and see it as magic, I fully expect his popularity to do well, he is practically a hacker in their eyes, able to conjure up magic and demonstrate skill.
- DanBC 12y agoMargeret Thatcher was a chemist. She's variously credited with inventing "raspberry ripple" icecream, or "Mr Whippy" soft-serve style icecream. (The last one is definitely not true, it was invented a long time before she started working).
- eru 12y agoAngela Merkel has a PhD in physical chemistry.
- userbinator 12y agodemonstrate a useful skill Speaking in public (especially to very large crowds) and not turning into a nervous wreck is not a useful skill?
- k-mcgrady 12y ago>> "Because the wider population don't understand programming and see it as magic, I fully expect his popularity to do well, he is practically a hacker in their eyes, able to conjure up magic and demonstrate skill." The general public don't think of you as some sort of magic hacker because you code for a living, sorry.
- Lrigikithumer 12y ago... he didn't imply they did
- 12y ago
- zedadex 12y agoWhat a fascinating world this will be.
- blakecaldwell 12y agoCan someone (less lazy than me) try running it against this puzzle? http://www.telegraph.co.uk/news/science/science-news/9359579/Worlds-hardest-sudoku-can-you-crack-it.html http://www.telegraph.co.uk/news/science/science-news/9359579... It's been over a year since I've thought about solving sudoku, but here's how I solved it then: https://github.com/wblakecaldwell/c-sudoku-solver https://github.com/wblakecaldwell/c-sudoku-solver
- pegler 12y agohttps://gist.github.com/pegler/752ae571c5d6028ebe72 https://gist.github.com/pegler/752ae571c5d6028ebe72 Row[1] : 800000000 Row[2] : 003600000 Row[3] : 070090200 Row[4] : 050007000 Row[5] : 000045700 Row[6] : 000100030 Row[7] : 001000068 Row[8] : 008500010 Row[9] : 090000400 8-- --- --- --3 6-- --- -7- -9- 2-- -5- --7 --- --- -45 7-- --- 1-- -3- --1 --- -68 --8 5-- -1- -9- --- 4-- 812 753 649 943 682 175 675 491 283 154 237 896 369 845 721 287 169 534 521 974 368 438 526 917 796 318 452 Level Counts: (8, 7): 1 (7, 7): 2 (7, 2): 3 (7, 5): 5 (2, 2): 7 (6, 2): 11 (1, 2): 20 (1, 7): 33 (6, 7): 51 (4, 7): 62 (2, 7): 86 (5, 2): 114 (8, 2): 160 (5, 3): 195 (5, 8): 217 (5, 9): 260 (5, 1): 317 (5, 4): 371 (4, 8): 398 (4, 9): 456 (6, 9): 473 (6, 1): 440 (6, 3): 429 (6, 5): 407 (6, 6): 392 (4, 3): 364 (4, 1): 360 (7, 6): 330 (7, 1): 302 (2, 1): 264 (7, 4): 229 (8, 5): 200 (4, 5): 164 (1, 5): 134 (2, 5): 115 (2, 6): 92 (1, 6): 71 (3, 6): 63 (4, 4): 47 (1, 3): 41 (8, 6): 37 (3, 4): 28 (3, 1): 20 (8, 9): 15 (2, 9): 12 (2, 8): 7 (1, 8): 4 (3, 9): 4 (3, 8): 1 (8, 1): 1 (1, 9): 1 (9, 1): 1 (1, 4): 1 (9, 3): 1 (9, 4): 1 (9, 5): 1 (9, 6): 1 (3, 3): 1 (9, 8): 1 (9, 9): 1 Count = 7826 Total Count = 13080
- taeric 12y agoDecided to try this puzzle against an implementation of the DLX algorithm I put up a while back.[1] Looks at 2,825 board states, in total. If I stop it at the solution, only looks at 1,489 states. [1] http://taeric.github.io/Sudoku.html http://taeric.github.io/Sudoku.html
- dragonbonheur 12y agoNow, could someone with his age and experience get a job in Silicon Valley? The answer is precisely what is wrong in today's tech firms. Ageism must die.
- eru 12y agoHe has a lot of experience in management positions, and was the Senior Wrangler in Cambridge. I bet you dollars to donuts he could get a job in SV.
- dragonbonheur 12y agoNot him specifically, someone of the same age or even 10 years younger and same experience in C++ programming.
- balabaster 12y agoand the same management and entrepreneurial chops? Investors care about one thing: Money. If you can demonstrate to them less risk and more financial gain, they'll throw their money at you. Age has nothing to do with it. In the absence of knowing, they'll throw their money at anyone who can sell them on a lucrative vision and that person's ability to deliver that vision.
- Lrigikithumer 12y agoPeople with agendas making aggressive comments on barely related subjects to incite arguments which accomplish nothing are precisely what is wrong with todays online discussion.
- unfunco 12y agoYes. Absolutely. Experience managing the resources of a population of 5.5 million, experience on the world stage, programming and problem solving ability, his alma mater include Cambridge and Harvard, and military service, able to maintain close relationships with important people (including the President of the United States.) He would absolutely get a job in Silicon Valley.
- yincrash 12y agoIs there proof that this is his?
- codeulike 12y agoHe was the top of his year in Mathematics at Cambridge, which is pretty damn hardcore. So its definitely feasible that he could bang out some C++ code.
- Gigablah 12y agoPosted on his official Twitter account: https://twitter.com/leehsienloong/status/595166789660647426 https://twitter.com/leehsienloong/status/595166789660647426
- kenrick95 12y agoHe posted on Facebook, with screenshot of DevCpp. https://www.facebook.com/leehsienloong/photos/a.344710778924968.83425.125845680811480/905828379479869/?type=1 https://www.facebook.com/leehsienloong/photos/a.344710778924...
- Lrigikithumer 12y agoCapitalised identifiers? Global variables? Inconsistent indentation? PM of Singapore needs a better style guide.
- rikf 12y agoThis is awesome and I don't wanna hate but the question has to be asked why c++? There are tens more languages that are more modern and "aspirational"
- noipv4 12y agoShort of getting whipped, even the PM will learn to code. <sarcasm>
- whizzkid 12y agoLittle bit off topic but, Google Drive is giving me 500 error. It was long time ago I read that Google was directly rejecting the CVs that have typos in them which I find it annoying and not nice. And today I see this title typo in their error page which is totally fine and a mistake that i also make sometimes (leaving shift button little early while pressing 1) <title>Error 500 (Server Error)!!1</title> "For Google — a company that sees 50,000 résumés a week — the typo is one of five résumé mistakes that will immediately land yours in the "no" pile." [0] http://www.businessinsider.com/google-resume-mistake-2014-9?IR=T http://www.businessinsider.com/google-resume-mistake-2014-9?... Human beings will make mistakes Google, there is no need to extremely force it to otherwise.
- schrodinger 12y agoI would suspect that was intentional.
- whizzkid 12y agohmm, when i think about it now, maybe it was!!1
- balabaster 12y agoOccasionally you'll also come across someone who beats the joke to death just to make their point!!!1111OneOneEleven
- Gigablah 12y agoIt's deliberate. One of those "internet culture" things. Engineers are allowed to have a bit of humour sometimes.
- daveid 12y ago!!1 and variations thereof are intentional, it's a joke about being so excited you can't hold shift any longer.
- amelius 12y agoWhat strategy is this solver using? Is it a brute-force approach? Are there heuristics used?
- vasilipupkin 12y agoI think it's neat and could draw more people to CS, but yeah, people, let's not get overexcited over this. Knowing how to write a Sudoku solver in C++ says nothing, positive or negative about him as a prime minister
- deleted 12y ago[deleted]
- balabaster 12y agoI've been a (reasonably successful) programmer for 20+ years and I don't even know how to play Sudoku, nor does learning interest me... not being able to write a Sudoku solver bears no resemblance on ones capabilities. This goes the same as being able to write one. So I agree, getting excited about this seems somewhat... irrelevant. Being able to write any kind of computer program doesn't demonstrate being capable of effective leadership. Having a compelling vision for one's country, understanding the issues you will need to overcome to get there and inspiring the people to help you take it there are far more relevant to me. Knowing a bit of C++ and understanding an algorithm to make it solve a puzzle is largely useless in this context. Understanding a bit about technology at (close to) the lowest level, doesn't signify an understanding of how the internet works, how encryption systems work, how network security or the communications infrastructure works. Without an understanding of these in today's world of the communications and the internet, you may as well not understand how to program at all. Where we see technology failing the people (certainly in North America) are because legislators are largely incompetent in this context and seek to protect corporate interests over the needs of the people. I would say, being a systems administrator or systems analyst would make you far more capable of understanding the implications of technical bills and regulations than understanding a bit of C++.
- rustyrubygone 12y agoPoliticians and important folk recognise the power and awesomeness of C++, and don't waste time on Ruby, Go, Rust or other time waster languages!
- edpichler 12y agoFor people who are criticizing this, try to find something good on it: it's just a curiosity about a powerful man of a well succeed country, that can inspire someone. This also can be considered as a positive fact for me, once in my country, it's common to find politicians that even doesn't have any degree (including a very recent president).