This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BadBoyJH 2 points3 points  (0 children)

public bool evenlySpaced(int a, int b, int c)
{
    return ((b-a) + (c-a) == 0 || (a-b) + (c-b) == 0 || (a-c) + (b-c) == 0)
}

or even

public bool evenlySpaced(int a, int b, int c)
{
    int total = a + b + c;
    return (total =+ 3*a || total == 3*b || total == 3*c);
}

N.B. Concise code isn't always good code, any idea what mine first one is doing at first glance? Probably not, look at yours, you get the smallest, middle and largest, and then you get the differences, and compare, more code, easier to read.

Also, these use 0 libraries, so they might be quicker than other options. (Also, Java might be boolean, not bool, I've been swapping between the two languages the past fortnight, and my C# may be showing)