P00485 - MCO (Max Consecutive Ones)
There are two general solutions covered here.
Solution | Link | |
---|---|---|
APL | mco ← {0⌈⌈/(≢¨⊆⍨)⍵} |
Link |
Kap | Mco ⇐ ⌈/≢¨⊂⍨ |
|
TinyAPL | Mco ← {⌈⍆≢¨⊆⍨⍵} Mco ← ⌈⍆⍤(≢¨⍤⊆⍨) |
|
J | mco =. [: >./ [: (#;._1) 0,] mco =. {{ >./ (#;._1) 0,y }} |
Link |
BQN | Mco ← ⌈´·+´¨(+`¬)⊸⊔ |
Link |
Uiua | Mco ← /↥⊜⧻. |
|
Q | mco: {max sum each {(where differ x) cut x} x} |
Link |
Julia | maximum(length.(split(string.(x) |> join, "0"))) |
|
MATLAB | 🔜 | |
NumPy | np.max([np.sum(x) for x in np.split(x, np.where(np.diff(x) != 0)[0] + 1)]) |
|
R | 🔜 | |
Nial | mco is op x { max (EACH tally (0 match x cut x)) } |
|
Futhark | 🔜 | |
Ivy | no partition/cut/split | |
SaC | 🔜 | |
ArrayFire | 🔜 | |
MatX | 🔜 |
Solution | Link | |
---|---|---|
APL | scan is broken | |
Kap | mco ⇐ ⌈/⊢«×»+\ |
|
TinyAPL | Mco ← ⦅⌈⍆⋄⊢«×»+⍆↟⦆ |
|
J | mco =. {{ >./(([*+)/\.)&.|. y }} |
|
BQN | Mco ← ⌈´(⊢×+)` |
Link |
Uiua | Mco ← /↥\(×+,) |
|
Q | mco: { max {y*y+x} scan x } |
|
Julia | accumulate((a,b) -> b*(a+b), x) |> maximum |
|
MATLAB | no scan | |
NumPy | np.max(np.frompyfunc(lambda a,b: b*(a+b), 2, 1).accumulate(x)) |
|
R | max(Reduce(function(a,b) b*(a+b), x, accumulate=TRUE)) |
|
Nial | scan is broken | |
Futhark | def mco x = scan (\a b -> b*(a+b)) 0 x |> i32.maximum |
|
Ivy | scan is broken | |
SaC | 🔜 | |
ArrayFire | 🔜 | |
MatX | 🔜 |