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.'

230 comments

  1. Lead By Example?! by Anonymous Coward · · Score: 1

    Is a politician actually doing it?

    1. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      Is a politician actually doing it?

      Yes, he is a Southeastern Asian that leads by example solving Sudoku... or you mean the "code" thing? Well, (and since i can't claim all, not even most...) many politicians know how to do other things also - o.k., it is interesting for the /. crowd that he knows to code, but our former prime-minister had a restaurant... what would be more important for you if you were a survivor of a zombie apocalypse, a stupid Sudoku solver or our great Greek dinner with mousaka, some feta cheese and retsina wine, and a galaktoboureko for desert? I know what i would prefer!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    2. Re:Lead By Example?! by qpqp · · Score: 1

      Po-po, re malaka... Galaktoboureko... I'd kill to have some over here...

    3. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      Etsi ine patrioti... ti sudoku kai malakies... dose galaktoboureko ston lao reee! Don't kill anyone, just come to Greece gia na tin breis!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    4. Re:Lead By Example?! by quenda · · Score: 3, Funny

      but our former prime-minister had a restaurant... our great Greek dinner with mousaka,

      Which one? You'd have hoped with that experience he might have had some idea how to balance the books. Did his restaurant go broke?

    5. Re:Lead By Example?! by antiperimetaparalogo · · Score: 4, Informative

      but our former prime-minister had a restaurant... our great Greek dinner with mousaka,

      Which one? You'd have hoped with that experience he might have had some idea how to balance the books. Did his restaurant go broke?

      It was mister Samaras, the one who just lost the elections - (he claims) his restaurant did just fine (he had it years ago, together with a business partner, while studing in USA - yes, one more Greek restaurant in the States!). To be fair he did a good job as a prime minister in the elimination of deficit, he not only balanced the books, but provided a (significant) surplus. Our new prime minister...well...!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    6. Re:Lead By Example?! by Anonymous Coward · · Score: 0

      I'll pass on both.

    7. Re:Lead By Example?! by qpqp · · Score: 1

      just come to Greece

      As soon as I'm done here.. But looks like this year, finally! ('cause I feel like the guy in the middle with regards to Hellas!

    8. Re:Lead By Example?! by someone1234 · · Score: 1

      If someone can create a recursive sudoku solver, he can do other stuff. What about a brute force password cracker with shortcuts? Since a zombie apocalypse isn't coming soon, and food is easy to come by, i would actually prefer an expert coder.

      --
      Patents Drive Free Software as Hurricanes Drive Construction Industry
    9. Re:Lead By Example?! by SuricouRaven · · Score: 1

      Any zombie survival team needs an expert in at least four fields: Combat, medicine, survival and technology.

      Combat and medicine keep the team alive.
      Survival collects food, at least for the first few months - after that it becomes safer to return to the urban areas where you can just grab canned food with ease.
      Technology establishes communications with other survivors and maintains the radio gear and power source.

    10. Re:Lead By Example?! by Anonymous Coward · · Score: 0

      Oh really now? Have you seen how he raised the debt while at the same time taking measures that cripppled the social nature of the government?

      http://www.google.gr/publicdata/explore?ds=ds22a34krhq5p_&met_y=gd_pc_gdp&idim=country:el:de:it&hl=en&dl=en

    11. Re:Lead By Example?! by Anonymous Coward · · Score: 0

      Yeah. I'm going with the guy who amasses surpluses each year over the bankrupt guy.

    12. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      If someone can create a recursive sudoku solver, he can do other stuff.

      O.K., if can also cook, i am fine with someone who can create a recursive sudoku solver.

      What about a brute force password cracker with shortcuts?

      What about it? Will that "brute force password cracker with shortcuts" help us cook our Greek mousaka? If yes then i am o.k. with it, lets use it dude!

      Since a zombie apocalypse isn't coming soon, and food is easy to come by, i would actually prefer an expert coder.

      O.K, i admit "a zombie apocalypse isn't coming soon", but since you admit "food is easy to come by" you must accept that cookers are more useful than any coder... just taste our Greek mousaka and you will forget all those code guys.

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    13. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      Never been outside Greece for more than a couple of months so i can't relate to you my dear patrioti (but i can relate to the guy on the video...). Anyway, since most of my family lived in Germany for years, i wish you the best where ever you are (i hope it's some exotic place, but probably you may feel like that very often)... take care brother...

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    14. Re:Lead By Example?! by Anonymous Coward · · Score: 0

      Jeez. Are you obsessed with your Greek identity?

    15. Re:Lead By Example?! by Anonymous Coward · · Score: 0

      I prefer Turkish moussaka myself.

    16. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      Oh really now? Have you seen how he raised the debt while at the same time taking measures that cripppled the social nature of the government?

      http://www.google.gr/publicdata/explore?ds=ds22a34krhq5p_&met_y=gd_pc_gdp&idim=country:el:de:it&hl=en&dl=en

      The data you provide are up to fiscal year 2013, and most important it is about debt (he managed to balance the books and have surplus from which our debt will be payed back) - the "social nature" of the government is our problem... that created the debt, that creates the current social problems!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    17. Re:Lead By Example?! by qpqp · · Score: 1

      since most of my family lived in Germany for years

      Ha! That's where I am right now, for years too... Hope your family boar/bears this place better than I do.

      (i hope it's some exotic place, but probably you may feel like that very often

      Yeah, I wish it was exotic, at least that I had the sea close to me.. So that is indeed how I often feel mixed with this.
      Thanks for the empathy!
      And from the many songs, this is mine.

      take care brother...

      K' esi, adelfe! Euxaristo!

    18. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      Most of my family (i been there only as a baby) left Germany and returned in Greece (now i have only few cousins living there, married to German wifes). I am originaly from northern-eastern Greece (you know, where almost all, or their families, were in Germany!), living the last few decades in Athens (you know, where almost all, or their families, are originaly from some other part of Greece!), feeling like an immigrant with nostalgia for his home! O.K., my case is not so bad as yours (and i believe/hope yours is not as bad as the older's were), but i feel you patrioti...

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    19. Re:Lead By Example?! by qpqp · · Score: 1

      married to German wifes

      OMG!

      yours is not as bad as the older's were

      Oh, I'm definitely closer than the Greeks in Australia or the US, but I still really, really look forward to coming back.
      Guess I'll have to write a song, 'cause I can't think of one about this.. Hmm..

    20. Re:Lead By Example?! by antiperimetaparalogo · · Score: 1

      married to German wifes

      OMG!

      paradosiakos tipos - "papoutsi apo ton topo sou, kai as einai kai mpalomeno"

      yours is not as bad as the older's were

      Oh, I'm definitely closer than the Greeks in Australia or the US, but I still really, really look forward to coming back.

      nai, ela piso gia na armegeis kotes...

      Guess I'll have to write a song, 'cause I can't think of one about this.. Hmm..

      ama kseris apo mpouzouki!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    21. Re:Lead By Example?! by qpqp · · Score: 1

      Nai... Den xsero, re file. Otan vlepeis mia omorfh gynaika edo, 90 tis 100 tha einai apo anatolikh h notia Europh.
      The grass is always greener on the other side, etc. Ala kalitera kotes na armego apo ypofero ta sklavakia ths nomos edo. Kai den exei thalassa, oute hlios. Telos panton... Feugoumai se ligo.

  2. That's C code by Anonymous Coward · · Score: 1, Informative

    Not C++.

    1. Re:That's C code by fisted · · Score: 2, Informative

      void Succeed()

      That's actually more C++'ish, a C programmer would put it as

      void Succeed(void)

      Which means in C what the former means in C++.
      </nitpick>

      Apart from that, yeah. It's pretty much C. Almost C89, even, were it not for the C++ style comments and two instances of mixed declarations and code.

    2. Re:That's C code by Anonymous Coward · · Score: 0

      Yep, I normally moan about people writing "C with classes" and thinking it's C++, but this isn't even C with classes.

    3. Re: That's C code by Anonymous Coward · · Score: 0

      I just moan about people using anything but C ;)

    4. Re:That's C code by Anonymous Coward · · Score: 0

      void Succeed()

      That's actually more C++'ish, a C programmer would put it as

      What you are seeing here is K&R syntax for a parameterless function.
      Considering that that form was deprecated in C89 it seems odd to mix it with single line comments but perhaps he used a mix of K&R and other textbooks when he learned how to program.

    5. Re: That's C code by Anonymous Coward · · Score: 1

      In C int foo(void) and int foo() declare totally different types. The former declares a function with no arguments. The latter declares a function with an unspecified number of arguments with unspecified type. I believe C++ doesn't permit the latter, and so the same syntax in C++ has quite different behavior in C.

      I use it for the rare occasion I need a polymorphic function pointer in C and don't need the useless of hassle of strong typing, which would otherwise require a union of function pointers. For example, a state machine with a function pointer register.

      The following is legal C but I believe illegal C++:

      int (*fun)();
      int foo(int, int);
      int bar(void *);

      fun =
      fun =

    6. Re:That's C code by hcs_$reboot · · Score: 1, Funny

      a C programmer would put it as void Succeed(void)

      A C programmer would put it as 'void succeed()' or even 'succeed()'.

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    7. Re:That's C code by Anonymous Coward · · Score: 0

      Most probably "void succeed(void)" as upper cases are a no-no and void(s) should be traditionally visible.

    8. Re:That's C code by Anonymous Coward · · Score: 0

      That's the way I was taught by C for Dummies.

    9. Re:That's C code by fisted · · Score: 1

      In the absense of a return type, that'd be 'int', and GP doesn't seem to understand the difference between no parameters and unspecified parameters...

    10. Re:That's C code by fisted · · Score: 1

      No; please learn C.

    11. Re:That's C code by Anonymous Coward · · Score: 0

      If you want to nitpick, start with the first line of code:

      #include "stdio.h"

      What ever happened to using the standard library include directories?

    12. Re:That's C code by Jobless+*topia · · Score: 1

      How about this?

      $ tcc -v Sudoku2.cpp
      tcc version 0.9.26 (x86-64 Linux)
      -> Sudoku2.cpp
      Sudoku2.cpp:1: error: unrecognized file type
      $ cp Sudoku2.cpp Sudoku2.c
      $ tcc -v Sudoku2.c
      tcc version 0.9.26 (x86-64 Linux)
      -> Sudoku2.c
      $ ./a.out
      Row[1] : ^C

      Also compiles under gcc and g++. Except for the file extension;) the PM's code is legal and portable C and therefore also legal C++. The code, however, appears to have poor runtime error handling. The program will happily accept any character you input from the keyboard, punctuation marks as well as letters and numerals. Other posters have also noted the absence of any online help or usage instructions.

    13. Re:That's C code by fnj · · Score: 1

      There is legal and portable C that is not C++. Yes, C++ is close to a superset, but it is NOT a superset.

    14. Re:That's C code by fisted · · Score: 2

      Also compiles under gcc and g++. Except for the file extension;)

      You cannot use "$compiler compiles it" to determine whether it's portable or correct C, just look at all the non-C garbage gcc happily accepts.
      Though in this case i'm not saying it wouldn't be correct; I just pointed out that C programmers usually wouldn't declare their function to have an unspecified number of arguments when what they really want is no arguments. It's not wrong; just unusual, C++ influenced style.

      the PM's code is legal and portable C

      Possibles &= ~(Possibles & -Possibles);
      Portable my ass. This at least requires two's complement. I'm also fairly sure that in addition to being nonportable, it's undefined behaviour unless there's a sequence point i'm missing (can verify that later)

      and therefore also legal C++.

      Don't be silly. Valid C isn't automatically valid C++, and if you have a program that happens to be something both a C and a C++ would accept, it doesn't need to have the same behaviour. Consider:

      int main(void)
      {
      int class = 42;
      }

      That's strictly conforming C, and invalid C++

      Further consider:

      int main(void)
      {
      for (size_t i = 0; i puts("poof");
      }

      That's valid C++, invalid C89, strictly conforming C99/C11. When treated as C, it will behave different from when treated as C++, unless your implementation has char and int being of the same width, which is rather unusual.
      Thanks for playing.

    15. Re:That's C code by fisted · · Score: 1

      for (size_t i = 0; i puts("poof");

      Duh, /. ate a <. That should read:
      for (size_t i = 0; i < sizeof '0'; i++) puts("poof");

    16. Re:That's C code by hcs_$reboot · · Score: 1

      GP doesn't seem to understand the difference between no parameters and unspecified parameters...

      In C, the compiler doesn't care if you return nothing from a 'int' function. So, while 'void f()' would be cleaner, only 'f()' without a return type set (ie 'int') is seen a lot.
      :-)

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    17. Re:That's C code by hcs_$reboot · · Score: 1

      I teach you C - or at least the things you ignore - anytime.

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    18. Re:That's C code by fisted · · Score: 1

      In C, the compiler

      "The" compiler? You do realize that C is a language specification, right?

      doesn't care if you return nothing from a 'int' function.

      That's just wrong. It's possible (though unlikely) that your compiler "doesn't care"> It's undefined behaviour to fail to return a value from a non-void function. It doesn't get much wronger; and as a consequence of UB, the compiler isn't even required to do anything meaninful afterwards. If your particular implementation tolerates it, fine, but please don't conclude that it must be how C works then. You're outside the scope of C at that point.

      So, while 'void f()' would be cleaner, only 'f()' without a return type set (ie 'int') is seen a lot. :-)

      Yes, garbage code is seen a lot. You're not making it better by actively promoting horrible, non-portable, implementation-dependent and error-prone coding practices. Also, again, () means "unspecified number of parameters", (void) means "no parameters". C isn't quite C++.

    19. Re:That's C code by fisted · · Score: 1

      Care to teach me what the types of 0, '0' and "0" in C are?

    20. Re:That's C code by fisted · · Score: 1

      I guess i can outnitpick you on that; #include "stdio.h" is actually fine. Not that it's a good idea, but it will give you the same effect #include does, as far as the standard is concerned.

      Besides, the real failure about that line is that in C++ it should probably read #include <cstdio> (unless i'm mistaken; i do know my C, but C++ not so much)

    21. Re: That's C code by Anonymous Coward · · Score: 0

      Actually, in C++ you can "declares a function with an unspecified number of arguments with unspecified type." It done like this:

      int foo(...);

      which is illegal in C.

    22. Re:That's C code by Anonymous Coward · · Score: 0

      It won't give you the same effect at all. "stdio.h" searches the directory containing the current source file first, then the include directories. If you have a file called stdio.h there, it will be included instead of system stdio.h. That's not "the same effect as far as the standard is concerned" at all, and there's the reason it's not a good idea. If you're "outnitpicking" people who have read the standard, make sure you read it too ...

      People include "stdio.h" in C++ all the time, BTW.

    23. Re:That's C code by Anonymous Coward · · Score: 0

      0 is int. '0' is int. "0" is static char[2].

    24. Re: That's C code by Anonymous Coward · · Score: 0

      A union of function pointers? Ugh. Since both languages guarantee that all function pointers are the same size, a simple cast would suffice.

    25. Re: That's C code by shutdown+-p+now · · Score: 1

      It's still not the same thing. In C, you can declare a function without specifying the argument types, but then define it with specific types in a different translation unit. In C++, the definition and the declaration must match - if you declare it as int foo(...), then you must also define it in the same way (which renders it effectively useless, since without any named arguments you won't have anything to pass to va_*).

    26. Re:That's C code by shutdown+-p+now · · Score: 1

      OP is likely confusing the special exception that int main() gets for a general rule. For main, you can indeed return nothing, despite its return type, and that is equivalent to returning 0. This works in both C and C++.

    27. Re:That's C code by shutdown+-p+now · · Score: 1

      "stdio.h" searches the directory containing the current source file first, then the include directories.

      The standard itself doesn't have any notion of "directory containing the current source file" or "include directories", actually. It just says that "..." does some form of implementation-defined search, which, if it fails, falls back to <...>.

    28. Re:That's C code by shutdown+-p+now · · Score: 1

      stdio.h and cstdio are both valid in C++. However, there is a slight difference - cstdio is only guaranteed to define the identifiers that it provides in namespace std, while stdio.h makes the same guarantee only for the global namespace. In practice, they are usually both backed by the same header that does both, so you'll get both - but relying on that is non-portable. Since he doesn't use std:: to refer to those identifiers, "stdio.h" is the correct header for him to include.

    29. Re:That's C code by fisted · · Score: 1

      OP is likely confusing the special exception that int main([void]) gets for a general rule. For main, you can indeed return nothing, despite its return type, and that is equivalent to returning 0. This works in both C and C++.

      Yeah that sounds likely. I never understood why C99 intruduced that implicit return for main while at the same time doing away with most of the 'implicit int' nonsense...

    30. Re:That's C code by fisted · · Score: 1

      That's good to know, thanks.

    31. Re:That's C code by fisted · · Score: 1

      If you're "outnitpicking" people who have read the standard, make sure you read it too ...

      The irony. Sibling already explained it so I'll skip repeating that post purely to ridicule you that meta-fail.

    32. Re:That's C code by fisted · · Score: 1

      Did I ask you, dear AC, or hcs_$reboot? I'm fairly confident that he wouldn't have managed to answer it, but thanks for ruining it anyway.
      Besides, static isn't part of the type so your feeble attempt to demonstrate that AC knows C is 33% failure.

  3. It may have a .cpp extension but it's all C code by Anonymous Coward · · Score: 2, Informative

    I guess C++ just sounds higher tech.

  4. Technically C++ by Imagix · · Score: 4, Insightful

    Well... probably more accurate to call that C code. It's compilable under a C++ complier, but offhand I didn't spot anything that really made it C++-specific. Not a knock on the Prime Minister, but it might even be a little more geek cred to call it a Sudoku solver in C.

    1. Re:Technically C++ by Anonymous Coward · · Score: 0

      It seems like he chose the C++ for the comments style ;)

    2. Re:Technically C++ by Dutch+Gun · · Score: 4, Insightful

      Heh, leave it to the tech community to start nitpicking which language was actually used rather than the fact that we're seeing the very rare sight of a computer programmer in political office.

      I took a look at the code - yeah, it's really just C code, but that's fine for a tiny project like this. Nice code, very clean and readable, but not very well commented.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    3. Re:Technically C++ by grumbel5969 · · Score: 1

      The "const int", "//" comments and mixing declarations and code are pretty typical for C++ and atypical for C code (but allowed in C99 I think).

    4. Re: Technically C++ by Anonymous Coward · · Score: 0

      Does your political leaders even know how to write a hello world program in c? If not pls shut up.

    5. Re:Technically C++ by Anonymous Coward · · Score: 0

      Well it isn't ANSI compliant, for one thing...

      Single line comments out the wazoo!

    6. Re:Technically C++ by vux984 · · Score: 1

      // comments were added to the C standard. Not good old ANSI see but still ok.

      I haven't looked at the code, but the one thing I usually trip over when having to write pure C instead of C++ that's really mostly C is that everything has to be declared at the top of the function... Always. even some variable you only use in the IF $DEBUG block, I normally declare those in the if $debug block where it occurs, rather than creating a 2nd if debug block at the top of the function just to declare it.

      And stuff like that.

    7. Re:Technically C++ by Anonymous Coward · · Score: 0

      Yep, that makes it C++ (inline variables), but you can cheat in C by starting a new {} block :-)

    8. Re:Technically C++ by Bite+The+Pillow · · Score: 4, Insightful

      Since Dice, and really well before, fuck all of that technicality. If the dude can solve sudoku in anything other than a pencil, should we really nitpick?

    9. Re:Technically C++ by fisted · · Score: 3, Insightful

      everything has to be declared at the top of the function... Always.

      That's not true, and has never been. Until about 16 years ago, you had to declare your variables at the beginning of a block/compound statement. That can be well within the function.

      As of about 16 years ago, you're even allowed to freely mix your declarations and code.

      [incoherent gibberish]. And stuff like that.

      Yeah. The kind of stuff you seem largely unfamiliar with.

      General hint: If your functions are so long that having to (suppose this was indeed the case) declare/define all your variables at the top becomes a serious annoyance, then chances are that your functions are too long/do too much. Fix that instead.

    10. Re:Technically C++ by Alomex · · Score: 1

      // comments were added to the C standard. Not good old ANSI see but still ok.

      Bzzt, wrong. The last ANSI approved version of C is C99, which includes // as a comment delimiter.

    11. Re:Technically C++ by IgnitusBoyone · · Score: 1

      Given the date he wrote it my guess is it would not have compiled under any standard c compiler. He does most of the foward declarations, but he uses C++ style comments and C++ style void declarations. So, while it might not be OOP it is C++ and likely not valid C.

      I'll grab the code tommorow and see what standards gcc4.8 will compiler it under.

      --
      Momento Mori
    12. Re:Technically C++ by marko123 · · Score: 1

      Heh, leave it to the tech community to start nitpicking which language was actually used rather than the fact that we're seeing the very rare sight of a computer programmer in political office.

      I took a look at the code - yeah, it's really just C code, but that's fine for a tiny project like this. Nice code, very clean and readable, but not very well commented.

      Well he might be following Uncle Bob's Clean Code concepts and not filling his code with comments that could become crufty and misleading over time.

      --
      http://pcblues.com - Digits and Wood
    13. Re:Technically C++ by marko123 · · Score: 1

      Heh, leave it to the tech community to start nitpicking which language was actually used rather than the fact that we're seeing the very rare sight of a computer programmer in political office.

      I took a look at the code - yeah, it's really just C code, but that's fine for a tiny project like this. Nice code, very clean and readable, but not very well commented.

      Well he might be following Uncle Bob's Clean Code concepts and not filling his code with comments that could become crufty and misleading over time.

      I take that back after reading all the one letter variable names :)

      --
      http://pcblues.com - Digits and Wood
    14. Re:Technically C++ by Threni · · Score: 3

      The comments are definitely c++.

    15. Re: Technically C++ by Sique · · Score: 4, Informative

      I guess, Angela Merkel knows. At least she wrote a program to simulate electron movements for her PhD thesis.

      --
      .sig: Sique *sigh*
    16. Re:Technically C++ by gnasher719 · · Score: 1

      Well... probably more accurate to call that C code. It's compilable under a C++ complier, but offhand I didn't spot anything that really made it C++-specific. Not a knock on the Prime Minister, but it might even be a little more geek cred to call it a Sudoku solver in C.

      Extra points then to him for writing code to solve a problem, and not writing code to demonstrate his cleverness. Which is what the worst of C++ programmers usually do.

    17. Re:Technically C++ by Anonymous Coward · · Score: 1

      No, they're not. That comment style is included in the ancient C99 standard, and gcc accepts them unless you're specifying C89-strict.

    18. Re:Technically C++ by Anonymous Coward · · Score: 0

      If your functions are so long that having to (suppose this was indeed the case) declare/define all your variables at the top becomes a serious annoyance, then chances are that your functions are too long/do too much. Fix that instead.

      No, not really. If you write safe code (checking return codes and so on) your function will be long enough to benefit from declaring your variables closer to their use. In any way, shortening the scope of your variable allows for some nice compiler optimizations. It's not only clearer, your code might run faster.

    19. Re:Technically C++ by fnj · · Score: 1

      It will. I suggest you bone up on C99.

    20. Re:Technically C++ by TheRaven64 · · Score: 1

      General hint: If your functions are so long that having to (suppose this was indeed the case) declare/define all your variables at the top becomes a serious annoyance, then chances are that your functions are too long/do too much. Fix that instead.

      More general hint: The principle of minimum scope exists for a reason. Declare your variables at the point where they can be initialised, not at some arbitrary point and you make life easier for people trying to understand the lifetime of the variable.

      --
      I am TheRaven on Soylent News
    21. Re:Technically C++ by fisted · · Score: 1

      I completely agree, and as said, C99 intruduced mixed declarations and code, and i use it a lot.

      I don't understand why you'd be telling me this, unless for some reason you have the same misconception about C89 that GP had - the gibberish about 'top of function'

    22. Re:Technically C++ by fisted · · Score: 1

      More general hint: The principle of minimum scope exists for a reason. Declare your variables at the point where they can be initialised, not at some arbitrary point and you make life easier for people trying to understand the lifetime of the variable.

      Sorry for double posting, but your more general hint is largely moot after after applying my less general hint, because there won't be as much code in a function in order to make it confusing wrt. to scope and storage duration anymore.

    23. Re:Technically C++ by TheRaven64 · · Score: 1

      Apparently I've not had enough coffee yet (or have spent too long staring at MIPS CPU traces to spot the error) and thought that you said the exact opposite of what you said.

      --
      I am TheRaven on Soylent News
    24. Re:Technically C++ by fisted · · Score: 1

      Fortunately, you can open a new scope at basically any point. If you don't care about long functions, what's there to lose?

    25. Re:Technically C++ by Anonymous Coward · · Score: 0

      He did say the exact opposite of that. He basically said if you need this feature your functions are too long. Not, this feature assists with RAII and I use it all the time. And then he implied that challenging him on that implies you don't understand C, which implies that he thinks that having declarations at the top of each new scope is enough to support RAII, which implies he doesn't understand RAII.

    26. Re:Technically C++ by vux984 · · Score: 1

      Bzzt, wrong.

      I'm not sure about that.

      ANSI C, also known as C89 and C90 depending on the year of ratification

      https://en.wikipedia.org/wiki/...

      Yes it also says:

      In March 2000, ANSI adopted the ISO/IEC 9899:1999 standard. This standard is commonly referred to as C99.

      Thus C99 is an ANSI standard, but its not "ANSI C"
      When you say "ANSI C" its still C89/90.

      At least that's my take on it.

    27. Re:Technically C++ by Anonymous Coward · · Score: 0

      Same AC here, disregard that. I just realized that I wasted years of time trying to do serious RAII in C, when I should've gone for a language which more naturally supports the concept.
      But then again, I'm but a pimply faced buzzword-spewing brogrammer. Ruby FTW!

    28. Re:Technically C++ by vux984 · · Score: 1

      Yeah. The kind of stuff you seem largely unfamiliar with.

      Lol, yes, relax. I'm not a pure C guy and I won't offend you by pretending to be.

      That's not true, and has never been. Until about 16 years ago, you had to declare your variables at the beginning of a block/compound statement. That can be well within the function.

      You know, until I saw it in this thread, it never occurred to me to just open a new block for the purposes of inlining a debug declaration. Thanks, I'll use that.

      As of about 16 years ago, you're even allowed to freely mix your declarations and code.

      Cool beans. The one C program I do have to maintain (a small 'plugin' DLL for an embedded system) I have to compile with Visual Studio 2010, which doesn't support C99 syntax. So as of about today I'm still not allowed to, even if the rest of the world has been enjoying it for 16 years. VS2012 doesn't have it either; but i hear VS2013 does. :)

      General hint: If your functions are so long that having to (suppose this was indeed the case) declare/define all your variables at the top becomes a serious annoyance, then chances are that your functions are too long/do too much. Fix that instead.

      That's not the issue at all. The specific example I gave was the issue:

      An IF DEBUG; where the variable was only used within the debug conditional.

      In C++, C#, etc I've always declared and initialized anything I needed in a debug block in the debug block, except for in C where not only did i declared it at the top, but it gets its own debug block too since its only used by debug builds.

      Even in a short function this is inelegant looking:


      void func(int a)
      {
            int x = 1;
            int y = 2;
            int z = 0;
      #IF DEBUG
            int q = 3;
      #ENDIF
            z = dosomething(a, x);
            y += z;
      #IF DEBUG // do something that needs z,y and q
      #ENDIF
      [... rest of function...]
      }

      Your note that I can start a block anywhere -- Thanks; until now it hadn't occurred to me to use that expressly to inline declarations for debug blocks.

    29. Re:Technically C++ by fisted · · Score: 1

      I have to compile with Visual Studio 2010, which doesn't support C99 syntax. So as of about today I'm still not allowed to, even if the rest of the world has been enjoying it for 16 years. VS2012 doesn't have it either; but i hear VS2013 does. :)

      Yes and no; VS2013 seems to understand a bit more or C99, but that isn't because Microsoft would suddenly have started caring about their C compiler. Their C++ compiler got a bit of an upgrade wrt. more recent changes to the C++ standard, and the C compiler understanding a few C99 idioms is largely a side-effect/waste-product of that process.

      The specific example I gave was the issue:

      An IF DEBUG; where the variable was only used within the debug conditional. [...]

      Okay, I see what you mean now.

      Your note that I can start a block anywhere -- Thanks; until now it hadn't occurred to me to use that expressly to inline declarations for debug blocks.

      My pleasure. Would you mind returning the favor and teach me how you post code in a /. comment without /. eating the indentation?

    30. Re:Technically C++ by vux984 · · Score: 1

      code tags of course. ;)

      <code> </code>

      And to post tags with out /. eating those html entities for less than and greater than:

      &lt; and &gt; and &amp; for the ampersand itself

    31. Re:Technically C++ by fisted · · Score: 1

      I
      must
      be
      stupid


      That's:
      <code>
      I<br>
      (tab)must<br>
      (spaces)be<br>
      &nbsp;&nbsp;&nbsp;&nbsp;stupid<br>
      </code>

      Not sure what I'm missing here. Whatever you did, /. translates it into &nbsp;'s inside <tt></tt> tags

    32. Re:Technically C++ by vux984 · · Score: 1

      Hmmm.... typed this; using 2 spaces using regular spacebar as indents:


      {
          This
              is
                  a
              test
      }

      Simply copy and pasted this from wikipedia


      ; Uses S-C Assembler variant.
      ; .or is origin
      ; .as is ASCII String
      ; .hs is Hex String .or $300
      main ldy #$00 .1 lda str,y
                      beq .2
                      jsr $fded ; ROM routine, COUT, y is preserved
                      iny
                      bne .1 .2 rts
      str .as "HELLO WORLD" .hs

      Then Using preview and viewing the page source I get:


      <code>
      {
          This
              is
                  a
              test
      }
      </code>

      and

      <code>
      ; Uses S-C Assembler variant.
      ; .or is origin
      ; .as is ASCII String
      ; .hs is Hex String .or $300
      main ldy #$00 .1 lda str,y
                      beq .2
                      jsr $fded ; ROM routine, COUT, y is preserved
                      iny
                      bne .1 .2 rts
      str .as "HELLO WORLD" .hs
      </code>

      I'm not getting nbsp entities nor am i getting TT tags?! I'm using Firefox on Windows 7; not sure what else to say?!!

    33. Re:Technically C++ by fisted · · Score: 1

      the <tt> tags appear when you click "Quote Parent" under the reply box.
      However, i figured it out, it was the comment posting mode that can be set in the account settings; it has to be "Plain old text" (but still supports HTML, oh well..)
                  Thanks. :)

    34. Re:Technically C++ by Dutch+Gun · · Score: 1

      Well he might be following Uncle Bob's Clean Code concepts and not filling his code with comments that could become crufty and misleading over time.

      I've never bought that argument. Comments simply need to be properly maintained along with the code. If you're not updating the comments when you change the code, you're doing a half-assed job.

      Besides, my take is that comments are generally most useful when they explain *what* you're attempt to do rather than *how* exactly you're doing it, and that tends to change far less frequently. The only exception to that general rule is when the code is particularly complex or tricky, and at that point, you should be writing comments in paragraphs.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    35. Re:Technically C++ by shutdown+-p+now · · Score: 1

      VS2013 seems to understand a bit more or C99, but that isn't because Microsoft would suddenly have started caring about their C compiler. Their C++ compiler got a bit of an upgrade wrt. more recent changes to the C++ standard, and the C compiler understanding a few C99 idioms is largely a side-effect/waste-product of that process.

      Not quite. VS 2013 actually saw a bunch of C-specific C99 features such as designated initializers for structs. The main reason why this was done is because there are now quite a few popular open source libraries that use those features, and VC is the only compiler that cannot handle them, which made it a pain to port them to Windows.

    36. Re:Technically C++ by shutdown+-p+now · · Score: 1

      I don't recall which comment mode this works with, but also try <ecode> instead of <code>. This also makes it unnecessary to escape < and > between the tags.

    37. Re:Technically C++ by fisted · · Score: 1

      Well i said 'largely'; the list of dedicated C99 features seems quite small; two of the four newly supported C99 language features are _Bool and mixing declarations and code. The other two, designated initializers and compound literals, okay. Not very far from C++ initializer lists, but yes this might be the part where MS actually paid a little attention to C.
      Your argument about open source libs does make sense, too, but purely from experience I would have expected MS to not give a damn :).

    38. Re:Technically C++ by fisted · · Score: 1

      <neat>

    39. Re:Technically C++ by shutdown+-p+now · · Score: 1

      In this particular case I just happen to know exactly what they were thinking when they were implementing this feature, because they are my colleagues (even if I don't work on the team that works on C++) :) The list of features that they did was based on some specific libraries that they had most complaints about on Windows, and then filtered down further based on ease of implementation. If I remember correctly, one major beneficiary of those changes is supposed to be ffmpeg.

      This all might make more sense if you remember that Office in some incarnation or the other now ships across three non-Windows platforms (OS X, iOS and Android), then there is the OneDrive client etc. Basically there's a whole bunch of stuff that has suddenly gone cross-plat in the past couple of years, and that's a lot of C++ code that now has to play ball with the libraries that are the de facto standard outside of the MS ecosystem. In many cases, once you start doing that, it makes sense to use the same library on Windows as well, but then you start running into those conformance issues with C99.

      The other aspect is that we want people to write cross-platform C and C++ code, because it's the kind that, right now, is most easily portable between all mobile platforms - and seeing where Windows phones and tables are in terms of popularity relative to iOS and Android, MS has to encourage portability as a way to get more apps ported to Windows. You see things like Apache Cordova tools and Clang/LLDB support in VS 2015 for the same reason - they make it easier to write Android apps, for example, but more importantly, the way they encourage writing those apps just happens to be the one that emphasizes portable code. Now that is more geared towards C++, but the question of popular libraries written in C also comes up there.

    40. Re:Technically C++ by fisted · · Score: 1

      In this particular case I just happen to know exactly what they were thinking when they were implementing this feature, because they are my colleagues (even if I don't work on the team that works on C++) :)

      Heh, fair enough. I guess I can't argue with that. Pretty surprising, though, because looking at your username here, the unix is kind of showing ;)

    41. Re:Technically C++ by shutdown+-p+now · · Score: 1

      My Slashdot username predates my current employment arrangement by about 5 years, I think. But, yeah. Back then I ran FreeBSD (which is where the name is from) on my servers, and Gentoo on my desktop. Things change :) (well, some of them; some of my home servers are still FreeBSD - ain't broken and all that...)

      By now, though, it's not really all that surprising, given the amount of work specifically targeting other platforms (Linux among them) happening throughout the company. My team, for example, is actually specifically looking for people with a Linux background right now, because we're building a service running on it, using Docker containers for isolation.

  5. Put in context by Anonymous Coward · · Score: 5, Informative

    The guy was a Senior Wrangler (top math undergrad) at Cambridge before going to governance. I would hope he'd have picked up some coding skills along the way.

    Now with some other leaders, I'm impressed when they spell their names right.

    1. Re: Put in context by Anonymous Coward · · Score: 5, Informative

      Wiki link to those who aren't across Cambridge lingo

      http://en.m.wikipedia.org/wiki/Senior_Wrangler_%28University_of_Cambridge%29

      The Senior Wrangler is the top mathematics undergraduate at Cambridge University in England, a position once regarded as "the greatest intellectual achievement attainable in Britain."

    2. Re: Put in context by Anonymous Coward · · Score: 2, Informative

      The Senior Wrangler is the top mathematics undergraduate at Cambridge University in England, a position once regarded as "the greatest intellectual achievement attainable in Britain."

      In other news wiping an adult mans arse was once considered the greatest political achievement attainable not by birth in Britain.

    3. Re: Put in context by Whiteox · · Score: 1

      +1 for using the correct spelling of arse.

      --
      Don't be apathetic. Procrastinate!
    4. Re: Put in context by martin-boundary · · Score: 1

      +1 for dissing the British on behalf of all the French slashdotters in the thread.

    5. Re:Put in context by Anonymous Coward · · Score: 0

      What's more, he has a Master's degree with honors in Computer Science, also from Cambridge (a course that is heavily focused on numerical analysis).

      CAPTCHA: EXTRAS

  6. Re:It may have a .cpp extension but it's all C cod by AuMatar · · Score: 4, Informative

    Its also all legal C++. Just because it doesn't use the advanced features doesn't mean it isn't C++. I'd argue that for something this simple its even better code this way.

    --
    I still have more fans than freaks. WTF is wrong with you people?
  7. The actual code by Anonymous Coward · · Score: 5, Informative

    How's about including a link to the actual code?

    Here you go:

    https://drive.google.com/folde...

    OR:

    https://github.com/Doppp/LHL-S...

    1. Re:The actual code by daniel23 · · Score: 0

      +1 informative

      --
      605413? Yes, it's a prime.
    2. Re:The actual code by hcs_$reboot · · Score: 1

      The guy is probably proud of his prog, that's why he published it. Indeed, that's more a C approach than a C++, but anyway for solving a sudoku there is no need to put in place a lot of complex data structures.
      What I like in this prog is that he optimizes the process by simply considering that since any 1-9 digit can only be once in each column, each row, and each of the nine 3×3 sub-grids, he uses a 10 bits int and associate 2^i with a digit (instead of an array, or worse checking all digits each time). Then 'Place()' recursively tries only possible combinations which converges quickly to a solution.
      Good prog. I wish all political figures would be able to show such an artwork!

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    3. Re:The actual code by Anonymous Coward · · Score: 0

      Here are my review comments for Sudoku2.cpp as it appears in github commit dace346 ("PM Lee's Sudoku Solver").

      Major review comments:

      (1) There's a buffer overflow on line 154 when S == 81.
      Suggestion: Move the if-statement on lines 157-160 above lines 154 and 155.
      Extended suggestion / minor comment: consider guarding all array accesses with function calls that do strict bounds checking.

      (2) Uses scanf("%s", ...) on line 83.
      Suggestion: Use fgets() and check return value, or make a loop with int ch = fgetc() and check ch != EOF.

      Minor review comments:

      (1) The indentation in this file is fairly consistent, but it's not perfectly consistent.
      Suggestion: Use an indentation tool.

      (2) There's a compile warning: Unused local variable j on line 98.
      The file is not 100% ANSI C compliant, so there's no reason to declare variables at the top of the functions.
      Suggestion: Move all function variable declarations to the point of first assignment.

      (3) It's not immediately obvious that line 144 always executes at least once, and therefore S2 is always defined on line 148.
      Suggestion: This is one of the rare cases where a comment would actually be helpful. Alternately, just assign S2 = S on line 131.

      Nitpick review comments:

      (1) [minor nitpick] The code would be more legible and maintainable if it used macros or functions to encapsulate the bit-twiddling.
      Suggestion: Define GetLowestBit(n) and use it instead of using n & -n in several places. Also, BitCount = GetBitCount(Possibles) would be better than doing the following in the middle of another loop:

      136: BitCount = 0;
      137: while (Possibles) {
      138: Possibles &= ~(Possibles & -Possibles);
      139: BitCount++;
      140: }

      (2) [minor nitpick] The tables InBlock[], InRow[], and InCol[] seem fairly pointless.
      Suggestion: Until profiling determines that it's a performance problem, I'd suggest removing the tables and just using macros or functions to decode the Square value (i.e. 0..80) into a block #, row #, or column #.

      (3) [very minor nitpick] Most C and C++ coding conventions eschew UpperCamelCase names for variables and functions. Constants are usually ALL_CAPS_UNDERSCORE, and usually only class names are UpperCamelCase.
      Suggestion: This looks more like C than C++, so I'd recommend using lowercase_underscore and renaming the file extension to ".c".

  8. 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

    1. Re:Free Amos Yee by Anonymous Coward · · Score: 0

      Amos Yee may be a teenager but he did post a YouTube video claiming that Jesus was a bad person. Such things are not allowed in Singapore.

  9. The PM writes good code by sk999 · · Score: 1

    I was able to compile it with both gcc and g++, even though it seems to have been written for a Windoze system. So yes, it is legal as both C and C++ code.

    No idea how to run it. Was expecting "You are standing in an open field west of a white house, with a boarded front door. There is a small mailbox here." Instead, all you get is "Row[1] :"

    1. Re:The PM writes good code by Anonymous Coward · · Score: 0

      Wow, really? Running arbitrary code are you? It's open source so it must be secure!

    2. Re:The PM writes good code by Anonymous Coward · · Score: 0

      It's only 219 lines long. Yeesh!

    3. Re:The PM writes good code by Anonymous Coward · · Score: 1

      Did you audit every line in your browser and all the libraries it uses and everything that was used to compile them and the compiler and the things that compiled the compiler and the hardware that ran it all? And that's for starters. You also need to check your computer display. Make sure your eyes haven't been replaced with life-like duplicates that can change what you see. Step outside our reality for a moment and make sure there's nothing messing with your perceptions.

      Or you could read his code. It's only 219 lines and there's no complex code in it.

    4. Re:The PM writes good code by Anonymous Coward · · Score: 2, Funny

      You never heard of the Obfuscated_C_Code_Contest. Who knows what this "Sudoku Solver Code" actually does? It could be a Trojan horse to steal American freedoms.

    5. Re:The PM writes good code by fisted · · Score: 1

      I was able to compile it with both gcc and g++ [...] [s]o yes, it is legal as both C and C++ code.

      Hahaha. You're so mistaken, it's not even funny anymore. (No, not even with -ansi -pedantic). The language that gcc accepts is a twisted superset of C, so using gcc to evaluate whether it's correct C code is completely meaningless.

    6. Re:The PM writes good code by Anonymous Coward · · Score: 0

      Those code snippets made my day. Thanks!

    7. Re:The PM writes good code by Anonymous Coward · · Score: 0

      American freedoms? Which remaining ones?

    8. Re:The PM writes good code by Anonymous Coward · · Score: 0

      No idea how to run it. ... all you get is "Row[1] :"

      Try this:

      $ echo -en "5...7....\n6..195...\n.98....6.\n8...6...3\n4..8.3..1\n7...2...6\n.6....28.\n...419..5\n....8..79\n" | ./a.out

      Credit where credit is due: That sudoku puzzle instance came from here, which was linked elsewhere in this thread by UnknownSoldier.

  10. Not that big of a deal... by Nutria · · Score: 3, Funny

    after all our President is a "coder" too!!! :eyeroll:

    --
    "I don't know, therefore Aliens" Wafflebox1
    1. Re:Not that big of a deal... by Bite+The+Pillow · · Score: 0

      The comparison is not remotely appropriate. You're not helping, and you should shut the hell up until you have something to contribute.

      "Our President" did little in the way of programming, and that is obvious. I haven't read the code, and now I don't even care, because you sound like a retarded fart.

      I'd like to promise to come back when you have a point, but that's like promising to give birth to a Martian.

    2. Re:Not that big of a deal... by Anonymous Coward · · Score: 0

      God you're mad. You must enjoy it.

    3. Re:Not that big of a deal... by aNonnyMouseCowered · · Score: 1

      Somebody's sense of humor went out the window.

    4. Re:Not that big of a deal... by Anonymous Coward · · Score: 0

      Knock it all you like, but apparently after all this time he's the first to bother reaching down to fondle us data plumbers. I respect that.
      http://techcrunch.com/2014/12/...

    5. Re:Not that big of a deal... by tlhIngan · · Score: 1

      I don't know.

      The code resembles something you expect from a first-year programming student - there's an input buffer overflow bug waiting to happen, the array size is odd (80 byte array? why? scanf() is still called without a field length specifier, and you only use 9 of those 80 bytes in a normal case).

      Perhaps it was written by him in his spare time. Or maybe it was like Obama where the base of the code was already provided and he needed to fill in a few things.

      Plus the general lack of commenting, explanation of the general data structures used, or algorithms. Maybe even ding points on practically everything being a global variable.

      Either he was learning to program, or someone basically told him what to do which explains the lack of error checking, the lack of comments, and the use of globals and he was a coder-monkey and not someone who develops software who took a set of requirements and created something from scratch.

      So, props for the effort, but is it really original work, or was there someone else at the keyboard helping him along?

    6. Re:Not that big of a deal... by gnasher719 · · Score: 4, Insightful

      The code resembles something you expect from a first-year programming student - there's an input buffer overflow bug waiting to happen, the array size is odd (80 byte array? why? scanf() is still called without a field length specifier, and you only use 9 of those 80 bytes in a normal case).

      You seem to be very optimistic in your views of first year programming students.

      Here's what I see: Many years ago, I had a lovely job helping to teach people to program, and I had to review their homework. There were some whose thought processes were all over the place. There was one guy who managed to write the most convoluted code that always worked perfectly well, but I would never have hired him because reviewing it was just too painful. And there was one student who wrote code that I could scan in half a minute and see that it was correct and worked. And that's what this guy's code looks like.

      "Perhaps it was written by him in his spare time". OF COURSE it was written in his spare time. His a prime minister, he doesn't write code on the job. What comments do you want? The code is simple and obvious. What data structures to explain? If you are too stupid to understand them immediately, then you shouldn't be programming. What lack of error checking? What scenario do you suggest where error checking would help?

      Your last sentence is a totally unfounded, vicious attack on the intellectual honesty of the man. It's disgusting. Unless you have any evidence for it, you should apologise.

    7. Re:Not that big of a deal... by tlhIngan · · Score: 1

      "Perhaps it was written by him in his spare time". OF COURSE it was written in his spare time. His a prime minister, he doesn't write code on the job. What comments do you want? The code is simple and obvious. What data structures to explain? If you are too stupid to understand them immediately, then you shouldn't be programming. What lack of error checking? What scenario do you suggest where error checking would help?

      Easy. What does (x & -x) compute, off the top of your head?

      There's so much bit-twiddling there that it's confusing and does boggle the mind. It's clever, yes, but guess what? Clever sucks. It's the code you get from prima donnas who don't expect to maintain it. Heck, someone posted a link to bit twiddling hacks on a Stanford server - it's a lot of elaborate code that's non-obvious (and even that hack isn't actually in the list, interestingly).

      And yes, error checking. Sure it's a simple app that doesn't need error checking, but it's useful to have common error checks put in - I mean an 80 char buffer for a 9 char string is not an error prevention. Using scanf() with a field width specifier is dangerous - you might as well just use gets() and be done with it - you get the same result. And we know WHY you don't use gets().

      You seem extraordinarily proud that he might code something up like this. Perhaps. All I say is that perhaps it isn't 100% original code, he didn't sit down one day and say "I can't solve this Sudoku, so I'll write my own solver" and crank that out. It almost seems like someone provided basically everything and his "contribution" is he typed it in.

      There are enough fancy tricks in there coupled with a lot of interesting issues that I would call it as perhaps a bit more effort than what Obama did, but not by much.

      And comments? Yeah, they're important, especially assuming it was done in his spare time. I mean, if he's doing it on and off, I expect him to forget. Anyone who maintains software knows after a month, the code you wrote might as well be written by someone else.

      Yes, it's possible it's 100% original code that he cleverly wrote a few years ago, in which case, yes I apologize. But it reeks of a lot of things that seem far outside the realm of common domain knowledge amongst developers (nevermind high-ranking government officials) that either he had a lot of help, or someone wrote 99% of the code, and he finished it off, kinda-sorta like Obama's JavaScript thing. (And given it IS Singapore, I expect the original developer to keep silent on the matter for many reasons).

    8. Re:Not that big of a deal... by Anonymous Coward · · Score: 0

      rofl who peed in to your cereal?

  11. Oh yeah? by Tablizer · · Score: 1

    Well, we have an ex-Prime-Minister who paints puppies, goats, and feet sticking out of bath-tubs!

    1. Re:Oh yeah? by I'm+New+Around+Here · · Score: 1

      What does he do with the rest of the dead body, that is in the bathtub?

      --
      If you think I voted for Trump because of this post, you're wrong. I voted for Dr. Jill Stein of the Green Party. Again.
    2. Re:Oh yeah? by lgw · · Score: 1

      Feeds it to the goats and puppies, obviously.

      --
      Socialism: a lie told by totalitarians and believed by fools.
  12. Impressive, but.... by Anonymous Coward · · Score: 1

    can he eat a raw onion?

    1. Re:Impressive, but.... by Anonymous Coward · · Score: 1

      Can he pull little girls hair?

    2. Re:Impressive, but.... by Anonymous Coward · · Score: 0

      Can he skol (how do you really spell that word, skul? skull?...anyway) a schooner?

    3. Re:Impressive, but.... by james_gnz · · Score: 1

      Can he pull little girls hair?

      That's not fair... She was 26, and he thought it was consentual.
      John Key: Ponytail pull not sexist

  13. Your move by ZeroInt · · Score: 0

    Seems he's into making calculated moves.

  14. That's good code by Anonymous Coward · · Score: 0

    This strikes me as being some quite good code and easily readable.

    Kudos, Mr. PM!

  15. Well... by EmeraldBot · · Score: 3, Informative

    While not utilizing any of c++'s features, it is still valid c++. I think he might call it this because he may usually program in c++, but maybe just for this one project he did it in c, and since it's still legal c++ he finds it easier to just label it as c++. I actually quite like it - could use a bit more commenting, but overall very clean and readable. Should compile with a decent c or c++compiler...

    --
    "Set a man a fire, he'll be warm for the rest of the night. Set a man afire, he'll be warm for the rest of his life."
    1. Re:Well... by RedHackTea · · Score: 1

      Yes, technically it compiles with both g++ and gcc for me. If it weren't for using stdio, I'd say that it's more C++ style (not all C++ programs need classes) because of no (void) for functions and main is declared at the bottom (for C++, functions must be declared before use, so it's common to see main at bottom for quick codez like this). Let's just agree that it's C and C++ having sex and call it a day :) My real gripe is that he compiled a .EXE and is clearly using Windows! For shame... for shame... got to convert this politician to Linux, but I guess I'll forgive him this one time.

      --
      The G
  16. 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
    1. Re:From his Facebook post on his Sudoku solver by UnknownSoldier · · Score: 2, Informative

      That's common knowledge.

      Bit Twiddling Hacks

    2. Re:From his Facebook post on his Sudoku solver by Anonymous Coward · · Score: 5, Insightful

      Not among prime ministers

    3. Re:From his Facebook post on his Sudoku solver by narcc · · Score: 1

      Well, it was common knowledge.

      Kids these days...

    4. Re:From his Facebook post on his Sudoku solver by Anonymous Coward · · Score: 2, Funny

      I have been around for a long time and no well adjusted kid has ever known what a binary integer was let alone a trick that utilizes it to determine the largest power of two that divides it.

    5. Re:From his Facebook post on his Sudoku solver by swillden · · Score: 1

      That's common knowledge.

      Bit Twiddling Hacks

      Not, too common, apparently, since this particular hack isn't in that list. It wasn't too hard to work out what it does (find the largest power of 2 that divides x or, equivalently, find the value of the lowest bit that is set) but it didn't make the Hacks list, and I don't think that's because it's too obvious.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    6. Re:From his Facebook post on his Sudoku solver by Anonymous Coward · · Score: 1

      Actually, it was buried as a lemma for one of the hacks:

      Count the consecutive zero bits (trailing) on the right with multiply and lookup

      unsigned int v; // find the number of trailing zeros in 32-bit v
      int r; // result goes here
      static const int MultiplyDeBruijnBitPosition[32] =
      {
          0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
          31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
      };
      r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];

      Converting bit vectors to indices of set bits is an example use for this. It requires one more operation than the earlier one involving modulus division, but the multiply may be faster. The expression (v & -v) extracts the least significant 1 bit from v. The constant 0x077CB531UL is a de Bruijn sequence, which produces a unique pattern of bits into the high 5 bits for each possible bit position that it is multiplied against. When there are no bits set, it returns 0. More information can be found by reading the paper Using de Bruijn Sequences to Index 1 in a Computer Word by Charles E. Leiserson, Harald Prokof, and Keith H. Randall.

      Emphasis added by me.

    7. Re:From his Facebook post on his Sudoku solver by swillden · · Score: 1

      Thanks. I missed that.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    8. Re:From his Facebook post on his Sudoku solver by balbus000 · · Score: 1

      Yes, because usually prime ministers don't have any use for division.

  17. He didn't check online?? by UnknownSoldier · · Score: 1

    C version, 67 lines of code ...

    http://rosettacode.org/wiki/Su...

    1. Re:He didn't check online?? by Anonymous Coward · · Score: 0

      You didnt check online? UnknownSoldier username already taken.

    2. Re:He didn't check online?? by UnknownSoldier · · Score: 1

      Quit trolling.

      Names aren't unique even if some people like to believe in Imaginary Property.

  18. Now ask ourselves this question: by Anonymous Coward · · Score: 0

    Is a politician actually doing it?

    How many of our congress critters know how to code?
     
    ... other than the MS-BASIC goto statements, that is ...

    1. Re:Now ask ourselves this question: by Anonymous Coward · · Score: 1

      hell, the press went out of their way to sabotage the last presidential candidate who knew any language other then English. My experience is that Mandarin is a lot harder to learn than C/C++, but, well, when we mock the educated because they're not on our team ...

    2. Re:Now ask ourselves this question: by randalware · · Score: 0

      Obama typed in a bit of (simple?) javascript and then the press bragged that he was the first US President to code !

      Surely some President before ran a spreadsheet or did a search & replace in a word processor.

      A line of Javascript, whoopy do, but an designing & programming an entire program in C++, that's computer coding !

      --
      This is my opinion based on what little I know and understand of the rumors and lies Thanks, Randal
    3. Re:Now ask ourselves this question: by Coren22 · · Score: 1

      He forgot to capitalize the H in Hell, but than was correct in usage. Mandarin compared to C/C++ is not temporal which is what then is used for.

      --
      APK likes to ask for responses to the same things over and over. Maybe he just likes the responses?
  19. Stupid sudoku solver? by Taco+Cowboy · · Score: 4, Insightful

    It might be a 'stupid sudoku solver', like you say, but at least, that is a program that does something, rather than the congress critters who do nothing but producing massive amount of HOT AIR

    --
    Muchas Gracias, Señor Edward Snowden !
    1. Re: Stupid sudoku solver? by Anonymous Coward · · Score: 0

      Few words on his father

      https://youtu.be/6TZPdM3xn24

    2. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 5, Funny

      It might be a 'stupid sudoku solver', like you say, but at least, that is a program that does something, rather than the congress critters who do nothing but producing massive amount of HOT AIR

      Imagine that you are a zombie apocalypse survivor, naked and wet, in a freezing winter Alaskan night, tired to death, and you can share a tent either with this Singapore's prime minister who wants you to stay awake with him and solve stupid Sudoku puzzles or with one of those "congress critters who do nothing but producing massive amount of HOT AIR" - who would be you choice?

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    3. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 1

      As far as doing things, not only the instructions in the binary but the source code itself did things and keeps doing things, and compared to a "stupid sudoku solver" they probably have more value to humanity or at least a subset of humanity. One, it scratched an itch that the author had. Either he needed it for the instructions it would issue, or he wanted to write it as some form of exercise, either mental or practical. Two, he's put the code out there for others to learn from. Granted, you (probably) couldn't use it for a thesis or dissertation, but it does display a (different probably) way of solving a given program that what you initially thought. Heck, in a class I taught this term of 20 students working individually there were 5 or 6 different ways of solving fizzbuzz.

      The actual styles of writing code, working with code written by a programmer who doesn't have the same native (spoken) language as you, etc. All very useful skills to have, and by putting his code out there he's giving others a chance to learn from it.

    4. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 0

      You forgot to mention that you are Greek and that you hate Europe and Muslims.

      You are slipping.

      Thanks dude (who ever you are, i guess some of the usual /. libtard who have a problem with anyone describing some things the way they are...): I am Greek and i hate Muslims (but you are mistaken about the "hate Europe" part, since the most important reason i hate Muslims is because i LOVE Europe).

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    5. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      I'm going with Sudoku puzzles.

    6. Re:Stupid sudoku solver? by narcc · · Score: 0

      Do you hate any other people group? Turks? Black people? Jews?

    7. Re:Stupid sudoku solver? by Pseudonym · · Score: 1

      Why is the Prime Minister of Singapore in Alaska after the zombie apocalypse?

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    8. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 0

      Do you hate any other people group? Turks? Black people? Jews?

      • Turks: i am Greek... do you even have to ask?!
      • Black people: no - NIGGERS: yes
      • (biologically) Jews: no - (culturally) Jews: it depends, Jews are like Greeks... very complicated.

      What about you my fellow Slashdoter?

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    9. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      Why is the Prime Minister of Singapore in Alaska after the zombie apocalypse?

      He arrived there just before this zombie apocalypse mayhem started, because of this stupid "sudoku solver code" conference that wanted him as a speaker... you know "Mister Prime Minister of Singapore, a coder, a sudoku lover, let us give him a warm welcome for being with us in freezing Alaska" - can you believe that?

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    10. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      The more Greeks I know, the more I like my Turkish friends.

      It's curious why you folks believe you have any relationship, other than geographic, to ancient Greece. You're just loser Slavs. Pay your taxes, go back to work and shut the fuck up.

    11. Re:Stupid sudoku solver? by Pseudonym · · Score: 1

      I guess that's just as believable as the rest of the scenario.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    12. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      but you are mistaken about the "hate Europe" part, since the most important reason i hate Muslims is because i LOVE Europe

      The feeling is unlikely to be mutual.

    13. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      The more Greeks I know, the more I like my Turkish friends.

      It's curious why you folks believe you have any relationship, other than geographic, to ancient Greece. You're just loser Slavs. Pay your taxes, go back to work and shut the fuck up.

      I bet you're white German female.

    14. Re:Stupid sudoku solver? by itzly · · Score: 1

      Imagine that you are a zombie apocalypse survivor

      I've seen walking dead, and if that show is any guide for zombie behaviour and properties, it would seem to me that the military would have no problem taking them all out in a few days, and restore order.

    15. Re:Stupid sudoku solver? by Hognoxious · · Score: 0

      Maybe the Germans, for lending them a load of money which they pissed up the wall instead of using it to drag their country into the 20th century.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    16. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      Military members always become zombies first.

    17. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      I'd take the Singaporean politiciana d put him on tour with his Soduku code, selling out all the big stadiums, and as his manager act as gatekeeper for all his groupies... and stay warm in Alaska nights with hot pussy from a nearby animal shelter.

    18. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      So your congressman does HVAC?

    19. Re:Stupid sudoku solver? by Coren22 · · Score: 1

      The Germans taught that to the Greeks when they forcefully took a loan from a conquered Greece during WW2, then spent the money and refused to repay when the war was over.

      --
      APK likes to ask for responses to the same things over and over. Maybe he just likes the responses?
    20. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      Imagine that you are a zombie apocalypse survivor

      I've seen walking dead, and if that show is any guide for zombie behaviour and properties, it would seem to me that the military would have no problem taking them all out in a few days, and restore order.

      As a (conscript, because all male Greeks serve in our military) ex-SF i trust the military (any military to be honest, USA's SURELY included, since i trained with them) for... almost everything - as most Greeks do.

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    21. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      I guess that's just as believable as the rest of the scenario.

      O.K., the "zombie apocalypse" thing is not so believable... but some other parts of my scenario come from personal experience! Don't ask... conscript military service!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    22. Re:Stupid sudoku solver? by cellocgw · · Score: 1

      hmmm.... solving fizzbuzz....
      ( code is in the R language BTW)

      fbfun1 <- function(xfoo) {
      xfoo<-1:xfoo
      fbfoo <- 1+(!as.logical(mod(xfoo,3)))*(as.logical(mod(xfoo,5))) + 2*(as.logical(mod(xfoo,3)))*(!as.logical(mod(xfoo,5)))+3*(!as.logical(mod(xfoo,3)))*(!as.logical(mod(xfoo,5)))
       
      fbbar <- unlist(lapply(fbfoo, function(x) switch(x,0,'fizz','buzz','fizzbuzz')))
      return(fbbar)
      }
       
      fbfun3 <- function(xfoo) {
      xfoo<-1:xfoo
      fbfoo <- 1+(!as.logical(mod(xfoo,3)))*(as.logical(mod(xfoo,5))) + 2*(as.logical(mod(xfoo,3)))*(!as.logical(mod(xfoo,5)))+3*(!as.logical(mod(xfoo,3)))*(!as.logical(mod(xfoo,5)))
      fbtab<-cbind(1:4,c('','fizz','buzz','fizzbuzz'))
      fbbar <- fbtab[fbfoo,2]
      return(fbbar)
      }
       
      fbfun4 <- function(xfoo) {
      fiz<- rep(c('','','fizz'),length.out=xfoo)
      buz<-rep(c('','','','','buzz'),length.out=xfoo)
      fbbar <- unlist(lapply(1:xfoo, function(j)paste(fiz[j],buz[j]) ) )
      return(fbbar)
      }
       
      # or completely sleazy:
      fbfun5 <- function(xfoo) {
      fiz<- rep(c('','','fizz','','buzz','fizz','','','fizz','buzz','','fizz','','','fizzbuzz'),length.out=xfoo)
      return(fiz)
      }

      --
      https://app.box.com/WitthoftResume Code: https://github.com/cellocgw
    23. Re:Stupid sudoku solver? by Rakarra · · Score: 1

      but you are mistaken about the "hate Europe" part, since the most important reason i hate Muslims is because i LOVE Europe

      The feeling is unlikely to be mutual.

      Depends on the section of Europe. France has long been leery of Muslims, and the UK is starting to move in that direction as well.

    24. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      Maybe the Germans, for lending them a load of money which they pissed up the wall instead of using it to drag their country into the 20th century.

      You could ask me directly fellow Slashdoter, i try to answer direct questions honestly. NO i don't hate Germans (and yes, they lend us a load of money which we pissed up the wall instead of using it to drag our country into the 21th century - if you visit Greece you would be convinced that we are not so retarded to be living in the 19th century).

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    25. Re:Stupid sudoku solver? by LordLimecat · · Score: 1

      Leave it to Slashdotters to denigrate our democratic representatives and idolize a glorified dictator.

      I hear Putin wrestles bears, clearly hes better for a country than our congress!

    26. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 2

      The Germans taught that to the Greeks when they forcefully took a loan from a conquered Greece during WW2, then spent the money and refused to repay when the war was over.

      Hmmm... i am surprised that you know that...

      Not that we fucking Greeks deserve any excuse for our other stupid behaviors, but yes, you are right, what you wrote is true (by the way: Hitler, until he was defeated, payed some of the money back!!! His successors in the goverment of the German (west, east, or unified now) state... no!)

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    27. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      but you are mistaken about the "hate Europe" part, since the most important reason i hate Muslims is because i LOVE Europe

      The feeling is unlikely to be mutual.

      Depends on the section of Europe. France has long been leery of Muslims, and the UK is starting to move in that direction as well.

      I just want to add that some Greeks were under the Muslim's rule until recently - we still have many Greeks alive that remember well what it means to be a Christian in a Muslim state. This is not an opinion (i expressed my opinion about Muslims in some other comment in this thread), it is just a fact. Also i would like to inform that i grow up in a place where the majority were Muslims!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    28. Re:Stupid sudoku solver? by Pseudonym · · Score: 1

      Awesome! So what is the PM of Singapore like?

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    29. Re:Stupid sudoku solver? by Hognoxious · · Score: 1

      21st. Kudos for spotting the gag, though.

      Still, having a tax authority runs at a loss is an, ummm, "impressive" feat. Of course its employees make quite a healthy profit...

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    30. Re:Stupid sudoku solver? by Anonymous Coward · · Score: 0

      He is a Golden Dawn supporter, and openly describes himself as Nazi:
      http://slashdot.org/comments.p...

      So the list of hated things is likely very long indeed.

    31. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      21st

      Thanks, you are right (i am struggling with my English - see my signature).

      Kudos for spotting the gag, though.

      Kudos for being a grammar NaZi... the world always needs more!

      Still, having a tax authority runs at a loss is an, ummm, "impressive" feat.

      In the last fiscal year we had a surplus - that is impressive for Greece!

      Of course its employees make quite a healthy profit...

      Bad old habits, acquired from almost 4 centuries of having the Ottoman filth in our proximity - as we say in Greece, a decade of occupation from NaZi Germany would have help us forget the Ottoman way of doing things.

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
    32. Re:Stupid sudoku solver? by antiperimetaparalogo · · Score: 1

      Awesome! So what is the PM of Singapore like?

      Ha! O.K., i am not gonna lie to you no more... i never met the guy! BUT: as a conscript, many times i had to share a tent with either a guy that wanted me to stay awake with him and play stupid games or some other who just wanted to sleeep! If a had an option, i choosed wise!

      --
      Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
  20. New competition by viperidaenz · · Score: 5, Funny

    There should be an international coding competition between heads of state.

    1. Re:New competition by paul5086 · · Score: 3, Funny

      Meanwhile, in New Zealand... http://static2.stuff.co.nz/125...

    2. Re:New competition by Anonymous Coward · · Score: 0

      There should be an international coding competition between heads of state.

      abbott would not fair well

    3. Re:New competition by Anonymous Coward · · Score: 0

      lol abbott!

    4. Re:New competition by viperidaenz · · Score: 1

      ... and a head of state cow milking competition...

    5. Re:New competition by NicBenjamin · · Score: 3, Insightful

      Would have to be Heads of Government. Lee's a Prime Minister, so he's not Head of State. Singapore's Head of State is Tony Tan.

      Under Singapore's Constitution President Tan has very few powers, but he still technically outranks the PM who has powers. It's similar to the system in Britain/Canada/etc. where the Queen's Head of State,* but the Prime Minister is the one who actually does everything interesting.

      And yes, this is a pet peeve of mine. I spent the week Netanyahu addressed Congress in constant nerd-rage because the entire US media kept calling him a "Head of State" when he isn't.

      *Altho many Canadians argue the Queen isn't their Head of State, her representative in Canada is (the Governor-General). The fact no Court's ruled on this definitively shows how important the title "Head of State" is in a Parliamentary system. Most legal scholars seem to think that the Queen is Head of State, but there is a minority that disagrees and their Constitution is not helpful on this question. But mostly nobody cares.

    6. Re:New competition by blackpaw · · Score: 1

      At least he's doing something practical, unlike the idiot we have here in Oz.

          http://www.smh.com.au/content/...

    7. Re:New competition by Trailer+Trash · · Score: 1

      *Altho many Canadians argue the Queen isn't their Head of State, her representative in Canada is (the Governor-General). The fact no Court's ruled on this definitively shows how important the title "Head of State" is in a Parliamentary system. Most legal scholars seem to think that the Queen is Head of State, but there is a minority that disagrees and their Constitution is not helpful on this question. But mostly nobody cares.

      Given that she owns the entire country it's kind of a moot point. If they piss her off she'll just kick them out.

    8. Re:New competition by swillden · · Score: 1

      *Altho many Canadians argue the Queen isn't their Head of State, her representative in Canada is (the Governor-General). The fact no Court's ruled on this definitively shows how important the title "Head of State" is in a Parliamentary system. Most legal scholars seem to think that the Queen is Head of State, but there is a minority that disagrees and their Constitution is not helpful on this question. But mostly nobody cares.

      Given that she owns the entire country it's kind of a moot point. If they piss her off she'll just kick them out.

      Heh. I suspect that if she tried the outcome would not be that they would leave.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  21. Not C++ Code Because its Understandable by Anonymous Coward · · Score: 2, Funny

    Its not C++ code because the code is understandable. For example:

    1. he does not use templates, restricting himself to solving only over the integer space. what about a sudoku puzzle of strings? basics, people, this is basic stuff.
    2. he is using raw loops. what about range based bi-directional iterators using lambdas? scott meyers is going to throw a tantrum.
    3. free functions without namespaces or a class even. more appropriate would have been korea::south::presidental_code::sudoku_solver.
    4. better yet, abstract it all away in a templated class, be sure to overload all the operators, implement copy-on-write and do the non-public stuff in a pimpl that relies some weird over-engineered templated-to-death library from boost. and make that shit virtual.
    5. and be sure to do all of the above multi-threaded, since you need to scale to multiple cores these days.

    1. Re:Not C++ Code Because its Understandable by Anonymous Coward · · Score: 0

      It's not C++ because he doesn't use a single C++ construction. You don't want to use the iostream library for input/output? Totally understandable, but then, don't include "stdio.h", you should include <cstdio>.

      If it compiles with a C89 compiler, it's nowhere near C++.

  22. that guy is for real by joss · · Score: 2

    He was Senior Wrangler while at Cambridge. Plus, his son is one of the most productive scala programmers in the world despite only doing it in his spare time. These guys ain't dumb.

    --
    http://rareformnewmedia.com/
  23. Singapore... by Mirar · · Score: 1

    I really, really like Singapore. They are doing pretty much everything right, including having the smartest and most educated leaders in the world, by far.

    I am a bit confused by their status as non-democracy though.

    1. Re:Singapore... by Anonymous Coward · · Score: 1

      What does that tell you about democracy?

      The problem with enlightened despots is the fact that there's so few of them.

    2. Re:Singapore... by Anonymous Coward · · Score: 0

      What does that tell you about democracy?

      It's a god that failed

    3. Re:Singapore... by Mirar · · Score: 1

      I'd guess democracy works as long as education levels are high enough and the democracy isn't diluted.

      Dictatorship seems to work as well as long as education levels are high enough and corruption is avoided.

      It's a good philosophical discussion where the limit is of when dictatorships are more democratic than democracies. :)

  24. Seriously? by Anonymous Coward · · Score: 0

    That's not C++!!!

    That is NOT C++, it is C!!!

  25. John Key, can you do that? by JeremyWH · · Score: 1

    NO he can't.

  26. Very C like. by gatkinso · · Score: 2

    Not a great example of modern C++.

    --
    I am very small, utmostly microscopic.
    1. Re:Very C like. by abies · · Score: 1

      Modern C++ would involve solving sudoku on compile time with template metaprogramming. All the stuff with classes, virtual functions, STL etc is so 90ties...

  27. Over use of back-tracking by Frans+Faase · · Score: 1

    Most Sudoku's can be solved without back-tracking. There is a rather trivial mapping of Sudoku's to Exact Cover problems (see: Hardest Sudoku). Good solvers, only use back-tracking when needed, and try to apply logic reduction first. When there is a column were A implies B, all rows in which B is true and A false can be eliminated, because a selection of such a row will leave the A column empty. Most of the published Sudoku's can be solved with using this simple reduction rule.

    1. Re:Over use of back-tracking by Anonymous Coward · · Score: 0

      Most Sudoku's can be solved without back-tracking.

      Most, but not all.

      Solvers that don't back-track are worthless.

    2. Re:Over use of back-tracking by Frans+Faase · · Score: 1

      I wasn't saying that all Sudoku's can be solved without back-tracking, I was just commenting about that its bad design to only guessing and back-tracking while there are other methods for finding a solution much faster. It is nice to note some improvements that could be made to the program, but missing the fact that a very poor performing algorithm is being used, is much worse. It is like correcting spelling mistakes in a mathematical proof while missing the fact that it has a logical error.

    3. Re:Over use of back-tracking by Anonymous Coward · · Score: 0

      The PM's solver only takes 12ms (including IO) on the puzzle acknowledged as the world's hardest Sudoku, so there's really not any need for it to run faster unless he thinks it needs to run faster.

      Review comments are there to help the reviewee learn to become a better programmer. If performance doesn't matter, then there's no need to mention it in review.

    4. Re:Over use of back-tracking by Frans+Faase · · Score: 1

      It seems that if there is one thing our intuirion is often wrong about, then it is on the issue of performance. It might well be that in the case of sudoku's a back-tracking algorithm might be faster than any smarter algorithm.

  28. Re:It may have a .cpp extension but it's all C cod by fisted · · Score: 1

    That's right, but that doesn't change that it's all C code as well. Labeling it C++ code is quite a stretch IMO.

  29. I'm impressed by Mr+Z · · Score: 3, Insightful

    There's no shortage of people ragging on the code. "It's not C++ enough to be called C++," "there's not enough comments", "it uses C stdio.h", etc. Get over it.

    This looks like the sort of program I might dash out over an afternoon (maybe two) to satisfy some intellectual curiosity. Programming as play. This isn't production code, it's fun code, written to satisfy oneself.

    Is it perfect? WHO CARES! That's not important. That misses the point. If you doodle in your notepad and it brings you a smile, does anyone care it's not as good as the Mona Lisa? You sure as heck don't. And that's what this code is. A doodle. It just happens to be in simple, straightforward procedural C/C++ code.

    I personally think playing with programming is important. Sure, you'll write a lot of dreck. But, you'll also learn a lot. You learn real lessons when you do write dodgy code, and the dodgy code actually bites you. You also can try new things fearlessly. After all, you're programming a toy for oneself, and you're under no deadline pressure. There's no spec you have to fulfill. You can experiment and enjoy it.

    Programming as play still helps build your programming reflexes. If and when you do sit down to write professional grade software, all of that play will make the basic work of programming natural. Rather than focusing your energy on the basic details of programming, you can instead focus your energy designing maintainable code that meets the business requirements and documenting that design. Writing the code just flows naturally.

    So, yeah, I'm impressed. This Sudoku solver brought a smile to my face. It's incredibly cool that the prime minister shared a code doodle with us.

  30. Sure, but it only does 9x9s by Anonymous Coward · · Score: 0

    I made mine general to all dimensions of Sudoku, and arbitrary rules (allows Xdokus, and 16x16s etc.).

    Naturally, I had to include the binary sudoku as well https://xkcd.com/74/

  31. Asserting implementation-defined behavior by tepples · · Score: 1

    You're not making it better by actively promoting horrible, non-portable, implementation-dependent and error-prone coding practices.

    What's wrong with making assumptions about implementation-defined behaviors and using static assertions to verify them? For example, would it be poor form to assume (and assert) things like 8-bit bytes or that the character set is ASCII, and if so, why?

    extern char assert_8bitbytes[(
        CHAR_BIT == 8 && sizeof(uint32_t) == 4
    ) ? 1 : -1];
    extern char assert_ascii[(
        'A' == 0x41 && 's' == 0x73
    ) ? 1 : -1];

    This way, the compiler will fail and kick out a diagnostic if the environment doesn't match the assumptions.

    1. Re:Asserting implementation-defined behavior by fisted · · Score: 1

      You're not making it better by actively promoting horrible, non-portable, implementation-dependent and error-prone coding practices.

      What's wrong with [depending on] implementation-defined behaviors and using static assertions to verify them?

      (Ignoring that that's quite a stretch from what I said, and deliberately ignoring the 'error-prone' part), if you do verify your assumptions about the implementations then of course it's less horrible. However, you do pay the price in losing portability, so if it isn't for a particular good reason, not unnecessarily relying on implementation-defined or unspecified behaviour is preferrable.

      For example, would it be poor form to assume (and assert) things like 8-bit bytes or that the character set is ASCII, and if so, why?

      extern char assert_8bitbytes[( CHAR_BIT == 8 && sizeof(uint32_t) == 4 ) ? 1 : -1]; extern char assert_ascii[( 'A' == 0x41 && 's' == 0x73 ) ? 1 : -1];

      This way, the compiler will fail and kick out a diagnostic if the environment doesn't match the assumptions.

      That's quite a hack (but better than nothing, sure). If you had a hard requirement such as "has to be ASCII-based" or "char must be 8 bits wide", then I'd wonder where it comes from. I don't deny that there may be a few good reasons, but it turns out that often you could write code in a way that is agnostic of such details and hence portable.
      For instance, the ctype.h functions (isprint(), isalnum() and friends) can be used to implement encoding-independent text processing.
      For requiring char to be of some specific width, there's hardly a reason, unless you're improperly (de)serializing. The (mandatory as of C99) types (u)int_leastN_t come to mind, and for the rare cases where you actually need a fixed-width-no-padding type, there are the (optional but widely implemented) (u)intN_t types)

  32. Not very user friendly by aNonnyMouseCowered · · Score: 2

    No help file. WTF is this supposed to do? A bad example given our age of touch and click operating systems, even the most arcane GNU or BSD program is more comprehensible. Maybe it says a lot about the politics of his country, smart but not very user friendly.

    1. Re:Not very user friendly by Anonymous Coward · · Score: 0

      If you need a help file to understand it then the problem is on your end. I mean really, it is a small program that does one specific task and you have the code right there. It is hardly rocket science.

      It is a good example of not dumbing down and spoon-feeding idiots. What does that say about your country?

  33. Adonis v. Lee by MagnusE · · Score: 1

    Adonis Georgiadis, a major political figure of the former Greek government (New Democracy) cannot solve this equation: x/2=30/3 but this guy shares his C++ program. My respect. :) PS: Proof in these videos: https://www.youtube.com/watch?... and https://www.youtube.com/watch?...

    --
    Fortune Rota Volvitur
  34. Accessing the data being deserialized by tepples · · Score: 1

    If you had a hard requirement such as "has to be ASCII-based" or "char must be 8 bits wide", then I'd wonder where it comes from.

    The fact that Internet protocols use 8-bit bytes and either ASCII or its superset UTF-8.

    For requiring char to be of some specific width, there's hardly a reason, unless you're improperly (de)serializing.

    Last time I checked, the C standard offered no facility for networking, graphics, or even enumeration of the files in a directory. This means most nontrivial interactive programs will need to use POSIX or Windows functions, which are defined in the POSIX and Win32 specifications but are undefined behavior from the perspective of the C standard, in order to access the data that the program is (de)serializing in the first place. Or is there a portable way to do this that I'm somehow missing?

    1. Re:Accessing the data being deserialized by fisted · · Score: 1

      The fact that Internet protocols use 8-bit bytes and either ASCII or its superset UTF-8.

      Binary protocols are a bit more substantial an argument here than text protocols, in which the matter could (but in practice rarely isn't) be addressed at the presentation layer. Of course, the part which does the actual conversion between host and network character encoding cannot be agnostic of the latter since it needs a means to translate between corresponding characters of the involved, but it could still be written in portable, strictly conforming C.
      This could in theory be applied to binary protocols as well, but unlikely to be worth the hassle as binary protocols tend to carry a few implicit assumption about the involved systems. To some degree, (byte order, mainly), it is done, though.

      Last time I checked, the C standard offered no facility for networking, graphics, or even enumeration of the files in a directory. This means most nontrivial interactive programs will need to use POSIX or Windows functions, which are defined in the POSIX and Win32 specifications but are undefined behavior from the perspective of the C standard, in order to access the data that the program is (de)serializing in the first place. Or is there a portable way to do this that I'm somehow missing?

      Depends. Strictly conforming C programs can be rather useless, yes. (Can also be rather useful, though, as most of the common unix filters could actually be implemented that way).
      As for portability in the light of networking and graphics, yes, obviously once settling for some more specific standard to adhere to, like POSIX, you're not portable across all platforms that support C anymore. Whether or not that's acceptable depends on what the developer intends to do; personally i'm following the general rule "Strictly conforming where possible, POSIX where necessary", with hopefully somewhat of a clean cut between the respective parts of a project, and as a result i get software that works on all platforms relevant to me, and if necessary is rather easily ported to other platforms.

      BTW: It's mostly the implementation-defined and unspecified behaviour which standards like POSIX define. Defining undefined behaviour might also happen here and there, but that strikes me as less common

  35. Re:It may have a .cpp extension but it's all C cod by BadPirate · · Score: 1

    So following your argument you could say that it's actually Objective-C? You could put a .mm on there and it would still execute.

    --
    - Holy crap, I've got MOD points! Who thought that was a good idea.