A Semi-palindrome Puzzle

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












An palindrome is a word that is its own reverse.



Now there are some words that might look like palindromes but are not. For example consider the word sheesh, sheesh is not a palindrome because its reverse is hseehs which is different, however if we consider sh to be a single letter, then it's reverse is sheesh. This kind of word we will call a semi-palindrome.



Specifically a word is a semi-palindrome if we can split up the word in to some number of chunks such that when the order of the chunks are reversed the original word is formed. (For sheesh those chunks are sh e e sh) We will also require no chunk contains letters from both halves of the word (otherwise every word would be a semi-palindrome). For example rear is not a semi-palindrome because r ea r has a chunk (ea) that contains letters from both sides of the original word. We consider the central character in an odd length word to be on neither side of the word, thus for words with odd length the center character must always be in it's own chunk.



Your task will be to take a list of positive integers and determine if they are a semi-palindrome. Your code should output two consistent unequal values, one if the input is a semi-palindrome and the other otherwise. However the byte sequence of your code must be a semi-palindrome itself.



Answers will be scored in bytes with fewer bytes being better.



Test-cases



 -> True
[1,0,1] -> True
[3,4,2,2,3,4] -> True
[3,5,0,3,5] -> True
[1,2,3,1] -> False
[1,2,3,3,4,1] -> False


Program to generate more testcases.










share|improve this question























  • I knew who this was written by halfway through, then I scrolled down to make sure I was right and.......did not see what I expected :P
    – ETHproductions
    2 hours ago














up vote
6
down vote

favorite












An palindrome is a word that is its own reverse.



Now there are some words that might look like palindromes but are not. For example consider the word sheesh, sheesh is not a palindrome because its reverse is hseehs which is different, however if we consider sh to be a single letter, then it's reverse is sheesh. This kind of word we will call a semi-palindrome.



Specifically a word is a semi-palindrome if we can split up the word in to some number of chunks such that when the order of the chunks are reversed the original word is formed. (For sheesh those chunks are sh e e sh) We will also require no chunk contains letters from both halves of the word (otherwise every word would be a semi-palindrome). For example rear is not a semi-palindrome because r ea r has a chunk (ea) that contains letters from both sides of the original word. We consider the central character in an odd length word to be on neither side of the word, thus for words with odd length the center character must always be in it's own chunk.



Your task will be to take a list of positive integers and determine if they are a semi-palindrome. Your code should output two consistent unequal values, one if the input is a semi-palindrome and the other otherwise. However the byte sequence of your code must be a semi-palindrome itself.



Answers will be scored in bytes with fewer bytes being better.



Test-cases



 -> True
[1,0,1] -> True
[3,4,2,2,3,4] -> True
[3,5,0,3,5] -> True
[1,2,3,1] -> False
[1,2,3,3,4,1] -> False


Program to generate more testcases.










share|improve this question























  • I knew who this was written by halfway through, then I scrolled down to make sure I was right and.......did not see what I expected :P
    – ETHproductions
    2 hours ago












up vote
6
down vote

favorite









up vote
6
down vote

favorite











An palindrome is a word that is its own reverse.



Now there are some words that might look like palindromes but are not. For example consider the word sheesh, sheesh is not a palindrome because its reverse is hseehs which is different, however if we consider sh to be a single letter, then it's reverse is sheesh. This kind of word we will call a semi-palindrome.



Specifically a word is a semi-palindrome if we can split up the word in to some number of chunks such that when the order of the chunks are reversed the original word is formed. (For sheesh those chunks are sh e e sh) We will also require no chunk contains letters from both halves of the word (otherwise every word would be a semi-palindrome). For example rear is not a semi-palindrome because r ea r has a chunk (ea) that contains letters from both sides of the original word. We consider the central character in an odd length word to be on neither side of the word, thus for words with odd length the center character must always be in it's own chunk.



Your task will be to take a list of positive integers and determine if they are a semi-palindrome. Your code should output two consistent unequal values, one if the input is a semi-palindrome and the other otherwise. However the byte sequence of your code must be a semi-palindrome itself.



Answers will be scored in bytes with fewer bytes being better.



Test-cases



 -> True
[1,0,1] -> True
[3,4,2,2,3,4] -> True
[3,5,0,3,5] -> True
[1,2,3,1] -> False
[1,2,3,3,4,1] -> False


Program to generate more testcases.










share|improve this question















An palindrome is a word that is its own reverse.



Now there are some words that might look like palindromes but are not. For example consider the word sheesh, sheesh is not a palindrome because its reverse is hseehs which is different, however if we consider sh to be a single letter, then it's reverse is sheesh. This kind of word we will call a semi-palindrome.



Specifically a word is a semi-palindrome if we can split up the word in to some number of chunks such that when the order of the chunks are reversed the original word is formed. (For sheesh those chunks are sh e e sh) We will also require no chunk contains letters from both halves of the word (otherwise every word would be a semi-palindrome). For example rear is not a semi-palindrome because r ea r has a chunk (ea) that contains letters from both sides of the original word. We consider the central character in an odd length word to be on neither side of the word, thus for words with odd length the center character must always be in it's own chunk.



Your task will be to take a list of positive integers and determine if they are a semi-palindrome. Your code should output two consistent unequal values, one if the input is a semi-palindrome and the other otherwise. However the byte sequence of your code must be a semi-palindrome itself.



Answers will be scored in bytes with fewer bytes being better.



Test-cases



 -> True
[1,0,1] -> True
[3,4,2,2,3,4] -> True
[3,5,0,3,5] -> True
[1,2,3,1] -> False
[1,2,3,3,4,1] -> False


Program to generate more testcases.







code-golf restricted-source






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 secs ago

























asked 2 hours ago









Post Left Ghost Hunter

34.1k10150356




34.1k10150356











  • I knew who this was written by halfway through, then I scrolled down to make sure I was right and.......did not see what I expected :P
    – ETHproductions
    2 hours ago
















  • I knew who this was written by halfway through, then I scrolled down to make sure I was right and.......did not see what I expected :P
    – ETHproductions
    2 hours ago















I knew who this was written by halfway through, then I scrolled down to make sure I was right and.......did not see what I expected :P
– ETHproductions
2 hours ago




I knew who this was written by halfway through, then I scrolled down to make sure I was right and.......did not see what I expected :P
– ETHproductions
2 hours ago










3 Answers
3






active

oldest

votes

















up vote
1
down vote














05AB1E, 59 bytes



2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θq2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ


Can without a doubt be golfed substantially. The challenge of itself is already pretty tough (for me at least). It already takes way too many bytes to remove the middle item of odd input-lists in my current 05AB1E program, as well as dealing with the edge case of an empty input-list.



Try it online or verify all test cases.



Explanation:





2ä # Split the input into two parts
# i.e. [3,4,2,0,2,3,4] → [[3,4,2,0],[2,3,4]]
ε } # Map both lists to:
N> # If it's the first item (index 0)
* # And
IgÉ i } # If the length of the input is odd:
# i.e. Index=0 and input=[3,4,2,0,2,3,4] for [3,4,2,0] → 1 (truthy)
# i.e. Index=1 and input=[3,4,2,0,2,3,4] for [2,3,4] → 0 (falsey)
¨ # Remove the last item (the middle item of the input-list)
# i.e. [3,4,2,0] → [3,4,2]
.œ # Then take all possible partitions of this inner list
# i.e. [[3,4,2],[2,3,4]]
# → [[[[3],[4],[2]],[[3],[4,2]],[[3,4],[2]],[[3,4,2]]],
# [[[2],[3],[4]],[[2],[3,4]],[[2,3],[4]],[[2,3,4]]]]
` # Push both lists of partitions to the stack
â # Take the cartesian product (all possible combinations) of the partitions
# i.e. [[[[3],[4],[2]],[[2],[3],[4]]],
# [[[3],[4],[2]],[[2],[3,4]]],
# ...,
# [[[3,4,2]],[[2,3,4]]]]
ʒ } # Filter this list of combinations by:
` # Push both parts to the stack
RQ # Check if the second list reversed, is equal to the first
# i.e. [[3,4],[2]] and [[2],[3,4]] → 1 (truthy)
gĀ # After the filter, check if there are any combinations left
# i.e. [[[[3,4],[2]],[[2],[3,4]]]] → 1 (truthy)
~Θ # Or
Ig_ # If the length of the input was 0
# i.e. [3,4,2,0,2,3,4] → 7 → 0 (falsey)
# i.e. 1 and 0 → 1 (truthy)
q # Stop the program (and then implicitly output the top of the stack)
2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ
# Everything after the `q` are no-ops to comply to the challenge rules





share|improve this answer



























    up vote
    0
    down vote














    Python 2, 275 251 bytes





    def s(x):
    l=len(x)
    if l<3:return l<1or x[0]==x[-1]
    for i in range(1,l/2+1):
    if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
    '''
    def s(x):
    l=len(x)
    if l<3:return l<1or x[0]==x[-1]
    for i in range(1,l/2+1):
    if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
    '''


    Try it online!



    -24 bytes thanks to @Kevin Cruijssen



    This feels a little like cheating, but duplicating the program technically makes it a semi-palindrome, though I'm sure doing so increases the byte count more than necessary.
    Returns 1 for semi-palindrome, and returns None otherwise.






    share|improve this answer


















    • 1




      251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
      – Kevin Cruijssen
      24 mins ago










    • 243 bytes by using a comment instead of a multiline string and letting the code run two times
      – ovs
      58 secs ago

















    up vote
    0
    down vote














    Python 2, 157 153 bytes





    s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))#s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))


    Try it online!





    share




















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "200"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174065%2fa-semi-palindrome-puzzle%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote














      05AB1E, 59 bytes



      2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θq2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ


      Can without a doubt be golfed substantially. The challenge of itself is already pretty tough (for me at least). It already takes way too many bytes to remove the middle item of odd input-lists in my current 05AB1E program, as well as dealing with the edge case of an empty input-list.



      Try it online or verify all test cases.



      Explanation:





      2ä # Split the input into two parts
      # i.e. [3,4,2,0,2,3,4] → [[3,4,2,0],[2,3,4]]
      ε } # Map both lists to:
      N> # If it's the first item (index 0)
      * # And
      IgÉ i } # If the length of the input is odd:
      # i.e. Index=0 and input=[3,4,2,0,2,3,4] for [3,4,2,0] → 1 (truthy)
      # i.e. Index=1 and input=[3,4,2,0,2,3,4] for [2,3,4] → 0 (falsey)
      ¨ # Remove the last item (the middle item of the input-list)
      # i.e. [3,4,2,0] → [3,4,2]
      .œ # Then take all possible partitions of this inner list
      # i.e. [[3,4,2],[2,3,4]]
      # → [[[[3],[4],[2]],[[3],[4,2]],[[3,4],[2]],[[3,4,2]]],
      # [[[2],[3],[4]],[[2],[3,4]],[[2,3],[4]],[[2,3,4]]]]
      ` # Push both lists of partitions to the stack
      â # Take the cartesian product (all possible combinations) of the partitions
      # i.e. [[[[3],[4],[2]],[[2],[3],[4]]],
      # [[[3],[4],[2]],[[2],[3,4]]],
      # ...,
      # [[[3,4,2]],[[2,3,4]]]]
      ʒ } # Filter this list of combinations by:
      ` # Push both parts to the stack
      RQ # Check if the second list reversed, is equal to the first
      # i.e. [[3,4],[2]] and [[2],[3,4]] → 1 (truthy)
      gĀ # After the filter, check if there are any combinations left
      # i.e. [[[[3,4],[2]],[[2],[3,4]]]] → 1 (truthy)
      ~Θ # Or
      Ig_ # If the length of the input was 0
      # i.e. [3,4,2,0,2,3,4] → 7 → 0 (falsey)
      # i.e. 1 and 0 → 1 (truthy)
      q # Stop the program (and then implicitly output the top of the stack)
      2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ
      # Everything after the `q` are no-ops to comply to the challenge rules





      share|improve this answer
























        up vote
        1
        down vote














        05AB1E, 59 bytes



        2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θq2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ


        Can without a doubt be golfed substantially. The challenge of itself is already pretty tough (for me at least). It already takes way too many bytes to remove the middle item of odd input-lists in my current 05AB1E program, as well as dealing with the edge case of an empty input-list.



        Try it online or verify all test cases.



        Explanation:





        2ä # Split the input into two parts
        # i.e. [3,4,2,0,2,3,4] → [[3,4,2,0],[2,3,4]]
        ε } # Map both lists to:
        N> # If it's the first item (index 0)
        * # And
        IgÉ i } # If the length of the input is odd:
        # i.e. Index=0 and input=[3,4,2,0,2,3,4] for [3,4,2,0] → 1 (truthy)
        # i.e. Index=1 and input=[3,4,2,0,2,3,4] for [2,3,4] → 0 (falsey)
        ¨ # Remove the last item (the middle item of the input-list)
        # i.e. [3,4,2,0] → [3,4,2]
        .œ # Then take all possible partitions of this inner list
        # i.e. [[3,4,2],[2,3,4]]
        # → [[[[3],[4],[2]],[[3],[4,2]],[[3,4],[2]],[[3,4,2]]],
        # [[[2],[3],[4]],[[2],[3,4]],[[2,3],[4]],[[2,3,4]]]]
        ` # Push both lists of partitions to the stack
        â # Take the cartesian product (all possible combinations) of the partitions
        # i.e. [[[[3],[4],[2]],[[2],[3],[4]]],
        # [[[3],[4],[2]],[[2],[3,4]]],
        # ...,
        # [[[3,4,2]],[[2,3,4]]]]
        ʒ } # Filter this list of combinations by:
        ` # Push both parts to the stack
        RQ # Check if the second list reversed, is equal to the first
        # i.e. [[3,4],[2]] and [[2],[3,4]] → 1 (truthy)
        gĀ # After the filter, check if there are any combinations left
        # i.e. [[[[3,4],[2]],[[2],[3,4]]]] → 1 (truthy)
        ~Θ # Or
        Ig_ # If the length of the input was 0
        # i.e. [3,4,2,0,2,3,4] → 7 → 0 (falsey)
        # i.e. 1 and 0 → 1 (truthy)
        q # Stop the program (and then implicitly output the top of the stack)
        2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ
        # Everything after the `q` are no-ops to comply to the challenge rules





        share|improve this answer






















          up vote
          1
          down vote










          up vote
          1
          down vote










          05AB1E, 59 bytes



          2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θq2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ


          Can without a doubt be golfed substantially. The challenge of itself is already pretty tough (for me at least). It already takes way too many bytes to remove the middle item of odd input-lists in my current 05AB1E program, as well as dealing with the edge case of an empty input-list.



          Try it online or verify all test cases.



          Explanation:





          2ä # Split the input into two parts
          # i.e. [3,4,2,0,2,3,4] → [[3,4,2,0],[2,3,4]]
          ε } # Map both lists to:
          N> # If it's the first item (index 0)
          * # And
          IgÉ i } # If the length of the input is odd:
          # i.e. Index=0 and input=[3,4,2,0,2,3,4] for [3,4,2,0] → 1 (truthy)
          # i.e. Index=1 and input=[3,4,2,0,2,3,4] for [2,3,4] → 0 (falsey)
          ¨ # Remove the last item (the middle item of the input-list)
          # i.e. [3,4,2,0] → [3,4,2]
          .œ # Then take all possible partitions of this inner list
          # i.e. [[3,4,2],[2,3,4]]
          # → [[[[3],[4],[2]],[[3],[4,2]],[[3,4],[2]],[[3,4,2]]],
          # [[[2],[3],[4]],[[2],[3,4]],[[2,3],[4]],[[2,3,4]]]]
          ` # Push both lists of partitions to the stack
          â # Take the cartesian product (all possible combinations) of the partitions
          # i.e. [[[[3],[4],[2]],[[2],[3],[4]]],
          # [[[3],[4],[2]],[[2],[3,4]]],
          # ...,
          # [[[3,4,2]],[[2,3,4]]]]
          ʒ } # Filter this list of combinations by:
          ` # Push both parts to the stack
          RQ # Check if the second list reversed, is equal to the first
          # i.e. [[3,4],[2]] and [[2],[3,4]] → 1 (truthy)
          gĀ # After the filter, check if there are any combinations left
          # i.e. [[[[3,4],[2]],[[2],[3,4]]]] → 1 (truthy)
          ~Θ # Or
          Ig_ # If the length of the input was 0
          # i.e. [3,4,2,0,2,3,4] → 7 → 0 (falsey)
          # i.e. 1 and 0 → 1 (truthy)
          q # Stop the program (and then implicitly output the top of the stack)
          2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ
          # Everything after the `q` are no-ops to comply to the challenge rules





          share|improve this answer













          05AB1E, 59 bytes



          2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θq2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ


          Can without a doubt be golfed substantially. The challenge of itself is already pretty tough (for me at least). It already takes way too many bytes to remove the middle item of odd input-lists in my current 05AB1E program, as well as dealing with the edge case of an empty input-list.



          Try it online or verify all test cases.



          Explanation:





          2ä # Split the input into two parts
          # i.e. [3,4,2,0,2,3,4] → [[3,4,2,0],[2,3,4]]
          ε } # Map both lists to:
          N> # If it's the first item (index 0)
          * # And
          IgÉ i } # If the length of the input is odd:
          # i.e. Index=0 and input=[3,4,2,0,2,3,4] for [3,4,2,0] → 1 (truthy)
          # i.e. Index=1 and input=[3,4,2,0,2,3,4] for [2,3,4] → 0 (falsey)
          ¨ # Remove the last item (the middle item of the input-list)
          # i.e. [3,4,2,0] → [3,4,2]
          .œ # Then take all possible partitions of this inner list
          # i.e. [[3,4,2],[2,3,4]]
          # → [[[[3],[4],[2]],[[3],[4,2]],[[3,4],[2]],[[3,4,2]]],
          # [[[2],[3],[4]],[[2],[3,4]],[[2,3],[4]],[[2,3,4]]]]
          ` # Push both lists of partitions to the stack
          â # Take the cartesian product (all possible combinations) of the partitions
          # i.e. [[[[3],[4],[2]],[[2],[3],[4]]],
          # [[[3],[4],[2]],[[2],[3,4]]],
          # ...,
          # [[[3,4,2]],[[2,3,4]]]]
          ʒ } # Filter this list of combinations by:
          ` # Push both parts to the stack
          RQ # Check if the second list reversed, is equal to the first
          # i.e. [[3,4],[2]] and [[2],[3,4]] → 1 (truthy)
          gĀ # After the filter, check if there are any combinations left
          # i.e. [[[[3,4],[2]],[[2],[3,4]]]] → 1 (truthy)
          ~Θ # Or
          Ig_ # If the length of the input was 0
          # i.e. [3,4,2,0,2,3,4] → 7 → 0 (falsey)
          # i.e. 1 and 0 → 1 (truthy)
          q # Stop the program (and then implicitly output the top of the stack)
          2äεN>IgÉ*i¨}.œ}`âʒ`RQ}gĀIg_~Θ
          # Everything after the `q` are no-ops to comply to the challenge rules






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 29 mins ago









          Kevin Cruijssen

          31.8k553172




          31.8k553172




















              up vote
              0
              down vote














              Python 2, 275 251 bytes





              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''
              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''


              Try it online!



              -24 bytes thanks to @Kevin Cruijssen



              This feels a little like cheating, but duplicating the program technically makes it a semi-palindrome, though I'm sure doing so increases the byte count more than necessary.
              Returns 1 for semi-palindrome, and returns None otherwise.






              share|improve this answer


















              • 1




                251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
                – Kevin Cruijssen
                24 mins ago










              • 243 bytes by using a comment instead of a multiline string and letting the code run two times
                – ovs
                58 secs ago














              up vote
              0
              down vote














              Python 2, 275 251 bytes





              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''
              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''


              Try it online!



              -24 bytes thanks to @Kevin Cruijssen



              This feels a little like cheating, but duplicating the program technically makes it a semi-palindrome, though I'm sure doing so increases the byte count more than necessary.
              Returns 1 for semi-palindrome, and returns None otherwise.






              share|improve this answer


















              • 1




                251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
                – Kevin Cruijssen
                24 mins ago










              • 243 bytes by using a comment instead of a multiline string and letting the code run two times
                – ovs
                58 secs ago












              up vote
              0
              down vote










              up vote
              0
              down vote










              Python 2, 275 251 bytes





              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''
              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''


              Try it online!



              -24 bytes thanks to @Kevin Cruijssen



              This feels a little like cheating, but duplicating the program technically makes it a semi-palindrome, though I'm sure doing so increases the byte count more than necessary.
              Returns 1 for semi-palindrome, and returns None otherwise.






              share|improve this answer















              Python 2, 275 251 bytes





              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''
              def s(x):
              l=len(x)
              if l<3:return l<1or x[0]==x[-1]
              for i in range(1,l/2+1):
              if x[l-i:]==x[:i]and s(x[i:l-i]):return 1
              '''


              Try it online!



              -24 bytes thanks to @Kevin Cruijssen



              This feels a little like cheating, but duplicating the program technically makes it a semi-palindrome, though I'm sure doing so increases the byte count more than necessary.
              Returns 1 for semi-palindrome, and returns None otherwise.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 19 mins ago

























              answered 36 mins ago









              Cowabunghole

              478211




              478211







              • 1




                251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
                – Kevin Cruijssen
                24 mins ago










              • 243 bytes by using a comment instead of a multiline string and letting the code run two times
                – ovs
                58 secs ago












              • 1




                251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
                – Kevin Cruijssen
                24 mins ago










              • 243 bytes by using a comment instead of a multiline string and letting the code run two times
                – ovs
                58 secs ago







              1




              1




              251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
              – Kevin Cruijssen
              24 mins ago




              251 bytes by combining your first two ifs and return statements, and using space and tab as indentation instead of tab and 2x tab.
              – Kevin Cruijssen
              24 mins ago












              243 bytes by using a comment instead of a multiline string and letting the code run two times
              – ovs
              58 secs ago




              243 bytes by using a comment instead of a multiline string and letting the code run two times
              – ovs
              58 secs ago










              up vote
              0
              down vote














              Python 2, 157 153 bytes





              s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))#s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))


              Try it online!





              share
























                up vote
                0
                down vote














                Python 2, 157 153 bytes





                s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))#s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))


                Try it online!





                share






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote










                  Python 2, 157 153 bytes





                  s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))#s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))


                  Try it online!





                  share













                  Python 2, 157 153 bytes





                  s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))#s=lambda x,i=0:x==x[::-1]or x[i:]and(x[-i:]==x[:i]and s(x[i:-i])or s(x,i+1))


                  Try it online!






                  share











                  share


                  share










                  answered 6 mins ago









                  ovs

                  17.8k21058




                  17.8k21058



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174065%2fa-semi-palindrome-puzzle%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      Installing NextGIS Connect into QGIS 3?

                      One-line joke