0
\$\begingroup\$

Introduction

Your job is to write a function or program that detects if a number a is less than a number b.

But... You are not allowed to use built-in alternatives for equals, less than, greater than, less than or equal to, greater than or equal to, or not equal to operators. (Writing your own implementation is allowed.) Similar alternative methods/alternatives in other languages that are designed to replace those operations are also restricted.

You are allowed to use operators that are not banned, e.g. bitwise operators and the not operator (but it would be better if your answer did not have the not operator).

Challenge

Simply return a truthy or falsy value (or something that evaluates in the language to true or false like 0 or 1) to indicate whether a is less than b. The winner of the challenge can be determined by the shortest code. External sources are not allowed, but anonymous functions are. Explaining your answer is not mandatory, but encouraged.

Example using Javascript:

(a,b)=>!!Math.max(0,b-a) //remove the !! for truthy and falsy numbers
/*Explanation
(a,b)                    Parameters a and b
     =>                  Function is
       !!                returns true if truthy and false if falsy
         Math.max(0,b-a) returns the greater number, 0 or b-a
*/

Examples of Input and Output

Input | Output
------|-------
1, 3  | true
2, 2  | false
3, 2  | false
\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! The challenge you have linked is very old and not really a good example of a challenge. I have currently voted to close that challenge and I am voting to close your challenge for the same reason. In the future you can visit our sandbox (linked in the sidebar) to get feedback ahead of time. \$\endgroup\$ – Ad Hoc Garf Hunter Dec 29 '19 at 19:51
  • 2
    \$\begingroup\$ The core of the issue is that what consitutes a certain operation (e.g. == or <) is not very clear and varies wildly from language to language. \$\endgroup\$ – Ad Hoc Garf Hunter Dec 29 '19 at 19:54
  • 2
    \$\begingroup\$ Related meta post in Things to avoid when writing challenges. \$\endgroup\$ – Arnauld Dec 29 '19 at 21:25
  • \$\begingroup\$ @a'_' That returns true for 3, 2 even though 3 is not less than 2... \$\endgroup\$ – Yousername Dec 30 '19 at 4:44
  • \$\begingroup\$ @a'_' well you could use logical negation (decided that was too much) and bitwise operators. \$\endgroup\$ – Yousername Dec 30 '19 at 14:27
3
\$\begingroup\$

APL (Dyalog Unicode), 2 bytesSBCS

Anonymous tacit prefix function. Requires ⎕IO←0

⊃⍒

Try it online!

gives the "grade". The indices into the argument that would stably sort it in descending order

  • If the first element is less than the second, it gives [1,0]

  • If the the elements are equal, it gives [0,1]

  • If the second element is less than the second, it gives [0,1]

 picks the first element of that

  • If the first element is less than the second, it gives 1

  • If the the elements are equal, it gives 0

  • If the second element is less than the second, it gives 0

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Hm, I guess this answer isn't useful. \$\endgroup\$ – Adám Dec 29 '19 at 20:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.