7
\$\begingroup\$

In this challenge, your task is to detect (vertical) Skewer Symmetry. This means that one half of the pattern can be produced by mirroring the other half along a vertical axis, and then moving it vertically.

For example, the following pattern has skewer symmetry:

asdf    
jkl;fdsa
    ;lkj

Because if you start from the left half...

asdf               
jkl;

...then mirror it along a vertical axis...

    fdsa
    ;lkj

...then move it down by a character (filling the empty rows with spaces)...


    fdsa
    ;lkj

...you get the second half.

Rules:

  • You may assume the input is rectangle and has an even number of columns.
  • If the pattern itself exhibits reflection symmetry, it is considered skewer symmetry.
  • This is strict character by character symmetry, so [[ is considered symmetrical, but not [].
  • You should output truthy if the input has skewer symmetry, falsy otherwise.
  • Default I/O rules apply, standard loopholes are banned.

Test Cases

Truthy cases:

asdf    
jkl;fdsa
    ;lkj
asdffdsa
[ 


 [
  ba
abdc
cd

Falsy cases:

[ 
 ]
ab
ba
aa
a 
 a
a  a
b b 
ab  
  b 
   a
\$\endgroup\$
  • \$\begingroup\$ suggested test case: ["abfe","cdhg","efba","ghdc"]. i don't know what the result should be. \$\endgroup\$ – ngn Oct 4 at 13:49
  • 1
    \$\begingroup\$ Suggested test case: ["ab ", " b ", " a"] (where the columns are symmetric with the spaces stripped, but not with spaces present) \$\endgroup\$ – Mnemonic Oct 4 at 15:16
  • 1
    \$\begingroup\$ @ngn This is similar to the ["ab", "ba"] test case, result should be falsy (it’s a symmetry+rotation, while skew symmetry is only symmetry+translation). \$\endgroup\$ – Grimy Oct 4 at 18:12
  • 1
    \$\begingroup\$ @Grimy Formatting ate the array. It's supposed to be four columns, with 'a' in the first and last and 'b' in the second and third. So ["ab..", "..b.", "...a"], with the dots replaced with spaces. \$\endgroup\$ – Mnemonic Oct 4 at 18:19
  • 1
    \$\begingroup\$ Suggested test case: [" ba","abdc","cd "] -> truthy (left part is moved downwards). May we assume, that the input contains only printable ASCII (' ' (space) to '~')? \$\endgroup\$ – nimi Oct 5 at 8:29
1
\$\begingroup\$

Haskell, 137 135 133 bytes

f s=uncurry(#)$unzip$splitAt(div(length$s!!0)2)<$>s
a#b@(x:y)|e$last a++x=init a#y|e$last b++a!!0=b#a|r<-reverse<$>b=a==r
e=all(<'!')

Try it online!

\$\endgroup\$
1
\$\begingroup\$

J, 34 23 38 bytes

1 e.[:(e.&:((-:@#{.])"1)|."1\.)"2],:|.

Try it online!

thanks to nimi for catching a bug

Will attempt to regolf the fixed version later.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.