[Community Puzzle] All Operations are Equal!

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @tzaph,validated by @Bmol and @UnicornP.
If you have any issues, feel free to ping them.

A = 0
B = 2
C = 1
D = 1
E = 1
A + E = B - E = C * E = 1
… x = 4

Not sure what you’re trying to say? But the puzzle mentions that A, B, C, D and E must be positive, so A can’t be 0.

Any clues for validator 1 and validator 2?
I’m pretty sure I did everything correct since it’s passed all build-in tests.
But when I submit it’s failed on Validator 1 and 2.

The input numbers in Validator 1 are just random numbers.

The input numbers in Validator 2 are either very small numbers or very large numbers (the upper end of the constrained range of X). So you may try to debug by first checking whether your code produces correct answers for very small X.

1 Like

Thank you!
It seems it does. It passes the built-in test 2 which includes both small and large numbers. But still fails submitting validators.
1
2
3
4
5
99996
99997
99998
99999
100000
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES

Solved. Thanks for the clue!
I’ve added x < 8 condition to prevent useless calculations and it was hiding my algorithm defect.

1 Like

As the skill in the puzzle says Brute Force, I’m trying to generate all possible tuples (R,S,T,U) so R+S+T+U == X with no repetition, but just that gives me timeout as soon as Test 2, even before I start implementing E and trying to allocate each RSTU to ABCD…

There should be a path I’m not seeing at all here :slight_smile:

How about trying a brute force on a smaller scale? Something other than 4-tuples?

1 Like

Same. I actually had a note about the missing part, but after solving IDE Tests I thought that version was enough.
If someone else has a < 8 condition, test your logic on 9

1 Like

Thanks, that helped :slight_smile:

I would be interested to know if there is a mathematical rule to choose the upper bound of E ?
My feeling told me 1 < E < X/3 but I have no strong demonstration for it (and it was enough to solve all validators in time)

1 Like

it is definitely <= x/4

Here is where I am with the bounds of E:

# K stands for A+E (==B-E…)

# A = K-E, B = K + E, C = K/E, D = K*E

# Search for a valid root to equation 1 + (2-X/K) * E + E ** 2

# delta imposes k <= x / 4 (real square root), k >= 2 (as k = a>=1 + e>=1)

# 2 <= k <= x / 4

# 1 <= e <= x / 4 (as k = e * c and c >= 1)

# 1 <= e <= (x+(x**2-8*x)**.5)/4 - 1 (implies x >= 8 for real square root)