r/shittyprogramming • • Dec 01 '19

Question about a logic problem:

Hey all, so I have the following logic problem for school:

Given three ints, a b c, one of them is small, one is medium and one is large. Return true if the three values are evenly spaced, so the difference between small and medium is the same as the difference between medium and large.

evenlySpaced(2, 4, 6) → true

evenlySpaced(4, 6, 2) → true

evenlySpaced(4, 6, 3) → false

Now, I know that when programming, it's always best to make sure you condense everything into as few lines as possible. I think I've gotten the solution optimized fully as it is only one command, but could someone tell me how to better it? Here's my code:

public boolean evenlySpaced(int a, int b, int c) {
    return a > b && b > c ? a - b == b - c : (a > c && c > b ? a - c == c - b : (b > c && c > a ? b - c == c - a : (b > a && a > c ? b - a == a - c : (c > b && b > a ? c - b == b - a : (c > a && a > b ? c - a == a - b : a == b && b == c)))));
}

Thanks in advance.

94 Upvotes

30 comments sorted by

View all comments

Show parent comment

7

u/inconspicuous_male Dec 01 '19

You aren't full stack unless you can add a front end to the project. Shouldn't be too hard to throw some CSS into the mix

9

u/[deleted] Dec 01 '19

Oh yes, doing math by putting some divs stacked and by calculating their total width.

1

u/ScientificBeastMode Dec 02 '19

Don't forget to write a custom HTML parser class.