Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Golfed 4 bytes
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 12(削除) 12 (削除ここまで) 8 bytes

-4 bytes thanks to Fatalize

c⌉M&iih.hhM∧{iih}fot

Outputs as [[max, col], row]. Try it online! Try it online!

c⌉M&iih.hhM∧{iih}fot
c { }f Flatten the matrix (i.e.Find nestedall listways of numbers)
 ⌉ Get the maximum
 M  Call that value M
 & Start over with the original listsatisfying ofthis listspredicate:
 i Non-deterministically getGet some [element, index] pair (i.e. a row and its row index)
 ih Apply the same operation to that row, turning it into an element and
 its column index
 We now have a list of [[element, col], row] for some as-yet-unknowneach element
 .  That nested list isin the outputarray
 hh Take the first element of the firsto element of thatSort listascending
 M Assert that it is thet same asTake the max calculated earlier
 ∧ Break unification with thelast outputone

Nicer output format, 1411 bytes

c⌉M&iihgtc.hM∧{iih}fotgtc
c⌉M&iihgtc.hM∧{iih}fotgtc
c⌉M&iih {iih}fot Same as above, givinggives [[element[[max, col], row] for an unknown element
 gt  gt Wrap the last itemelement in a singleton list: [[element[[max, col], [row]]
 c c Concatenate: [element[max, col, row]
 . That list is the output
 hM∧ Its first element is the same as the max

To output as [max, row, col] is 1512 bytes; the only change is to transpose the matrix first with \:

c⌉M&\iihgtc.hM∧\{iih}fotgtc

Brachylog, 12 bytes

c⌉M&iih.hhM∧

Outputs as [[max, col], row]. Try it online!

c⌉M&iih.hhM∧
c  Flatten the matrix (i.e. nested list of numbers)
 ⌉ Get the maximum
 M  Call that value M
 & Start over with the original list of lists
 i Non-deterministically get some [element, index] pair (i.e. a row and its row index)
 ih Apply the same operation to that row, turning it into an element and
 its column index
 We now have [[element, col], row] for some as-yet-unknown element
 .  That nested list is the output
 hh Take the first element of the first element of that list
 M Assert that it is the same as the max calculated earlier
 ∧ Break unification with the output

Nicer output format, 14 bytes

c⌉M&iihgtc.hM∧
c⌉M&iihgtc.hM∧
c⌉M&iih  Same as above, giving [[element, col], row] for an unknown element
 gt  Wrap the last item in a singleton list: [[element, col], [row]]
 c Concatenate: [element, col, row]
 . That list is the output
 hM∧ Its first element is the same as the max

To output as [max, row, col] is 15 bytes; the only change is to transpose the matrix first with \:

c⌉M&\iihgtc.hM∧

Brachylog, (削除) 12 (削除ここまで) 8 bytes

-4 bytes thanks to Fatalize

{iih}fot

Outputs as [[max, col], row]. Try it online!

{iih}fot
{ }f Find all ways of satisfying this predicate:
 i Get some [element, index] pair (i.e. a row and its row index)
 ih Apply the same operation to that row, turning it into an element and
 its column index
 We now have a list of [[element, col], row] for each element in the array
 o Sort ascending
 t Take the last one

Nicer output format, 11 bytes

{iih}fotgtc
{iih}fotgtc
{iih}fot Same as above, gives [[max, col], row]
 gt Wrap the last element in a singleton list: [[max, col], [row]]
 c Concatenate: [max, col, row]

To output as [max, row, col] is 12 bytes; the only change is to transpose the matrix first with \:

\{iih}fotgtc
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 12 bytes

c⌉M&iih.hhM∧

Outputs as [[max, col], row]. Try it online!

Explanation

c⌉M&iih.hhM∧
c Flatten the matrix (i.e. nested list of numbers)
 ⌉ Get the maximum
 M Call that value M
 & Start over with the original list of lists
 i Non-deterministically get some [element, index] pair (i.e. a row and
 its row index)
 ih Apply the same operation to that row, turning it into an element and
 its column index
 We now have [[element, col], row] for some as-yet-unknown element
 . That nested list is the output
 hh Take the first element of the first element of that list
 M Assert that it is the same as the max calculated earlier
 ∧ Break unification with the output

Nicer output format, 14 bytes

c⌉M&iihgtc.hM∧

Outputs as [max, col, row]. Try it online!

Explanation

c⌉M&iihgtc.hM∧
c⌉M&iih Same as above, giving [[element, col], row] for an unknown element
 gt Wrap the last item in a singleton list: [[element, col], [row]]
 c Concatenate: [element, col, row]
 . That list is the output
 hM∧ Its first element is the same as the max

To output as [max, row, col] is 15 bytes; the only change is to transpose the matrix first with \:

c⌉M&\iihgtc.hM∧

To output as [max, [row, col]] as originally requested is... longer. Brachylog doesn't handle mixed-type lists very well.

AltStyle によって変換されたページ (->オリジナル) /