Skip to main content
21 events
when toggle format what by license comment
Aug 13, 2011 at 1:37 history edited Harry K. CC BY-SA 3.0
added 159 characters in body
Aug 13, 2011 at 1:34 comment added Harry K. Thanks Joey, you made me a happy man again :) Btw, Pelles-C on the PC doesn't really like arbitrary arguments in main, actually it doesn't even compile them. I happily accept 1 char overhead in favor of portability :)
Aug 12, 2011 at 17:59 comment added Joey Adams I rolled back the answer. As for the discussion, it's only broken when a and b are unreasonably large, and the asker did not specify the range of integers that must be supported. Code Golf answers are usually not held to this high of a standard. Oh, and you can save one character by putting a,b in the parameter list of main :-)
Aug 12, 2011 at 17:59 history rollback Joey Adams
Rollback to Revision 1
Aug 12, 2011 at 17:14 comment added Matthew Read Delete it or revert it. As-is it's not an answer.
Aug 12, 2011 at 8:37 comment added Harry K. @dmckee: yes, I found it, but if it's not inappropriate for the post to stay like this, it contains some interesting commentary going on I think. Peter, we just have a different point of view, nevertheless the author changed the specs so golfing is not required any more, so full-blown programs can be presented now (which is not that interesting anymore, imho).
Aug 11, 2011 at 19:43 comment added Peter Taylor Surely handling overflow is the essence of the problem. Without that it's a "challenge" consisting of "Can you tell whether an int is negative without using < or >?"
Aug 11, 2011 at 17:53 comment added dmckee --- ex-moderator kitten Harry, you can delete the post on your own. See the "delete" option next to the "edit" button?
Aug 11, 2011 at 16:29 comment added Harry K. I got what Joey said, but accepting that as a flaw we can also accept no input overflow check as a flow. My point is that imho both of those are away from the very essence of the given problem. I could present a full blown program taking care of a hell lot of stuff, but I think this is not what code golfing is about. Handling overflows can be easily put as a separate problem by itself (especially in C).
Aug 11, 2011 at 16:01 comment added Peter Taylor I think you misunderstood Joey. He's clearly talking about arithmetic overflow caused by the subtraction being e.g. 0x80000000 - 1, not about input parsing.
Aug 11, 2011 at 15:34 comment added Harry K. @Peter Taylor: alas, the only way to control over/underflow in C is to read the numbers as strings and then convert them to integers with either one of the stro?() family of functions or a custom one. That's why you saw me reacting so strongly about that down-vote :)
Aug 11, 2011 at 15:01 comment added Peter Taylor Well, I think the spec is close enough now that I've posted a C# solution. Easily ported to C. Avoids underflow / overflow.
Aug 11, 2011 at 14:31 history edited Harry K. CC BY-SA 3.0
deleted 2 characters in body
Aug 11, 2011 at 14:18 history edited Harry K. CC BY-SA 3.0
added 107 characters in body
Aug 11, 2011 at 14:15 comment added Harry K. I hear you Peter, but I feel it's unfair to down-vote for a non-solvable side-effect, without providing an equal or better solution to the given problem. Anyway, this was supposed to be fun, but it's not... I'm withdrawing my code, waiting for your better solutions...
Aug 11, 2011 at 13:00 comment added Peter Taylor @Harry, surely the best approach is to wait until the question is properly specified? That's why I've asked for clarifications. (NB I haven't downvoted any of the answers, but I may come back later and downvote anything which fails the obvious test cases).
Aug 11, 2011 at 12:20 comment added Harry K. @joey: but then you rule out negative numbers both on the input and on the result, which someone could legitimately consider it to be a bigger flow than not checking for overflows. Plus, you don't solve the over/underflow problem either.
Aug 11, 2011 at 12:05 comment added Joey UB is a rather special case for C and derivates, but as long as your using signed ints and do that subtraction you have UB. Which means that there are inputs where your method isn't guaranteed to give the correct result. Just because over-/underflows are defined in other languages doesn't make it ok to rely on that in C, in my eyes. But agreed, the question is underspecified in any case. The easiest fix, conforming to the question would probably be to make a and b unsigned (where it is defined).
Aug 11, 2011 at 12:00 comment added Harry K. @joey: tsk, tsk... too picky! The problem doesn't talk about overflows/underflows and the author didn't answer to the relative question. If you have a better suggestion which checks input against the range INT_MIN to INT_MAX without using > or < I'd be happy to see it. Until then I consider your down-vote to be rather harsh! Keep also in mind that there will always be at least one number that overflows any of the built-in data types on input, no matter what data type you choose to represent a and b.
Aug 11, 2011 at 11:28 comment added Joey Undefined behavior if a-b overflows.
Aug 11, 2011 at 11:27 history answered Harry K. CC BY-SA 3.0