g | x | w | all
Bytes Lang Time Link
101Google Sheets240830T095855Zdoubleun
00605AB1E legacy240830T075055ZKevin Cr
053GNU sed240830T052338Zbleep
019K ngn/k240830T014311Zakamayu
nanScala 3240829T045624Z138 Aspe
073JavaScript ES11240828T205810ZArnauld
041Ruby240829T074827ZG B
055Python240828T210306ZAlbert.L
015APLDyalog Unicode240829T025859Zakamayu
007Nekomata + e240829T014044Zalephalp
052JavaScript Node.js240829T012128Zl4m2
007Jelly240828T234545ZJonathan
081Python240828T202651Zshape wa
020Charcoal240828T225402ZNeil
057Retina 0.8.2240828T224901ZNeil
023Uiua240828T215710Znyxbird
009Stax240828T193443ZKhuldrae
028Wolfram Language Mathematica240828T191925Zatt

Google Sheets, 101 bytes

=let(m,A1:F6,f,lambda(a,join(,index(if(len(a),a,"_")))),regexmatch(f(torow(m))&f(tocol(m,,1)),"010"))

Put the matrix in cells A1:E5 and the formula in cell A7.

screenshot

05AB1E (legacy), 6 bytes

ø«»тÁå

Input as a list of strings without delimiter, using 1/0 like in the challenge description.

Try it online or verify all test cases.

Explanation:

ø      # Zip/transpose the (implicit) input-list of strings, swapping rows/columns
 «     # Merge it to the (implicit) input-list
  »    # Join this list of strings by newlines
   т   # Push 100
    Á  # Rotate it once towards the right: "010"
     å # Check if the multiline string contains "010" as substring
       # (after which the result is output implicitly)

Uses the legacy version of 05AB1E, since ø works on a list of strings, whereas the new 05AB1E version would require a matrix (in the new version of 05AB1E, taking a matrix of bits as input, this would have been +1 byte: ø«J»тÁå).

GNU sed, 53 bytes

s/^|\n/f/g
:a
/010|f0[01]*f1[01]*f0/ct
s/f./f/g
ta

Online Editor. Run using gsed -zEf <program>. The program itself is 51 bytes; adding 2 bytes for options zE. Reads input of form

000
111
000

Outputs t if a move exists, f if we are stuck.

Explanation

K (ngn/k), 19 bytes

It takes input as array of characters, and checks if every row and column stays the same when splitted with 010. It outputs 0 for yes instance and 1 for no instance.

{i~,/"010"\'i:x,+x}

Try it online!

Scala 3, 129 101 bytes

Saved 28 bytes thanks to @shape warrior t


Golfed version. Attempt This Online!

g=>g.keys.exists{case(x,y)=>x>1&&g((x,y))*g((x-2,y))>g((x-1,y))||y>1&&g((x,y))*g((x,y-2))>g((x,y-1))}

Ungolfed version. Attempt This Online!

object Main {
  def checkPattern(grid: Map[(Int, Int), Int]): Boolean = {
    for ((x, y) <- grid.keys) {
      if (x > 1 && grid((x, y)) > grid((x - 1, y)) && grid((x - 1, y)) < grid((x - 2, y))) {
        return true
      }
      if (y > 1 && grid((x, y)) > grid((x, y - 1)) && grid((x, y - 1)) < grid((x, y - 2))) {
        return true
      }
    }
    false
  }

  def convert(testcase: String): Map[(Int, Int), Int] = {
    val rows = testcase.stripMargin.trim.split("\n")
    (for {
      (row, y) <- rows.zipWithIndex
      if row.trim.nonEmpty
      (char, x) <- row.trim.split("\\s+").zipWithIndex
    } yield (x, y) -> (1 - char.toInt)).toMap
  }

  def main(args: Array[String]): Unit = {
    val testcases = List(
      """
      0 0 0 0 0
      0 0 0 0 0
      0 0 0 0 1
      0 0 0 0 1
      0 0 0 0 0
      """,
      """
      0 0 0
      1 0 0
      0 0 0
      """,
      """
      1 0 0
      0 0 0
      0 0 1
      """,
      """
      1 1 1 1
      1 0 1 0
      1 1 1 1
      """,
      """
      1 1 1 1
      1 0 1 1
      1 1 1 1
      """,
      "1 0",
      "0 1 0 1",
      "0 1 1 0"
    )

    for (testcase <- testcases) {
      println(s"Input:\n      ${testcase.trim}\n\nOutput: ${checkPattern(convert(testcase))}\n")
    }
  }
}

JavaScript (ES11), 73 bytes

-2 thanks to shape warrior t

Expects a binary matrix (1 for empty, 0 for filled) and returns a Boolean value.

m=>m.some((r,y)=>r.some((v,x)=>v&&r[x+1]<r[x+2]|m[y+1]?.[x]<m[y+2]?.[x]))

Attempt This Online!

Ruby, 41 bytes

->s{(s+s.transpose).any?{|l|/010/=~l*''}}

Try it online!

Python, 53 55 bytes

Thanks @att for finding a bug (+2).

lambda d:"010"in((n:=d.find("\n"))*(d+n*"\n"))[::n+1]+d

Attempt This Online!

Expects a single string consisting of newline-terminated lines of 0s and 1s.

Python, 65 62 bytes

Thanks @att for -3.

lambda d:any((0,1,0)in zip(a,a[1:],a[2:])for a in[*zip(*d)]+d)

Attempt This Online!

Expects a list-of-lists of integers.

Any similarities of test code with that of shape warrior t's are mere coincidence =-P

How?

Essentially an exercise in performing the transpose.

APL(Dyalog Unicode), 15 bytes SBCS

A 3-train that checks if 0 1 0 is a substring of any row or column.

⊢∨⍥(1∊0 1 0∘⍷)⍉

Try it on APLgolf!

Nekomata + -e, 7 bytes

Ť?~q5Ƃ=

Attempt This Online!

Take input as a list of lists with 0 for boxes and 1 for empty spaces.

Ť?~q5Ƃ=
Ť?          Optionally transpose the input
  ~         Take any row
   q        Take any contiguous subsequence
    5Ƃ=     Check if it is equal to [1,0,1]

-e checks if there is a solution.

JavaScript (Node.js), 52 bytes

x=>x.match(`010|0[^]{${n=x.indexOf`
`}}1[^]{${n}}0`)

Try it online!

Regex-based

Jelly, 7 bytes

;ZK“]»ẇ

A monadic Link that accepts a list of lists of characters:

and yields an integer:

Try it online! Or see the test-suite.

How?

;ZK“]»ẇ - Link: list of lists of characters, Rows
 Z      - transpose {Rows} -> Columns
;       - {Rows} concatenate {Columns}
  K     - join {that} with space characters
   “]»  - compressed string = "ABA"
      ẇ - is {"ABA"} a sublist of {the space separated rows & columns}?

Also \$7\$ bytes accepting a list of lists of integers where \$1\$ are spaces and \$0\$ are boxes:

;ZK5B¤ẇ
     ¤  - nilad followed by link(s) as a nilad:
   5    -   five
    B   -   cast to binary -> [1,0,1]

Try it online!

Python, 95 81 bytes

lambda d:any(x>d[x,y]>d[x-1,y]<d[x-2,y]or y>d[x,y]>d[x,y-1]<d[x,y-2]for(x,y)in d)

Attempt This Online!

Takes a dict, with keys being (x, y) coordinates and values being either 0 for box or 1 for empty space. Returns false for stuck and true for non-stuck. -14 bytes after switching from (x, y) being the center square to (x, y) being the bottom right square, taking inspiration from Arnauld's JavaScript answer where (x, y) is the top left square.

Explanation: as was stated in the sandbox, this challenge boils down to finding a horizontal or vertical instance of the pattern [space] [box] [space] (one of the spaces gets filled in by the player; the box gets pushed into the other space). The code inspects every square to see if it's either the rightmost square of a horizontal (1, 0, 1) or the bottom square of a vertical (1, 0, 1). We can write (c, b, a) == (1, 0, 1) as c > b and b < a -- or (ab)using Python's chained comparisons, c > b < a.

There's a subtle, but neat thing going on with the short circuiting in the chained comparisons here: the x> and y> are there to prevent out-of-bounds indexing. If x = 0, then x>d[x,y] cannot be true, so d[x-1,y] and d[x-2,y] are never evaluated. If x = 1, then x>d[x,y]>d[x-1,y] cannot be true, so d[x-2,y] is never evaluated. (Recall that d[a,b] is always either 0 or 1.) The same logic applies to the other chain of comparisons.

Charcoal, 20 bytes

WS⊞υι⊙⁺υEθ⭆υ§λκ№ι010

Try it online! Link is to verbose version of code. Takes input as a string of 0s and 1s with a newline after each row and outputs a Charcoal boolean, i.e. - if a box can be moved, nothing if not. Explanation:

WS⊞υι

Input the level.

⊙⁺υEθ⭆υ§λκ№ι010

Concatenate it to its transpose and check any of the rows for the substring 010.

(My experimental transpose branch of Charcoal could perform the transpose operation in five fewer bytes.)

Retina 0.8.2, 57 bytes

1`010|(?<=(.)*)0.*¶(?<2-1>.)*(?(1)^)1.*¶(?<-2>.)*(?(2)^)0

Try it online! Takes input as a string of 0s and 1s with newlines between each row. Explanation:

1`

Only bother checking for one match.

010|

Search for the string 010 horizontally, or...

(?<=(.)*)0.*¶(?<2-1>.)*(?(1)^)1.*¶(?<-2>.)*(?(2)^)0

... search for the string 010 vertically.

Uiua, 23 bytes

¬≍×⍉∩(>1×/+◫¯3⊂⊂,,1)⍉..

Try it!

¬≍×⍉∩(>1×/+◫¯3⊂⊂,,1)⍉..
     ∩(              )⍉.  # for both the array and its transposition:
               ⊂⊂,,1      #  join a row of 1s above and below it
          /+◫¯3            #  sum three windows of it
       >1×                 #  and find the cells that are boxes have sums >1
   ⍉                      # de-transpose the transposition
  ×                        # find the cells that are stuck on both
¬≍                        # and check if they don' match the original array

Stax, 9 bytes

üo∟Ö╘└└⌂o

Run and debug it at staxlang.xyz! with printable 0/1 output

Takes input as a list of rows, each cell represented as integer 1 for empty and 2 for box. Output is falsy for stuck and truthy for not stuck.

I might be able to get away with â╧óΩ═àN♣ for 8 bytes, replacing the unpacked |I with just I. That would produce -1 for stuck and >=0 for not stuck, not quite as much a designated "yes" value or "no" value as falsy/truthy.

Unpacked (10 bytes)

cM+J11JE|I
cM+           concat with transposed copy
   J          join on 0
    11JE      literal [1,2,1]
        |I    all indices of subarray

Wolfram Language (Mathematica), 28 bytes

FreeQ[#|#,{___,,1,,___}]&

Try it online!

Input an array with 1 for boxes and Null for empty spaces. Returns True if all boxes are stuck, and False otherwise. is \[Transpose].