Skip to main content
Golfed 1 byte
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 1010 9 bytes

-1 byte thanks to a clever observation from Unrelated String

↔?ḍt↰+₁|∧0ḍt↰<|∧0 

Try it online!Try it online!

Alternate 109-byte solution: ↔?ḍt↰+₁ḍt↰<.∨0 (Try it online!Try it online!)

Explanation

↔?ḍt↰+₁|∧0ḍt↰<|∧0  The input reversed ?  is the same as the input ḍ  Split into two halves t  Take the second half (which is the longer one if they aren't the same) ↰  Recurse +₁< AddFirst 1integer togreater than the result of the recursive call   | If the preceding part failed (because the input isn't a palindrome):   ∧ Break unification with the input   0 and set the output to 0 

Brachylog, 10 bytes

↔?ḍt↰+₁|∧0 

Try it online!

Alternate 10-byte solution: ↔?ḍt↰+₁.∨0 (Try it online!)

Explanation

↔?ḍt↰+₁|∧0  The input reversed ?  is the same as the input ḍ  Split into two halves t  Take the second half (which is the longer one if they aren't the same) ↰  Recurse +₁ Add 1 to the result of the recursive call   | If the preceding part failed (because the input isn't a palindrome):   ∧ Break unification with the input   0 and set the output to 0 

Brachylog, 10 9 bytes

-1 byte thanks to a clever observation from Unrelated String

↔?ḍt↰<|∧0 

Try it online!

Alternate 9-byte solution: ↔?ḍt↰<.∨0 (Try it online!)

Explanation

↔?ḍt↰<|∧0 ↔ The input reversed ? is the same as the input ḍ Split into two halves t Take the second half (which is the longer one if they aren't the same) ↰ Recurse < First integer greater than the result of the recursive call | If the preceding part failed (because the input isn't a palindrome): ∧ Break unification with the input 0 and set the output to 0 
I understand why now, thanks to Fatalize in chat
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 10 bytes

↔?ḍt↰+₁|∧0 

Try it online!

I expectedAlternate 10-byte solution: ↔?ḍt↰+₁∨0ḍt↰+₁.∨0 to work for 9 bytes, but it doesn't. Not sure why.(Try it online!)

Explanation

↔?ḍt↰+₁|∧0 ↔ The input reversed ? is the same as the input ḍ Split into two halves t Take the second half (which is the longer one if they aren't the same) ↰ Recurse +₁ Add 1 to the result of the recursive call | If the preceding part failed (because the input isn't a palindrome): ∧ Break unification with the input 0 and set the output to 0 

Brachylog, 10 bytes

↔?ḍt↰+₁|∧0 

Try it online!

I expected ↔?ḍt↰+₁∨0 to work for 9 bytes, but it doesn't. Not sure why.

Explanation

↔?ḍt↰+₁|∧0 ↔ The input reversed ? is the same as the input ḍ Split into two halves t Take the second half (which is the longer one if they aren't the same) ↰ Recurse +₁ Add 1 to the result of the recursive call | If the preceding part failed (because the input isn't a palindrome): ∧ Break unification with the input 0 and set the output to 0 

Brachylog, 10 bytes

↔?ḍt↰+₁|∧0 

Try it online!

Alternate 10-byte solution: ↔?ḍt↰+₁.∨0 (Try it online!)

Explanation

↔?ḍt↰+₁|∧0 ↔ The input reversed ? is the same as the input ḍ Split into two halves t Take the second half (which is the longer one if they aren't the same) ↰ Recurse +₁ Add 1 to the result of the recursive call | If the preceding part failed (because the input isn't a palindrome): ∧ Break unification with the input 0 and set the output to 0 
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 10 bytes

↔?ḍt↰+₁|∧0 

Try it online!

I expected ↔?ḍt↰+₁∨0 to work for 9 bytes, but it doesn't. Not sure why.

Explanation

↔?ḍt↰+₁|∧0 ↔ The input reversed ? is the same as the input ḍ Split into two halves t Take the second half (which is the longer one if they aren't the same) ↰ Recurse +₁ Add 1 to the result of the recursive call | If the preceding part failed (because the input isn't a palindrome): ∧ Break unification with the input 0 and set the output to 0