The max() is not enough
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Intro
A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".
While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.
ÃÂ Challenge
"Return the largest of a list of integers if-and-only-if they are not all equal."
More specifically:
Given a string containing only a comma-separated list of integers:
- If they are all equal, return/output nothing
- Else, return/output the largest
Rules
- The input must be a string containing only a comma-separated list of integers
- The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input
Entries may be a full program or just a function, provided you provide some way to test them!
Assumptions
- Assume input list elements may be more than one digit but no larger than
( 232 â 1 ) - Assume the input list has no more than a million elements
- Assume the input will not include negative values
- Assume the input will never be empty
For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").
ÃÂ Examples
(1) All equal:
Input: 1,1
Output:
(2) Dissimilar:
Input: 1,2
Output: 2
(3) Zero!:
Input: 0,0,0,0,0,0,0,1,0,0
Output: 1
(4) Random:
Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9
(5) Larger numbers, larger list:
Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887
Additional examples:
(6) All equal, larger list:
Input: 7,7,7,7,7,7,7,7,7
Output:
(7) All equal, larger list, larger numbers:
Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:
(8) Not equal, larger list, larger numbers:
Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)
Scoring
This is code-golf
, so the code with the shortest number of bytes wins!
code-golf
add a comment |Â
up vote
2
down vote
favorite
Intro
A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".
While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.
ÃÂ Challenge
"Return the largest of a list of integers if-and-only-if they are not all equal."
More specifically:
Given a string containing only a comma-separated list of integers:
- If they are all equal, return/output nothing
- Else, return/output the largest
Rules
- The input must be a string containing only a comma-separated list of integers
- The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input
Entries may be a full program or just a function, provided you provide some way to test them!
Assumptions
- Assume input list elements may be more than one digit but no larger than
( 232 â 1 ) - Assume the input list has no more than a million elements
- Assume the input will not include negative values
- Assume the input will never be empty
For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").
ÃÂ Examples
(1) All equal:
Input: 1,1
Output:
(2) Dissimilar:
Input: 1,2
Output: 2
(3) Zero!:
Input: 0,0,0,0,0,0,0,1,0,0
Output: 1
(4) Random:
Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9
(5) Larger numbers, larger list:
Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887
Additional examples:
(6) All equal, larger list:
Input: 7,7,7,7,7,7,7,7,7
Output:
(7) All equal, larger list, larger numbers:
Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:
(8) Not equal, larger list, larger numbers:
Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)
Scoring
This is code-golf
, so the code with the shortest number of bytes wins!
code-golf
2
Is it OK to throw an error when the list contains all equal values? And can we output a null value (such asNone
in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
â DJMcMayhemâ¦
1 hour ago
2
Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
â Arnauld
1 hour ago
I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
â Shaggy
29 mins ago
@Arnauld Please vote based on the challenge not on user that posted it.
â W W
29 mins ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Intro
A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".
While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.
ÃÂ Challenge
"Return the largest of a list of integers if-and-only-if they are not all equal."
More specifically:
Given a string containing only a comma-separated list of integers:
- If they are all equal, return/output nothing
- Else, return/output the largest
Rules
- The input must be a string containing only a comma-separated list of integers
- The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input
Entries may be a full program or just a function, provided you provide some way to test them!
Assumptions
- Assume input list elements may be more than one digit but no larger than
( 232 â 1 ) - Assume the input list has no more than a million elements
- Assume the input will not include negative values
- Assume the input will never be empty
For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").
ÃÂ Examples
(1) All equal:
Input: 1,1
Output:
(2) Dissimilar:
Input: 1,2
Output: 2
(3) Zero!:
Input: 0,0,0,0,0,0,0,1,0,0
Output: 1
(4) Random:
Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9
(5) Larger numbers, larger list:
Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887
Additional examples:
(6) All equal, larger list:
Input: 7,7,7,7,7,7,7,7,7
Output:
(7) All equal, larger list, larger numbers:
Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:
(8) Not equal, larger list, larger numbers:
Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)
Scoring
This is code-golf
, so the code with the shortest number of bytes wins!
code-golf
Intro
A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".
While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.
ÃÂ Challenge
"Return the largest of a list of integers if-and-only-if they are not all equal."
More specifically:
Given a string containing only a comma-separated list of integers:
- If they are all equal, return/output nothing
- Else, return/output the largest
Rules
- The input must be a string containing only a comma-separated list of integers
- The output must be either nothing (no output of any kind), or else the largest element from the input, represented as it is in the input
Entries may be a full program or just a function, provided you provide some way to test them!
Assumptions
- Assume input list elements may be more than one digit but no larger than
( 232 â 1 ) - Assume the input list has no more than a million elements
- Assume the input will not include negative values
- Assume the input will never be empty
For the avoidance of doubt, the explanation of the challenge given just after "More specifically" shall supersede the statement of the challenge above it ("Return the largest...").
ÃÂ Examples
(1) All equal:
Input: 1,1
Output:
(2) Dissimilar:
Input: 1,2
Output: 2
(3) Zero!:
Input: 0,0,0,0,0,0,0,1,0,0
Output: 1
(4) Random:
Input: 7,3,8,4,8,3,9,4,6,1,3,7,5
Output: 9
(5) Larger numbers, larger list:
Input: 627,3894,863,5195,7789,5269,8887,3262,1448,3192
Output: 8887
Additional examples:
(6) All equal, larger list:
Input: 7,7,7,7,7,7,7,7,7
Output:
(7) All equal, larger list, larger numbers:
Input: 61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976,61976
Output:
(8) Not equal, larger list, larger numbers:
Input: 96185,482754,96185,96185,96185,96185,96185,96185,7,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,96185,961185,96185,96185,96185
Output: 961185 (sorry)
Scoring
This is code-golf
, so the code with the shortest number of bytes wins!
code-golf
code-golf
asked 1 hour ago
ElectricWarr
193
193
2
Is it OK to throw an error when the list contains all equal values? And can we output a null value (such asNone
in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
â DJMcMayhemâ¦
1 hour ago
2
Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
â Arnauld
1 hour ago
I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
â Shaggy
29 mins ago
@Arnauld Please vote based on the challenge not on user that posted it.
â W W
29 mins ago
add a comment |Â
2
Is it OK to throw an error when the list contains all equal values? And can we output a null value (such asNone
in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the input
â DJMcMayhemâ¦
1 hour ago
2
Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
â Arnauld
1 hour ago
I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
â Shaggy
29 mins ago
@Arnauld Please vote based on the challenge not on user that posted it.
â W W
29 mins ago
2
2
Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as
None
in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the inputâ DJMcMayhemâ¦
1 hour ago
Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as
None
in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the inputâ DJMcMayhemâ¦
1 hour ago
2
2
Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
â Arnauld
1 hour ago
Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
â Arnauld
1 hour ago
I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
â Shaggy
29 mins ago
I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
â Shaggy
29 mins ago
@Arnauld Please vote based on the challenge not on user that posted it.
â W W
29 mins ago
@Arnauld Please vote based on the challenge not on user that posted it.
â W W
29 mins ago
add a comment |Â
11 Answers
11
active
oldest
votes
up vote
1
down vote
CJam, 16 13 bytes
q',/:iL|$1>W>
Try it online!
add a comment |Â
up vote
1
down vote
Neim, 4 bytes
ðÂÂÂðÂÂÂÃÂðÂÂÂ
Explanation:
ÃÂ If
ð all elements are equal
ð not
then
ð get greatest element
Try it online!
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
add a comment |Â
up vote
1
down vote
Python 2, 42 bytes
a=input();print('',max(a))[len(set(a))!=1]
Try it online!
This assumes that the input has at least 1 element.
This is my first code golf. It could probably be improved ;P
New contributor
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 53 bytes
Does a function returning '' count as no output? Sure this can be improved upon...
s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)
Try it online!
1
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
add a comment |Â
up vote
0
down vote
R, 50 bytes
x=scan();`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
If the input HAS to be a string...83 bytes.
x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
add a comment |Â
up vote
0
down vote
Python 2, 44 bytes
k=eval(input())
if~-len(set(k)):print max(k)
Try it online!
add a comment |Â
up vote
0
down vote
Ohm v2, 9 bytes
Ul1E?OqÿâÂÂ
Try it online!
Explanation:
Ul1E?OqÿâÂÂ
U Uniquify input
l Get length
1E Push whether length is equak to 1
?Oq If so immediately quit
ÿâ Else print maximum
add a comment |Â
up vote
0
down vote
Octave, 28 bytes
Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.
@(a)max(a)(1+all(a(1)==a):1)
Try it online!
add a comment |Â
up vote
0
down vote
Perl 6, 26 23 bytes
.max if .Set>1o*.EVAL
Try it online!
Returns an empty slip if everything is equal.
add a comment |Â
up vote
0
down vote
K4, 38 bytes
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
Test Cases:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
,4
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
q)
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
,9
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
q)
I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though
Explanation
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
",":x //split string on commas
7h$ //cast strings to long
-48 //they'll be from ascii format, so compensate
?: //get distinct list
t: //set list to variable t
#: //get count of t
1= //check if count t = 1
$[expr;`True;`False] is the conditional format
;; //return nothing if true
x@>xt //if false, sort t descending
*: //return first value
Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.
EDIT: If the commas are a problem, it can be fixed with two more bytes:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
4
,/ //joins the single element lists into one
Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.
add a comment |Â
up vote
0
down vote
Japt, 16 bytes
This would be 9 if not for the unnecessarily strict input format.
Assumes the string contains at least 2 integers.
q, mn
â ÃÂÃÂ?Urw:P
Try it
add a comment |Â
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
CJam, 16 13 bytes
q',/:iL|$1>W>
Try it online!
add a comment |Â
up vote
1
down vote
CJam, 16 13 bytes
q',/:iL|$1>W>
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
CJam, 16 13 bytes
q',/:iL|$1>W>
Try it online!
CJam, 16 13 bytes
q',/:iL|$1>W>
Try it online!
edited 1 hour ago
answered 1 hour ago
Esolanging Fruit
8,09932373
8,09932373
add a comment |Â
add a comment |Â
up vote
1
down vote
Neim, 4 bytes
ðÂÂÂðÂÂÂÃÂðÂÂÂ
Explanation:
ÃÂ If
ð all elements are equal
ð not
then
ð get greatest element
Try it online!
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
add a comment |Â
up vote
1
down vote
Neim, 4 bytes
ðÂÂÂðÂÂÂÃÂðÂÂÂ
Explanation:
ÃÂ If
ð all elements are equal
ð not
then
ð get greatest element
Try it online!
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Neim, 4 bytes
ðÂÂÂðÂÂÂÃÂðÂÂÂ
Explanation:
ÃÂ If
ð all elements are equal
ð not
then
ð get greatest element
Try it online!
Neim, 4 bytes
ðÂÂÂðÂÂÂÃÂðÂÂÂ
Explanation:
ÃÂ If
ð all elements are equal
ð not
then
ð get greatest element
Try it online!
answered 1 hour ago
Okx
12k27100
12k27100
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
add a comment |Â
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
Currently, the input must be a comma-delimited string of integers but I've asked if we can take an array instead.
â Shaggy
27 mins ago
add a comment |Â
up vote
1
down vote
Python 2, 42 bytes
a=input();print('',max(a))[len(set(a))!=1]
Try it online!
This assumes that the input has at least 1 element.
This is my first code golf. It could probably be improved ;P
New contributor
add a comment |Â
up vote
1
down vote
Python 2, 42 bytes
a=input();print('',max(a))[len(set(a))!=1]
Try it online!
This assumes that the input has at least 1 element.
This is my first code golf. It could probably be improved ;P
New contributor
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 42 bytes
a=input();print('',max(a))[len(set(a))!=1]
Try it online!
This assumes that the input has at least 1 element.
This is my first code golf. It could probably be improved ;P
New contributor
Python 2, 42 bytes
a=input();print('',max(a))[len(set(a))!=1]
Try it online!
This assumes that the input has at least 1 element.
This is my first code golf. It could probably be improved ;P
New contributor
edited 8 mins ago
New contributor
answered 25 mins ago
Arnav Borborah
1114
1114
New contributor
New contributor
add a comment |Â
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 53 bytes
Does a function returning '' count as no output? Sure this can be improved upon...
s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)
Try it online!
1
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 53 bytes
Does a function returning '' count as no output? Sure this can be improved upon...
s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)
Try it online!
1
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
JavaScript (Node.js), 53 bytes
Does a function returning '' count as no output? Sure this can be improved upon...
s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)
Try it online!
JavaScript (Node.js), 53 bytes
Does a function returning '' count as no output? Sure this can be improved upon...
s=>(a=s.split`,`).every(e=>a[0]==e)?'':Math.max(...a)
Try it online!
answered 1 hour ago
Chris M
1615
1615
1
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
add a comment |Â
1
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
1
1
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
A very quick improvement: tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/â¦
â Shaggy
20 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
@Shaggy nice! I started off using Set but couldn't get it as short as that
â Chris M
16 mins ago
add a comment |Â
up vote
0
down vote
R, 50 bytes
x=scan();`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
If the input HAS to be a string...83 bytes.
x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
add a comment |Â
up vote
0
down vote
R, 50 bytes
x=scan();`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
If the input HAS to be a string...83 bytes.
x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
R, 50 bytes
x=scan();`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
If the input HAS to be a string...83 bytes.
x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
R, 50 bytes
x=scan();`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
If the input HAS to be a string...83 bytes.
x=as.numeric(el(strsplit(scan(,""),',')));`if`(length(unique(x))==1,cat(""),max(x))
Try it online!
edited 1 hour ago
answered 1 hour ago
Robert S.
47912
47912
add a comment |Â
add a comment |Â
up vote
0
down vote
Python 2, 44 bytes
k=eval(input())
if~-len(set(k)):print max(k)
Try it online!
add a comment |Â
up vote
0
down vote
Python 2, 44 bytes
k=eval(input())
if~-len(set(k)):print max(k)
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Python 2, 44 bytes
k=eval(input())
if~-len(set(k)):print max(k)
Try it online!
Python 2, 44 bytes
k=eval(input())
if~-len(set(k)):print max(k)
Try it online!
answered 51 mins ago
Chas Brown
4,3111319
4,3111319
add a comment |Â
add a comment |Â
up vote
0
down vote
Ohm v2, 9 bytes
Ul1E?OqÿâÂÂ
Try it online!
Explanation:
Ul1E?OqÿâÂÂ
U Uniquify input
l Get length
1E Push whether length is equak to 1
?Oq If so immediately quit
ÿâ Else print maximum
add a comment |Â
up vote
0
down vote
Ohm v2, 9 bytes
Ul1E?OqÿâÂÂ
Try it online!
Explanation:
Ul1E?OqÿâÂÂ
U Uniquify input
l Get length
1E Push whether length is equak to 1
?Oq If so immediately quit
ÿâ Else print maximum
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Ohm v2, 9 bytes
Ul1E?OqÿâÂÂ
Try it online!
Explanation:
Ul1E?OqÿâÂÂ
U Uniquify input
l Get length
1E Push whether length is equak to 1
?Oq If so immediately quit
ÿâ Else print maximum
Ohm v2, 9 bytes
Ul1E?OqÿâÂÂ
Try it online!
Explanation:
Ul1E?OqÿâÂÂ
U Uniquify input
l Get length
1E Push whether length is equak to 1
?Oq If so immediately quit
ÿâ Else print maximum
answered 49 mins ago
ThePlasmaRailgun
987
987
add a comment |Â
add a comment |Â
up vote
0
down vote
Octave, 28 bytes
Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.
@(a)max(a)(1+all(a(1)==a):1)
Try it online!
add a comment |Â
up vote
0
down vote
Octave, 28 bytes
Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.
@(a)max(a)(1+all(a(1)==a):1)
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Octave, 28 bytes
Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.
@(a)max(a)(1+all(a(1)==a):1)
Try it online!
Octave, 28 bytes
Returns the maximum (a number, which is an 1x1 matrix) or an empty (1x0) matrix.
@(a)max(a)(1+all(a(1)==a):1)
Try it online!
answered 45 mins ago
flawr
25.8k562178
25.8k562178
add a comment |Â
add a comment |Â
up vote
0
down vote
Perl 6, 26 23 bytes
.max if .Set>1o*.EVAL
Try it online!
Returns an empty slip if everything is equal.
add a comment |Â
up vote
0
down vote
Perl 6, 26 23 bytes
.max if .Set>1o*.EVAL
Try it online!
Returns an empty slip if everything is equal.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Perl 6, 26 23 bytes
.max if .Set>1o*.EVAL
Try it online!
Returns an empty slip if everything is equal.
Perl 6, 26 23 bytes
.max if .Set>1o*.EVAL
Try it online!
Returns an empty slip if everything is equal.
edited 42 mins ago
answered 1 hour ago
Jo King
16.9k24193
16.9k24193
add a comment |Â
add a comment |Â
up vote
0
down vote
K4, 38 bytes
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
Test Cases:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
,4
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
q)
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
,9
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
q)
I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though
Explanation
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
",":x //split string on commas
7h$ //cast strings to long
-48 //they'll be from ascii format, so compensate
?: //get distinct list
t: //set list to variable t
#: //get count of t
1= //check if count t = 1
$[expr;`True;`False] is the conditional format
;; //return nothing if true
x@>xt //if false, sort t descending
*: //return first value
Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.
EDIT: If the commas are a problem, it can be fixed with two more bytes:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
4
,/ //joins the single element lists into one
Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.
add a comment |Â
up vote
0
down vote
K4, 38 bytes
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
Test Cases:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
,4
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
q)
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
,9
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
q)
I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though
Explanation
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
",":x //split string on commas
7h$ //cast strings to long
-48 //they'll be from ascii format, so compensate
?: //get distinct list
t: //set list to variable t
#: //get count of t
1= //check if count t = 1
$[expr;`True;`False] is the conditional format
;; //return nothing if true
x@>xt //if false, sort t descending
*: //return first value
Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.
EDIT: If the commas are a problem, it can be fixed with two more bytes:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
4
,/ //joins the single element lists into one
Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
K4, 38 bytes
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
Test Cases:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
,4
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
q)
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
,9
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
q)
I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though
Explanation
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
",":x //split string on commas
7h$ //cast strings to long
-48 //they'll be from ascii format, so compensate
?: //get distinct list
t: //set list to variable t
#: //get count of t
1= //check if count t = 1
$[expr;`True;`False] is the conditional format
;; //return nothing if true
x@>xt //if false, sort t descending
*: //return first value
Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.
EDIT: If the commas are a problem, it can be fixed with two more bytes:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
4
,/ //joins the single element lists into one
Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.
K4, 38 bytes
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
Test Cases:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"1,2,4,4"
,4
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"4,4,4,4"
q)
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,3,8,4,8,3,9,4,6,1,3,7,5"
,9
q)k)$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]"7,7,7,7,7,7,7,7,7,7,7,7,7"
q)
I'm not very fluent in any of the k variants available on TiO, so no online example available, I'll try to come up with one though
Explanation
$[1=#:t:?:(7h$",":x)-48;;*:x@>xt]
",":x //split string on commas
7h$ //cast strings to long
-48 //they'll be from ascii format, so compensate
?: //get distinct list
t: //set list to variable t
#: //get count of t
1= //check if count t = 1
$[expr;`True;`False] is the conditional format
;; //return nothing if true
x@>xt //if false, sort t descending
*: //return first value
Can probably be golfed down more, not a fan of having to use that makeshift max function at the end.
EDIT: If the commas are a problem, it can be fixed with two more bytes:
q)k)$[1=#:t:?:(7h$",":x)-48;;*:,/x@>xt]"1,2,4,4"
4
,/ //joins the single element lists into one
Taking the total to 40, but the comma before the number simply means that it's a single element list as opposed to an atom.
edited 19 mins ago
answered 48 mins ago
Thaufeki
1015
1015
add a comment |Â
add a comment |Â
up vote
0
down vote
Japt, 16 bytes
This would be 9 if not for the unnecessarily strict input format.
Assumes the string contains at least 2 integers.
q, mn
â ÃÂÃÂ?Urw:P
Try it
add a comment |Â
up vote
0
down vote
Japt, 16 bytes
This would be 9 if not for the unnecessarily strict input format.
Assumes the string contains at least 2 integers.
q, mn
â ÃÂÃÂ?Urw:P
Try it
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Japt, 16 bytes
This would be 9 if not for the unnecessarily strict input format.
Assumes the string contains at least 2 integers.
q, mn
â ÃÂÃÂ?Urw:P
Try it
Japt, 16 bytes
This would be 9 if not for the unnecessarily strict input format.
Assumes the string contains at least 2 integers.
q, mn
â ÃÂÃÂ?Urw:P
Try it
answered 10 mins ago
Shaggy
17k21662
17k21662
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173458%2fthe-max-is-not-enough%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Is it OK to throw an error when the list contains all equal values? And can we output a null value (such as
None
in python) rather than outputting nothing? Also, why must the input be a string rather than a list? And what do you mean by the largest element from the input, represented as it is in the inputâ DJMcMayhemâ¦
1 hour ago
2
Please wait for updates / clarifications before downvoting right away an otherwise decent challenge from a new contributor.
â Arnauld
1 hour ago
I'd suggest loosening the input requirements to allow for an array/list of integers, too. Are we guaranteed that the list will contain at least 2 elements? Can we output a consistent, non-numeric value instead of nothing if all integers are equal?
â Shaggy
29 mins ago
@Arnauld Please vote based on the challenge not on user that posted it.
â W W
29 mins ago