Compare four integers, return word based on maximum [on hold]
$begingroup$
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 > max)
{
max = b;
word = 2;
}
else if (b == max)
{
word |= 2;
}
if (c > max)
{
max = c;
word = 4;
}
else if (c == max)
{
word |= 4;
}
if (d > 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
code-golf bitwise
New contributor
$endgroup$
put on hold as unclear what you're asking by Kevin Cruijssen, Οurous, G B, Erik the Outgolfer, Luis Mendo 3 hours ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 9 more comments
$begingroup$
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 > max)
{
max = b;
word = 2;
}
else if (b == max)
{
word |= 2;
}
if (c > max)
{
max = c;
word = 4;
}
else if (c == max)
{
word |= 4;
}
if (d > 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
code-golf bitwise
New contributor
$endgroup$
put on hold as unclear what you're asking by Kevin Cruijssen, Οurous, G B, Erik the Outgolfer, Luis Mendo 3 hours ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
2
$begingroup$
I have a solution in a golfing language, which uses the builtins Reverse, Maximum, Equality-check, Join, Convert from binary to integer, Convert from integer to hexadecimal. Does this means my score is 1 due to the Equality-check? I have the feeling this is too much focused on regular languages, and even for those it's not 100% clear what the scoring for let's say a Maximum-builtin.. :S
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
I would suggest you try to: 1. change this question to code-golf, which only care about the number of bytes. 2. or, restrict to some certain language (certain version of compiler/interpreter please), and list all statements and operators allowed, and how to score them.
$endgroup$
– tsh
12 hours ago
4
$begingroup$
1 is a better option, IMO. I think this makes a perfectly good code-golf question and I can't see any benefit that would come from restricting the languages available for answers
$endgroup$
– senox13
12 hours ago
2
$begingroup$
I updated my question to remove the criteria. Let me know it it's still unclear
$endgroup$
– Mr Anderson
11 hours ago
4
$begingroup$
Should I output a decimal number? Or may I output 4 binary digits instead?
$endgroup$
– tsh
11 hours ago
|
show 9 more comments
$begingroup$
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 > max)
{
max = b;
word = 2;
}
else if (b == max)
{
word |= 2;
}
if (c > max)
{
max = c;
word = 4;
}
else if (c == max)
{
word |= 4;
}
if (d > 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
code-golf bitwise
New contributor
$endgroup$
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 > max)
{
max = b;
word = 2;
}
else if (b == max)
{
word |= 2;
}
if (c > max)
{
max = c;
word = 4;
}
else if (c == max)
{
word |= 4;
}
if (d > 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
code-golf bitwise
code-golf bitwise
New contributor
New contributor
edited 54 mins ago
Mr Anderson
New contributor
asked 13 hours ago
Mr AndersonMr Anderson
1184
1184
New contributor
New contributor
put on hold as unclear what you're asking by Kevin Cruijssen, Οurous, G B, Erik the Outgolfer, Luis Mendo 3 hours ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as unclear what you're asking by Kevin Cruijssen, Οurous, G B, Erik the Outgolfer, Luis Mendo 3 hours ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
2
$begingroup$
I have a solution in a golfing language, which uses the builtins Reverse, Maximum, Equality-check, Join, Convert from binary to integer, Convert from integer to hexadecimal. Does this means my score is 1 due to the Equality-check? I have the feeling this is too much focused on regular languages, and even for those it's not 100% clear what the scoring for let's say a Maximum-builtin.. :S
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
I would suggest you try to: 1. change this question to code-golf, which only care about the number of bytes. 2. or, restrict to some certain language (certain version of compiler/interpreter please), and list all statements and operators allowed, and how to score them.
$endgroup$
– tsh
12 hours ago
4
$begingroup$
1 is a better option, IMO. I think this makes a perfectly good code-golf question and I can't see any benefit that would come from restricting the languages available for answers
$endgroup$
– senox13
12 hours ago
2
$begingroup$
I updated my question to remove the criteria. Let me know it it's still unclear
$endgroup$
– Mr Anderson
11 hours ago
4
$begingroup$
Should I output a decimal number? Or may I output 4 binary digits instead?
$endgroup$
– tsh
11 hours ago
|
show 9 more comments
2
$begingroup$
I have a solution in a golfing language, which uses the builtins Reverse, Maximum, Equality-check, Join, Convert from binary to integer, Convert from integer to hexadecimal. Does this means my score is 1 due to the Equality-check? I have the feeling this is too much focused on regular languages, and even for those it's not 100% clear what the scoring for let's say a Maximum-builtin.. :S
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
I would suggest you try to: 1. change this question to code-golf, which only care about the number of bytes. 2. or, restrict to some certain language (certain version of compiler/interpreter please), and list all statements and operators allowed, and how to score them.
$endgroup$
– tsh
12 hours ago
4
$begingroup$
1 is a better option, IMO. I think this makes a perfectly good code-golf question and I can't see any benefit that would come from restricting the languages available for answers
$endgroup$
– senox13
12 hours ago
2
$begingroup$
I updated my question to remove the criteria. Let me know it it's still unclear
$endgroup$
– Mr Anderson
11 hours ago
4
$begingroup$
Should I output a decimal number? Or may I output 4 binary digits instead?
$endgroup$
– tsh
11 hours ago
2
2
$begingroup$
I have a solution in a golfing language, which uses the builtins Reverse, Maximum, Equality-check, Join, Convert from binary to integer, Convert from integer to hexadecimal. Does this means my score is 1 due to the Equality-check? I have the feeling this is too much focused on regular languages, and even for those it's not 100% clear what the scoring for let's say a Maximum-builtin.. :S
$endgroup$
– Kevin Cruijssen
12 hours ago
$begingroup$
I have a solution in a golfing language, which uses the builtins Reverse, Maximum, Equality-check, Join, Convert from binary to integer, Convert from integer to hexadecimal. Does this means my score is 1 due to the Equality-check? I have the feeling this is too much focused on regular languages, and even for those it's not 100% clear what the scoring for let's say a Maximum-builtin.. :S
$endgroup$
– Kevin Cruijssen
12 hours ago
1
1
$begingroup$
I would suggest you try to: 1. change this question to code-golf, which only care about the number of bytes. 2. or, restrict to some certain language (certain version of compiler/interpreter please), and list all statements and operators allowed, and how to score them.
$endgroup$
– tsh
12 hours ago
$begingroup$
I would suggest you try to: 1. change this question to code-golf, which only care about the number of bytes. 2. or, restrict to some certain language (certain version of compiler/interpreter please), and list all statements and operators allowed, and how to score them.
$endgroup$
– tsh
12 hours ago
4
4
$begingroup$
1 is a better option, IMO. I think this makes a perfectly good code-golf question and I can't see any benefit that would come from restricting the languages available for answers
$endgroup$
– senox13
12 hours ago
$begingroup$
1 is a better option, IMO. I think this makes a perfectly good code-golf question and I can't see any benefit that would come from restricting the languages available for answers
$endgroup$
– senox13
12 hours ago
2
2
$begingroup$
I updated my question to remove the criteria. Let me know it it's still unclear
$endgroup$
– Mr Anderson
11 hours ago
$begingroup$
I updated my question to remove the criteria. Let me know it it's still unclear
$endgroup$
– Mr Anderson
11 hours ago
4
4
$begingroup$
Should I output a decimal number? Or may I output 4 binary digits instead?
$endgroup$
– tsh
11 hours ago
$begingroup$
Should I output a decimal number? Or may I output 4 binary digits instead?
$endgroup$
– tsh
11 hours ago
|
show 9 more comments
13 Answers
13
active
oldest
votes
$begingroup$
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)
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 4 bytesSBCS
Anonymous tacit prefix function. Takes [a,b,c,d]
as argument. Returns a bit-Boolean array.*
⌈/=⌽
Try it online!
⌈/
Does the maximum of the argument
=
equal (vectorises)
⌽
the reverse of the argument?
* Note that APL stores arrays of Booleans using one bit per value, so this does indeed return a 4-bit word, despite the display form being 0 0 1 0
.
$endgroup$
add a comment |
$begingroup$
R, 33 bytes
sum(2^which(max(a<-scan())==a)/2)
Try it online!
Using numerical output. if a vector of booleans is acceptable, then:
R, 17 bytes
max(a<-scan())==a
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 40 bytes
Takes input as ([d,c,b,a])
.
a=>a.map(r=x=>r=r*2|x==Math.max(...a))|r
Try it online!
Or 30 bytes if we can return 4 Boolean values:
a=>a.map(x=>x==Math.max(...a))
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 12 bytes
{$_ X==.max}
Try it online!
Anonymous code block that takes a list of integers and returns a list of booleans. If we need to return as a number, it's +4 bytes to wrap the inside of the code block with 2:[...]
.
Explanation:
{ } # Anonymous code block
$_ # With the input
X== # Which values are equal
.max # To the maximum element
$endgroup$
add a comment |
$begingroup$
Japt, 10
£Â(X¶UrÈwY
Try it!
-1 byte thanks to @Oliver!
Input is a 4-element array in the following format:
[d, c, b, a]
Output is an array of bits.
$endgroup$
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
add a comment |
$begingroup$
05AB1E, 3 bytes
ZQR
Input as a list of [a,b,c,d]
, output as a list of boolean.
Try it online or verify all test cases.
If this output format is not allowed based on the hexadecimal that is used in the challenge description, it would be 6 bytes instead:
ZQRJCh
Try it online or verify all test cases.
Explanation:
Z # Take the maximum of the implicit input-list
Q # Check for each in the (implicit) input-list if it equals this value
R # Reverse the resulting list (and output implicitly as result)
J # Join the list of 0s and 1s to a single string
C # Convert from binary to integer
h # Convert from integer to hexadecimal (and output implicitly as result)
$endgroup$
add a comment |
$begingroup$
Java (JDK), 85 bytes
a->{int m=a[0],w=1,i=0;for(;++i<4;)w=a[i]<m?w:(1<<i)^(a[i]>m?(m=a[i])^m:w);return w;}
Try it online!
- Takes the input as an array of
[a,b,c,d]
.
$endgroup$
add a comment |
$begingroup$
Haskell, 47 bytes
a#b=sum[1|b]+2*a
foldl(#)0.(map=<<(==).maximum)
Try it online!
35 bytes if I can output a string
f x=show.fromEnum.(==maximum x)=<<x
Try it online!
$endgroup$
add a comment |
$begingroup$
PHP, 54 bytes
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i-1;echo$r;
or
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i;echo$r/2;
take input from command line arguments. Run with -nr
or try them online.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 39 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max()?1:0)
Returns an IEnumerable<int>
, which represent bits.
Try it online!
C# (Visual C# Interactive Compiler), 35 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max())
If an IEnumerable<bool>
is acceptable.
Try it online!
C# (Visual C# Interactive Compiler), 49 bytes
n=>{for(int i=4;i-->0;Write(n[i]==n.Max()?1:0));}
Prints a binary string to STDOUT.
Try it online!
$endgroup$
add a comment |
$begingroup$
Here's a JS version that outputs as binary
update: Shorter with join, and without the lookup:
JavaScript (Node.js), 42 bytes
a=>a.map(x=>+(x==Math.max(...a))).join('')
Try it online!
Previous, with lookup, 49 bytes
a=>a.map(x=>[0,1][+(x==Math.max(...a))]).join('')
Try it online!
Previous, with reduce, 52 bytes:
a=>a.reduce((y,x)=>y+[0,1][+(x==Math.max(...a))],'')
Try it online!
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
$endgroup$
1
$begingroup$
You can safely remove[0,1][...]
since you're using an index that already is either $0$ or $1$.
$endgroup$
– Arnauld
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 51 bytes
x=>{for(int m=x.Max(),i=4;i-->0;)x[i]=x[i]==m?1:0;}
Try it online!
Above is an anonymous function that outputs by modifying an argument. Output is an array of 1's and 0's.
Below is a recursive function that outputs an integer.
C# (Visual C# Interactive Compiler), 60 bytes
int f(intx,int i=3)=>i<0?0:2*f(x,i-1)|(x[i]==x.Max()?1:0);
Try it online!
Both functions take input as a 4-element array.
[d, c, b, a]
$endgroup$
add a comment |
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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)
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
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)
answered 10 hours ago
AdámAdám
28.9k276204
28.9k276204
add a comment |
add a comment |
$begingroup$
APL (Dyalog Unicode), 4 bytesSBCS
Anonymous tacit prefix function. Takes [a,b,c,d]
as argument. Returns a bit-Boolean array.*
⌈/=⌽
Try it online!
⌈/
Does the maximum of the argument
=
equal (vectorises)
⌽
the reverse of the argument?
* Note that APL stores arrays of Booleans using one bit per value, so this does indeed return a 4-bit word, despite the display form being 0 0 1 0
.
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 4 bytesSBCS
Anonymous tacit prefix function. Takes [a,b,c,d]
as argument. Returns a bit-Boolean array.*
⌈/=⌽
Try it online!
⌈/
Does the maximum of the argument
=
equal (vectorises)
⌽
the reverse of the argument?
* Note that APL stores arrays of Booleans using one bit per value, so this does indeed return a 4-bit word, despite the display form being 0 0 1 0
.
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 4 bytesSBCS
Anonymous tacit prefix function. Takes [a,b,c,d]
as argument. Returns a bit-Boolean array.*
⌈/=⌽
Try it online!
⌈/
Does the maximum of the argument
=
equal (vectorises)
⌽
the reverse of the argument?
* Note that APL stores arrays of Booleans using one bit per value, so this does indeed return a 4-bit word, despite the display form being 0 0 1 0
.
$endgroup$
APL (Dyalog Unicode), 4 bytesSBCS
Anonymous tacit prefix function. Takes [a,b,c,d]
as argument. Returns a bit-Boolean array.*
⌈/=⌽
Try it online!
⌈/
Does the maximum of the argument
=
equal (vectorises)
⌽
the reverse of the argument?
* Note that APL stores arrays of Booleans using one bit per value, so this does indeed return a 4-bit word, despite the display form being 0 0 1 0
.
edited 11 hours ago
answered 11 hours ago
AdámAdám
28.9k276204
28.9k276204
add a comment |
add a comment |
$begingroup$
R, 33 bytes
sum(2^which(max(a<-scan())==a)/2)
Try it online!
Using numerical output. if a vector of booleans is acceptable, then:
R, 17 bytes
max(a<-scan())==a
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 33 bytes
sum(2^which(max(a<-scan())==a)/2)
Try it online!
Using numerical output. if a vector of booleans is acceptable, then:
R, 17 bytes
max(a<-scan())==a
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 33 bytes
sum(2^which(max(a<-scan())==a)/2)
Try it online!
Using numerical output. if a vector of booleans is acceptable, then:
R, 17 bytes
max(a<-scan())==a
Try it online!
$endgroup$
R, 33 bytes
sum(2^which(max(a<-scan())==a)/2)
Try it online!
Using numerical output. if a vector of booleans is acceptable, then:
R, 17 bytes
max(a<-scan())==a
Try it online!
answered 10 hours ago
Kirill L.Kirill L.
4,9651525
4,9651525
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 40 bytes
Takes input as ([d,c,b,a])
.
a=>a.map(r=x=>r=r*2|x==Math.max(...a))|r
Try it online!
Or 30 bytes if we can return 4 Boolean values:
a=>a.map(x=>x==Math.max(...a))
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 40 bytes
Takes input as ([d,c,b,a])
.
a=>a.map(r=x=>r=r*2|x==Math.max(...a))|r
Try it online!
Or 30 bytes if we can return 4 Boolean values:
a=>a.map(x=>x==Math.max(...a))
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 40 bytes
Takes input as ([d,c,b,a])
.
a=>a.map(r=x=>r=r*2|x==Math.max(...a))|r
Try it online!
Or 30 bytes if we can return 4 Boolean values:
a=>a.map(x=>x==Math.max(...a))
Try it online!
$endgroup$
JavaScript (ES6), 40 bytes
Takes input as ([d,c,b,a])
.
a=>a.map(r=x=>r=r*2|x==Math.max(...a))|r
Try it online!
Or 30 bytes if we can return 4 Boolean values:
a=>a.map(x=>x==Math.max(...a))
Try it online!
edited 11 hours ago
answered 11 hours ago
ArnauldArnauld
77.6k694325
77.6k694325
add a comment |
add a comment |
$begingroup$
Perl 6, 12 bytes
{$_ X==.max}
Try it online!
Anonymous code block that takes a list of integers and returns a list of booleans. If we need to return as a number, it's +4 bytes to wrap the inside of the code block with 2:[...]
.
Explanation:
{ } # Anonymous code block
$_ # With the input
X== # Which values are equal
.max # To the maximum element
$endgroup$
add a comment |
$begingroup$
Perl 6, 12 bytes
{$_ X==.max}
Try it online!
Anonymous code block that takes a list of integers and returns a list of booleans. If we need to return as a number, it's +4 bytes to wrap the inside of the code block with 2:[...]
.
Explanation:
{ } # Anonymous code block
$_ # With the input
X== # Which values are equal
.max # To the maximum element
$endgroup$
add a comment |
$begingroup$
Perl 6, 12 bytes
{$_ X==.max}
Try it online!
Anonymous code block that takes a list of integers and returns a list of booleans. If we need to return as a number, it's +4 bytes to wrap the inside of the code block with 2:[...]
.
Explanation:
{ } # Anonymous code block
$_ # With the input
X== # Which values are equal
.max # To the maximum element
$endgroup$
Perl 6, 12 bytes
{$_ X==.max}
Try it online!
Anonymous code block that takes a list of integers and returns a list of booleans. If we need to return as a number, it's +4 bytes to wrap the inside of the code block with 2:[...]
.
Explanation:
{ } # Anonymous code block
$_ # With the input
X== # Which values are equal
.max # To the maximum element
answered 10 hours ago
Jo KingJo King
24.2k357124
24.2k357124
add a comment |
add a comment |
$begingroup$
Japt, 10
£Â(X¶UrÈwY
Try it!
-1 byte thanks to @Oliver!
Input is a 4-element array in the following format:
[d, c, b, a]
Output is an array of bits.
$endgroup$
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
add a comment |
$begingroup$
Japt, 10
£Â(X¶UrÈwY
Try it!
-1 byte thanks to @Oliver!
Input is a 4-element array in the following format:
[d, c, b, a]
Output is an array of bits.
$endgroup$
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
add a comment |
$begingroup$
Japt, 10
£Â(X¶UrÈwY
Try it!
-1 byte thanks to @Oliver!
Input is a 4-element array in the following format:
[d, c, b, a]
Output is an array of bits.
$endgroup$
Japt, 10
£Â(X¶UrÈwY
Try it!
-1 byte thanks to @Oliver!
Input is a 4-element array in the following format:
[d, c, b, a]
Output is an array of bits.
edited 4 hours ago
answered 5 hours ago
danadana
1,231166
1,231166
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
add a comment |
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
Of course there is ;) There are apparently a lot of shortcuts to learn.
$endgroup$
– dana
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
$begingroup$
If a boolean array is an acceptable output, this can be 7 bytes
$endgroup$
– Oliver
4 hours ago
add a comment |
$begingroup$
05AB1E, 3 bytes
ZQR
Input as a list of [a,b,c,d]
, output as a list of boolean.
Try it online or verify all test cases.
If this output format is not allowed based on the hexadecimal that is used in the challenge description, it would be 6 bytes instead:
ZQRJCh
Try it online or verify all test cases.
Explanation:
Z # Take the maximum of the implicit input-list
Q # Check for each in the (implicit) input-list if it equals this value
R # Reverse the resulting list (and output implicitly as result)
J # Join the list of 0s and 1s to a single string
C # Convert from binary to integer
h # Convert from integer to hexadecimal (and output implicitly as result)
$endgroup$
add a comment |
$begingroup$
05AB1E, 3 bytes
ZQR
Input as a list of [a,b,c,d]
, output as a list of boolean.
Try it online or verify all test cases.
If this output format is not allowed based on the hexadecimal that is used in the challenge description, it would be 6 bytes instead:
ZQRJCh
Try it online or verify all test cases.
Explanation:
Z # Take the maximum of the implicit input-list
Q # Check for each in the (implicit) input-list if it equals this value
R # Reverse the resulting list (and output implicitly as result)
J # Join the list of 0s and 1s to a single string
C # Convert from binary to integer
h # Convert from integer to hexadecimal (and output implicitly as result)
$endgroup$
add a comment |
$begingroup$
05AB1E, 3 bytes
ZQR
Input as a list of [a,b,c,d]
, output as a list of boolean.
Try it online or verify all test cases.
If this output format is not allowed based on the hexadecimal that is used in the challenge description, it would be 6 bytes instead:
ZQRJCh
Try it online or verify all test cases.
Explanation:
Z # Take the maximum of the implicit input-list
Q # Check for each in the (implicit) input-list if it equals this value
R # Reverse the resulting list (and output implicitly as result)
J # Join the list of 0s and 1s to a single string
C # Convert from binary to integer
h # Convert from integer to hexadecimal (and output implicitly as result)
$endgroup$
05AB1E, 3 bytes
ZQR
Input as a list of [a,b,c,d]
, output as a list of boolean.
Try it online or verify all test cases.
If this output format is not allowed based on the hexadecimal that is used in the challenge description, it would be 6 bytes instead:
ZQRJCh
Try it online or verify all test cases.
Explanation:
Z # Take the maximum of the implicit input-list
Q # Check for each in the (implicit) input-list if it equals this value
R # Reverse the resulting list (and output implicitly as result)
J # Join the list of 0s and 1s to a single string
C # Convert from binary to integer
h # Convert from integer to hexadecimal (and output implicitly as result)
answered 10 hours ago
Kevin CruijssenKevin Cruijssen
39.4k560203
39.4k560203
add a comment |
add a comment |
$begingroup$
Java (JDK), 85 bytes
a->{int m=a[0],w=1,i=0;for(;++i<4;)w=a[i]<m?w:(1<<i)^(a[i]>m?(m=a[i])^m:w);return w;}
Try it online!
- Takes the input as an array of
[a,b,c,d]
.
$endgroup$
add a comment |
$begingroup$
Java (JDK), 85 bytes
a->{int m=a[0],w=1,i=0;for(;++i<4;)w=a[i]<m?w:(1<<i)^(a[i]>m?(m=a[i])^m:w);return w;}
Try it online!
- Takes the input as an array of
[a,b,c,d]
.
$endgroup$
add a comment |
$begingroup$
Java (JDK), 85 bytes
a->{int m=a[0],w=1,i=0;for(;++i<4;)w=a[i]<m?w:(1<<i)^(a[i]>m?(m=a[i])^m:w);return w;}
Try it online!
- Takes the input as an array of
[a,b,c,d]
.
$endgroup$
Java (JDK), 85 bytes
a->{int m=a[0],w=1,i=0;for(;++i<4;)w=a[i]<m?w:(1<<i)^(a[i]>m?(m=a[i])^m:w);return w;}
Try it online!
- Takes the input as an array of
[a,b,c,d]
.
edited 8 hours ago
answered 8 hours ago
Olivier GrégoireOlivier Grégoire
9,18511944
9,18511944
add a comment |
add a comment |
$begingroup$
Haskell, 47 bytes
a#b=sum[1|b]+2*a
foldl(#)0.(map=<<(==).maximum)
Try it online!
35 bytes if I can output a string
f x=show.fromEnum.(==maximum x)=<<x
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 47 bytes
a#b=sum[1|b]+2*a
foldl(#)0.(map=<<(==).maximum)
Try it online!
35 bytes if I can output a string
f x=show.fromEnum.(==maximum x)=<<x
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 47 bytes
a#b=sum[1|b]+2*a
foldl(#)0.(map=<<(==).maximum)
Try it online!
35 bytes if I can output a string
f x=show.fromEnum.(==maximum x)=<<x
Try it online!
$endgroup$
Haskell, 47 bytes
a#b=sum[1|b]+2*a
foldl(#)0.(map=<<(==).maximum)
Try it online!
35 bytes if I can output a string
f x=show.fromEnum.(==maximum x)=<<x
Try it online!
edited 4 hours ago
answered 4 hours ago
Sriotchilism O'ZaicSriotchilism O'Zaic
35.2k10159369
35.2k10159369
add a comment |
add a comment |
$begingroup$
PHP, 54 bytes
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i-1;echo$r;
or
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i;echo$r/2;
take input from command line arguments. Run with -nr
or try them online.
$endgroup$
add a comment |
$begingroup$
PHP, 54 bytes
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i-1;echo$r;
or
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i;echo$r/2;
take input from command line arguments. Run with -nr
or try them online.
$endgroup$
add a comment |
$begingroup$
PHP, 54 bytes
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i-1;echo$r;
or
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i;echo$r/2;
take input from command line arguments. Run with -nr
or try them online.
$endgroup$
PHP, 54 bytes
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i-1;echo$r;
or
while($i<4)$argv[++$i]<max($argv)||$r+=1<<$i;echo$r/2;
take input from command line arguments. Run with -nr
or try them online.
answered 3 hours ago
TitusTitus
13.2k11238
13.2k11238
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 39 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max()?1:0)
Returns an IEnumerable<int>
, which represent bits.
Try it online!
C# (Visual C# Interactive Compiler), 35 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max())
If an IEnumerable<bool>
is acceptable.
Try it online!
C# (Visual C# Interactive Compiler), 49 bytes
n=>{for(int i=4;i-->0;Write(n[i]==n.Max()?1:0));}
Prints a binary string to STDOUT.
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 39 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max()?1:0)
Returns an IEnumerable<int>
, which represent bits.
Try it online!
C# (Visual C# Interactive Compiler), 35 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max())
If an IEnumerable<bool>
is acceptable.
Try it online!
C# (Visual C# Interactive Compiler), 49 bytes
n=>{for(int i=4;i-->0;Write(n[i]==n.Max()?1:0));}
Prints a binary string to STDOUT.
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 39 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max()?1:0)
Returns an IEnumerable<int>
, which represent bits.
Try it online!
C# (Visual C# Interactive Compiler), 35 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max())
If an IEnumerable<bool>
is acceptable.
Try it online!
C# (Visual C# Interactive Compiler), 49 bytes
n=>{for(int i=4;i-->0;Write(n[i]==n.Max()?1:0));}
Prints a binary string to STDOUT.
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 39 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max()?1:0)
Returns an IEnumerable<int>
, which represent bits.
Try it online!
C# (Visual C# Interactive Compiler), 35 bytes
n=>n.Select((a,b)=>n[3-b]==n.Max())
If an IEnumerable<bool>
is acceptable.
Try it online!
C# (Visual C# Interactive Compiler), 49 bytes
n=>{for(int i=4;i-->0;Write(n[i]==n.Max()?1:0));}
Prints a binary string to STDOUT.
Try it online!
edited 3 hours ago
answered 3 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
1,428123
1,428123
add a comment |
add a comment |
$begingroup$
Here's a JS version that outputs as binary
update: Shorter with join, and without the lookup:
JavaScript (Node.js), 42 bytes
a=>a.map(x=>+(x==Math.max(...a))).join('')
Try it online!
Previous, with lookup, 49 bytes
a=>a.map(x=>[0,1][+(x==Math.max(...a))]).join('')
Try it online!
Previous, with reduce, 52 bytes:
a=>a.reduce((y,x)=>y+[0,1][+(x==Math.max(...a))],'')
Try it online!
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
$endgroup$
1
$begingroup$
You can safely remove[0,1][...]
since you're using an index that already is either $0$ or $1$.
$endgroup$
– Arnauld
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
add a comment |
$begingroup$
Here's a JS version that outputs as binary
update: Shorter with join, and without the lookup:
JavaScript (Node.js), 42 bytes
a=>a.map(x=>+(x==Math.max(...a))).join('')
Try it online!
Previous, with lookup, 49 bytes
a=>a.map(x=>[0,1][+(x==Math.max(...a))]).join('')
Try it online!
Previous, with reduce, 52 bytes:
a=>a.reduce((y,x)=>y+[0,1][+(x==Math.max(...a))],'')
Try it online!
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
$endgroup$
1
$begingroup$
You can safely remove[0,1][...]
since you're using an index that already is either $0$ or $1$.
$endgroup$
– Arnauld
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
add a comment |
$begingroup$
Here's a JS version that outputs as binary
update: Shorter with join, and without the lookup:
JavaScript (Node.js), 42 bytes
a=>a.map(x=>+(x==Math.max(...a))).join('')
Try it online!
Previous, with lookup, 49 bytes
a=>a.map(x=>[0,1][+(x==Math.max(...a))]).join('')
Try it online!
Previous, with reduce, 52 bytes:
a=>a.reduce((y,x)=>y+[0,1][+(x==Math.max(...a))],'')
Try it online!
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
$endgroup$
Here's a JS version that outputs as binary
update: Shorter with join, and without the lookup:
JavaScript (Node.js), 42 bytes
a=>a.map(x=>+(x==Math.max(...a))).join('')
Try it online!
Previous, with lookup, 49 bytes
a=>a.map(x=>[0,1][+(x==Math.max(...a))]).join('')
Try it online!
Previous, with reduce, 52 bytes:
a=>a.reduce((y,x)=>y+[0,1][+(x==Math.max(...a))],'')
Try it online!
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
fa=>a.map(x=>+(x==Math.max(...a))).join('')
console.log(f([ 4, 1,77, 6])) // 0010
console.log(f([10,10, 5, 4])) // 1100
console.log(f([ 1, 1, 1, 1])) // 1111
edited 3 hours ago
answered 4 hours ago
PureferretPureferret
543726
543726
1
$begingroup$
You can safely remove[0,1][...]
since you're using an index that already is either $0$ or $1$.
$endgroup$
– Arnauld
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
add a comment |
1
$begingroup$
You can safely remove[0,1][...]
since you're using an index that already is either $0$ or $1$.
$endgroup$
– Arnauld
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
1
1
$begingroup$
You can safely remove
[0,1][...]
since you're using an index that already is either $0$ or $1$.$endgroup$
– Arnauld
3 hours ago
$begingroup$
You can safely remove
[0,1][...]
since you're using an index that already is either $0$ or $1$.$endgroup$
– Arnauld
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
$begingroup$
@Arnauld seems obvious now. Thanks!
$endgroup$
– Pureferret
3 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 51 bytes
x=>{for(int m=x.Max(),i=4;i-->0;)x[i]=x[i]==m?1:0;}
Try it online!
Above is an anonymous function that outputs by modifying an argument. Output is an array of 1's and 0's.
Below is a recursive function that outputs an integer.
C# (Visual C# Interactive Compiler), 60 bytes
int f(intx,int i=3)=>i<0?0:2*f(x,i-1)|(x[i]==x.Max()?1:0);
Try it online!
Both functions take input as a 4-element array.
[d, c, b, a]
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 51 bytes
x=>{for(int m=x.Max(),i=4;i-->0;)x[i]=x[i]==m?1:0;}
Try it online!
Above is an anonymous function that outputs by modifying an argument. Output is an array of 1's and 0's.
Below is a recursive function that outputs an integer.
C# (Visual C# Interactive Compiler), 60 bytes
int f(intx,int i=3)=>i<0?0:2*f(x,i-1)|(x[i]==x.Max()?1:0);
Try it online!
Both functions take input as a 4-element array.
[d, c, b, a]
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 51 bytes
x=>{for(int m=x.Max(),i=4;i-->0;)x[i]=x[i]==m?1:0;}
Try it online!
Above is an anonymous function that outputs by modifying an argument. Output is an array of 1's and 0's.
Below is a recursive function that outputs an integer.
C# (Visual C# Interactive Compiler), 60 bytes
int f(intx,int i=3)=>i<0?0:2*f(x,i-1)|(x[i]==x.Max()?1:0);
Try it online!
Both functions take input as a 4-element array.
[d, c, b, a]
$endgroup$
C# (Visual C# Interactive Compiler), 51 bytes
x=>{for(int m=x.Max(),i=4;i-->0;)x[i]=x[i]==m?1:0;}
Try it online!
Above is an anonymous function that outputs by modifying an argument. Output is an array of 1's and 0's.
Below is a recursive function that outputs an integer.
C# (Visual C# Interactive Compiler), 60 bytes
int f(intx,int i=3)=>i<0?0:2*f(x,i-1)|(x[i]==x.Max()?1:0);
Try it online!
Both functions take input as a 4-element array.
[d, c, b, a]
edited 2 hours ago
answered 6 hours ago
danadana
1,231166
1,231166
add a comment |
add a comment |
2
$begingroup$
I have a solution in a golfing language, which uses the builtins Reverse, Maximum, Equality-check, Join, Convert from binary to integer, Convert from integer to hexadecimal. Does this means my score is 1 due to the Equality-check? I have the feeling this is too much focused on regular languages, and even for those it's not 100% clear what the scoring for let's say a Maximum-builtin.. :S
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
I would suggest you try to: 1. change this question to code-golf, which only care about the number of bytes. 2. or, restrict to some certain language (certain version of compiler/interpreter please), and list all statements and operators allowed, and how to score them.
$endgroup$
– tsh
12 hours ago
4
$begingroup$
1 is a better option, IMO. I think this makes a perfectly good code-golf question and I can't see any benefit that would come from restricting the languages available for answers
$endgroup$
– senox13
12 hours ago
2
$begingroup$
I updated my question to remove the criteria. Let me know it it's still unclear
$endgroup$
– Mr Anderson
11 hours ago
4
$begingroup$
Should I output a decimal number? Or may I output 4 binary digits instead?
$endgroup$
– tsh
11 hours ago