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

added 90 characters in body
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) 149(削除) 149 (削除ここまで) 135 bytes

Or R>=4.1, 121107 bytes by replacing four function occurrences with \s.

Edit: -14 bytes thenks to @Giuseppe .

function(M,a,b,`/`=combn,`?`=all)M==sapply(seq(!M),g<-function(i){M[i]=1;?!applycombn(nrow(M)/a,2a,function(x)applycombn(ncol(M)/b,2b,function(y)?M[x,y]))})?g(0)

Try it online! Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) 149 bytes

Or R>=4.1, 121 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)M==sapply(seq(!M),g<-function(i){M[i]=1;?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?M[x,y]))})?g(0)

Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) (削除) 149 (削除ここまで) 135 bytes

Or R>=4.1, 107 bytes by replacing four function occurrences with \s.

Edit: -14 bytes thenks to @Giuseppe .

function(M,a,b,`?`=all)M==sapply(seq(!M),g<-function(i){M[i]=1;?!combn(nrow(M),a,function(x)combn(ncol(M),b,function(y)?M[x,y]))})?g(0)

Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

slightly more readable
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) 149 bytes

Or R>=4.1, 121 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)!sapplyM==sapply(seq(!M),g<-function(i){M[i]=1;?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?M[x,y]))})-M?g(0)

Try it online! Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) 149 bytes

Or R>=4.1, 121 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)!sapply(seq(!M),g<-function(i){M[i]=1;?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?M[x,y]))})-M?g(0)

Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) 149 bytes

Or R>=4.1, 121 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)M==sapply(seq(!M),g<-function(i){M[i]=1;?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?M[x,y]))})?g(0)

Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

deleted 2 characters in body
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) 155(削除) 155 (削除ここまで) 149 bytes

Or R>=4.1, 127121 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)!sapply(seq(!M),g<-function(i,A=`[<-`(M,i,1)){M[i]=1;?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?A[xM[x,y]))})-M?g(0)

Try it online! Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) 155 bytes

Or R>=4.1, 127 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)!sapply(seq(!M),g<-function(i,A=`[<-`(M,i,1))?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?A[x,y])))-M?g(0)

Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

R, (削除) 196 (削除ここまで) (削除) 166 (削除ここまで) (削除) 155 (削除ここまで) 149 bytes

Or R>=4.1, 121 bytes by replacing four function occurrences with \s.

function(M,a,b,`/`=combn,`?`=all)!sapply(seq(!M),g<-function(i){M[i]=1;?!apply(nrow(M)/a,2,function(x)apply(ncol(M)/b,2,function(y)?M[x,y]))})-M?g(0)

Try it online!

Straightforward brute-force.

Takes advantage of redefining `?`=all and operator precedence (? has the lowest and is both unary and binary operator).

deleted 2 characters in body
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78
Loading
deleted 19 characters in body
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78
Loading
added 4 characters in body
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78
Loading
Source Link
pajonk
  • 19.4k
  • 5
  • 29
  • 78
Loading

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