Skip to main content
added 25 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Python, 48 48  47 bytes

f=lambda a,o=1:o<2ando>1or a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list ([]) if the input is valid or FalseTrue if not.

Try it online!Try it online!

How?

a is our list of instructions.

o starts off as 1 (,o=1) and is a flag that indicates whether we are on an octagon (1) or square (0), this is updated for the next iteration by subtracting the current flag value from the current instruction length (len(a[0])-o).

If we try to go diagonally from a square then o becomes 2 (since \$2-0=2\$) and then the next iteration's evaluation of o<2o>1 causes a return value of FalseTrue.

We drop the first (now executed) instruction from a (a[1:]) in order to perform the next iteration and if we find ourselves with an empty list the instructions were valid and andor a causes this empty list to be returned.

Python, 48 bytes

f=lambda a,o=1:o<2and a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list if the input is valid or False if not.

Try it online!

How?

a is our list of instructions.

o starts off as 1 (,o=1) and is a flag that indicates whether we are on an octagon (1) or square (0), this is updated for the next iteration by subtracting the current flag value from the current instruction length (len(a[0])-o).

If we try to go diagonally from a square then o becomes 2 (since \$2-0=2\$) and then the next iteration's evaluation of o<2 causes a return value of False.

We drop the first (now executed) instruction from a (a[1:]) in order to perform the next iteration and if we find ourselves with an empty list the instructions were valid and and a causes this empty list to be returned.

Python,  48  47 bytes

f=lambda a,o=1:o>1or a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list ([]) if the input is valid or True if not.

Try it online!

How?

a is our list of instructions.

o starts off as 1 (,o=1) and is a flag that indicates whether we are on an octagon (1) or square (0), this is updated for the next iteration by subtracting the current flag value from the current instruction length (len(a[0])-o).

If we try to go diagonally from a square then o becomes 2 (since \$2-0=2\$) and then the next iteration's evaluation of o>1 causes a return value of True.

We drop the first (now executed) instruction from a (a[1:]) in order to perform the next iteration and if we find ourselves with an empty list the instructions were valid and or a causes this empty list to be returned.

added 689 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Python, 48 bytes

f=lambda a,o=1:o<2and a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list if the input is valid or False if not.

Try it online!

How?

a is our list of instructions.

o starts off as 1 (,o=1) and is a flag that indicates whether we are on an octagon (1) or square (0), this is updated for the next iteration by subtracting the current flag value from the current instruction length (len(a[0])-o).

If we try to go diagonally from a square then o becomes 2 (since \$2-0=2\$) and then the next iteration's evaluation of o<2 causes a return value of False.

We drop the first (now executed) instruction from a (a[1:]) in order to perform the next iteration and if we find ourselves with an empty list the instructions were valid and and a causes this empty list to be returned.

Python, 48 bytes

f=lambda a,o=1:o<2and a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list if the input is valid or False if not.

Try it online!

Python, 48 bytes

f=lambda a,o=1:o<2and a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list if the input is valid or False if not.

Try it online!

How?

a is our list of instructions.

o starts off as 1 (,o=1) and is a flag that indicates whether we are on an octagon (1) or square (0), this is updated for the next iteration by subtracting the current flag value from the current instruction length (len(a[0])-o).

If we try to go diagonally from a square then o becomes 2 (since \$2-0=2\$) and then the next iteration's evaluation of o<2 causes a return value of False.

We drop the first (now executed) instruction from a (a[1:]) in order to perform the next iteration and if we find ourselves with an empty list the instructions were valid and and a causes this empty list to be returned.

Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Python, 48 bytes

f=lambda a,o=1:o<2and a and f(a[1:],len(a[0])-o)

A recursive function that accepts a list of strings and returns an empty list if the input is valid or False if not.

Try it online!