Page 2 of 3

Posted: Sat Feb 27, 2010 4:28 pm
by martin
That's exactly what I said, and not what Ace said...

Posted: Sat Feb 27, 2010 4:55 pm
by roflamingo
I used the right formula. Thanks to all 3 of ya :D

However the algorithm doesn't work 100% correctly...the land bulges in SA and Africa make it look like there are multiple oceans.

Posted: Sat Feb 27, 2010 8:32 pm
by martin
Use a flood fill algorithm:

1) Generate all points in the ocean and add them to a set
2) pick an arbitrary point (call it foo)
3) remove foo from the set
4) for each neighbour of foo, remove them from the set, and so on with each of their neighbours

If, once you run out of points (ie. all new points are either not in your territory, or are not land), you still have something in the set, then you have a disjoint ocean

Posted: Sun Feb 28, 2010 12:45 am
by xander
martin wrote:That's exactly what I said, and not what Ace said...

Ace left out the parentheses, but used space to make it clear what he was doing. You left out the subscripts. ;)

xander

Posted: Sun Feb 28, 2010 1:06 am
by martin
Ace left out parentheses, which makes what he said mathematically wrong, spaces aren't part of maths. I left out the subscripts because I'm a programmer and that means I can attach meaning to whatever arbitrary token I like.

Posted: Sun Feb 28, 2010 3:03 am
by xander
martin wrote:Ace left out parentheses, which makes what he said mathematically wrong, spaces aren't part of maths. I left out the subscripts because I'm a programmer and that means I can attach meaning to whatever arbitrary token I like.

You cannot simultaneously claim that something is mathematically incorrect, then claim that your abuse of notation is mathematically correct on the grounds that you are a programmer. The parentheses do help to clarify what is happening, but I hardly ever use them when actually writing out my mathematics. Instead, I use space, and the location of symbols, to create meaning. Neither of you was entirely correct---the correct formula is $(x_m,y_m) = \left({x_1+x_2\over 2},{y_1+y_2\over 2\right)$---but Ace's version was closer to being correct than yours. Those subscripts have meaning, and are important. :P

xander

Posted: Sun Feb 28, 2010 3:20 am
by Montyphy
You're all wrong. It should be:

Code: Select all

mx := (x1 + x2) * 0.5f;
my := (y1 + y2) * 0.5f;


:P

Posted: Sun Feb 28, 2010 3:20 pm
by martin
I can claim that xander, I just did.

Don't forget, we're talking Lua here, if someone were to use my formula in Lua, they'd get the right answer, if someone were to use Aces they'd get the wrong answer because the grammar doesn't attach any meaning to spaces.

Maybe it doesn't attach any meaning to spaces because there *is* no meaning to spaces

As an aside, although it's wrong to use spaces in programming (since they have no strict mathematical meaning in any (non esoteric) programming language that I know of), is it correct to use spaces in mathematical notation, and if so is that just an American thing? I have never seen any maths teacher, or computer science papers (some of which are quite maths heavy) using spaces to indicate operator ordering...

Posted: Sun Feb 28, 2010 3:57 pm
by Ace Rimmer
Hehe, I wasn't trying to be correct, technically. I figured you lot were smart enough to know what I was doing. xander got it anyway.

In fact, I thought about putting parenthesis in there a few times before this discussion started cause I knew somebody would point it out. :P

Posted: Sun Feb 28, 2010 4:05 pm
by shinygerbil
My maths teacher once told me it should really be BOMDAS, but that doesn't sound quite as snappy.

Edit: Wikipedia to the rescue. Either is correct.

Posted: Sun Feb 28, 2010 5:53 pm
by martin
shinygerbil wrote:My maths teacher once told me it should really be BOMDAS, but that doesn't sound quite as snappy.

Edit: Wikipedia to the rescue. Either is correct.


Link the bit which says either is correct?I'm interested because I have never seen spaces used like that in mathematical notation.

Also, important aside, they might be mathematically correct but only one will work properly in Lua

Posted: Sun Feb 28, 2010 11:21 pm
by xander
martin wrote:
shinygerbil wrote:My maths teacher once told me it should really be BOMDAS, but that doesn't sound quite as snappy.

Edit: Wikipedia to the rescue. Either is correct.


Link the bit which says either is correct?I'm interested because I have never seen spaces used like that in mathematical notation.

Also, important aside, they might be mathematically correct but only one will work properly in Lua

Again, the distribution of symbols on the page is important. Normally, you would write the "x1+x2" on the page, then put a line under it, then put the "2" under the line. There would be a clear division between the two symbols, using space and the location of symbols. Hence, Ace's version was perfectly clear (if not usable in code). Your version was a bit ambiguous, as "x" is a variable, not a constant. Moreover, it is even bad code, as I highly doubt that you would be using x in that situation (it is likely that "x" would already be used for something else). Thus, as I said above, neither of you is really right, but Ace was more right.

Let me put it this way: x1+x2 / 2 is perfectly clear. It is clear that x1+x2 is one unit, that 2 is another, and that x1+x2 is being divided by 2. x1+x2/2 is less clear. (x+x2)/2 is perhaps more clear, but treats x like a constant, which is contrary to convention. (x1+x2)/2 is more clear, and would actually work as code, thus would be the best choice.

Finally, the acronym is PEMDAS: parentheses (or brackets, as you silly Europeans call them), exponents, multiplication and division, and addition and subtraction. :P

xander

Posted: Sun Feb 28, 2010 11:49 pm
by bert_the_turtle
Welcome to the DEFCON forums, where everything gets turned into an argument :)

Posted: Sun Feb 28, 2010 11:57 pm
by Montyphy
xander wrote:Moreover, it is even bad code, as I highly doubt that you would be using x in that situation (it is likely that "x" would already be used for something else).


You obviously haven't seen martin's code :P

Posted: Mon Mar 01, 2010 1:12 am
by xander
Montyphy wrote:
xander wrote:Moreover, it is even bad code, as I highly doubt that you would be using x in that situation (it is likely that "x" would already be used for something else).


You obviously haven't seen martin's code :P

Burn.

xander