Compare four integers, return word based on maximum This function should take four integer inputs (a,b,c,d) and return a binary word based on which values equal the maximum of the four.

The return value will be between 1 and 0xF.

For example:

a = 6, b = 77, c = 1, d = 4

returns 2 (binary 0010; only 2nd-least significant bit is set corresponding to b being sole max value)

a = 4, b = 5, c = 10, d = 10

returns 0xC (binary 1100; 3rd- and 4th-least significant bits set corresponding to c and d equaling max value)

a = 1, b = 1, c = 1, d = 1

returns 0xF (binary 1111; all four bits set because all values equal the max)

Here is a simple implementation:

int getWord(int a, int b, int c, int d)
{
    int max = a;
    int word = 1;
    if (b &gt; max)
    {
        max = b;
        word = 2;
    }
    else if (b == max)
    {
        word |= 2;
    }
    if (c &gt; max)
    {
        max = c;
        word = 4;
    }
    else if (c == max)
    {
        word |= 4;
    }
    if (d &gt; max)
    {
        word = 8;
    }
    else if (d == max)
    {
        word |= 8;
    }
    return word;
}


return value can be string of 0's and 1's, bool / bit vector, or integer
Jelly, 2 bytes

Takes input as [d,c,b,a]. Returns a list of Booleans.

Ṁ=


Try it online!

Ṁ Maximum

= equal to (implies the other argument is the original argument; vectorises)