Least operators to test if X == Y

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I've got a bit of code that needs to be written in the event editor, and execute in a somewhat intensive section, and assign a value based on an input value, but can't use the "if" cases in the expression editor. So I'm trying to come up with the way I can do this in the least operators, bit of a math puzzle if anyone cares to try.

    Imagine it as this. Given X, if X == Y, return A, else, if X == Z, return B, else, return 0
    So in my best guess so far, it might look something like this:

    "Return {(1-Min(Abs(X-Y), 1)) * A + (1-Min(Abs(X-Z), 1)) * B}"
    But I'd also like to modify it to let me bounds too, for example
    "If X == (4 to 7) return (0 to 3)"

    So my best 'comparison' set so far is "(1 - Min(Abs(X-Y),1))" which is a total of 4 different operators (min, abs, -, -)
    Any way I can trim this down? Brain is hurting coming up with how I'd do bounds

  • Look into the IIF object. This allow an expression of the form 'if {cond} then {value1} else {value2}'. Nesting these will allow you to do it without all the operations.

    However, this should only be for readability; I doubt you will get a performance gain from this.

    [Note (and I'm sure this is fine in your application) your solution requires X, Y and Z to be integers and Y and Z distinct.]

    P.S. Has anybody else noticed that 'logical not' in the special object is actually a bitwise not? At least in the sense I'd use the terms.

    - Please login to see this link./Please login to see this link.

    Edited once, last by Jax (May 20, 2012 at 7:55 PM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!