A Semi-palindrome Puzzle
Clash 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.
code-golf restricted-source
add a comment |Â
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.
code-golf restricted-source
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
add a comment |Â
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.
code-golf restricted-source
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
code-golf restricted-source
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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.
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
add a comment |Â
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!
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered 29 mins ago
Kevin Cruijssen
31.8k553172
31.8k553172
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
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!
answered 6 mins ago
ovs
17.8k21058
17.8k21058
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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