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

67

u/AngryRiceBalls Dec 01 '19

Just a heads up, you're in a satirical subreddit. Awesome insight, but I'm just joking around lol.

46

u/inconspicuous_male Dec 01 '19

Oh fuck! I fell pray to a classic trap

21

u/AngryRiceBalls Dec 01 '19

Lmao you're all good.

2

u/claudioSMRun Dec 01 '19

ahah, i gotcha. cercatore.github.io/bebo