Skip to main content
added 63 characters in body
Source Link
frasiyav
  • 789
  • 4
  • 6

BQN, 1515 13 bytesSBCS

-2 bytes thanks to Marshall Lochbaum

-˜`⍟(≠-1˙)≡≠↑1˙˜`⍟≠≡1‿¯1⥊˜≠

Try it hereTry it here.

Unlike many array languages, BQN doesn't have a binomial primitive, so a more creative solution is required.

-˜`⍟(≠-1˙)≡≠↑1˙˜`⍟≠≡1‿¯1⥊˜≠ #
-˜`             # swapped minus scan
   ⍟(≠-1˙)⍟≠         # repeated input length-1 times
number of times
             # matches
           ≠↑1˙1‿¯1⥊˜≠ # inputalternating length1,-1 take.. 1extended (ex:to 1‿0‿0‿0the input 4↑1)length

BQN, 15 bytesSBCS

-˜`⍟(≠-1˙)≡≠↑1˙

Try it here.

Unlike many array languages, BQN doesn't have a binomial primitive, so a more creative solution is required.

-˜`⍟(≠-1˙)≡≠↑1˙ #
-˜`             # swapped minus scan
   ⍟(≠-1˙)      # repeated input length-1 times
               # matches
           ≠↑1˙ # input length take 1 (ex: 1‿0‿0‿0  4↑1)

BQN, 15 13 bytesSBCS

-2 bytes thanks to Marshall Lochbaum

-˜`⍟≠≡1‿¯1⥊˜≠

Try it here.

Unlike many array languages, BQN doesn't have a binomial primitive, so a more creative solution is required.

-˜`⍟≠≡1‿¯1⥊˜≠ #
-˜`           # swapped minus scan
   ⍟≠         # repeated input length number of times
             # matches
      1‿¯1⥊˜≠ # alternating 1,-1 .. extended to the input length
Source Link
frasiyav
  • 789
  • 4
  • 6

BQN, 15 bytesSBCS

-˜`⍟(≠-1˙)≡≠↑1˙

Try it here.

Unlike many array languages, BQN doesn't have a binomial primitive, so a more creative solution is required.

-˜`⍟(≠-1˙)≡≠↑1˙ #
-˜`             # swapped minus scan
   ⍟(≠-1˙)      # repeated input length-1 times
          ≡     # matches
           ≠↑1˙ # input length take 1 (ex: 1‿0‿0‿0 ≡ 4↑1)