Skip to main content
added 931 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

GolfScript, 107 91 / 155 bytes

Prints -3-1-1 for convenient palindromes, -4-1-1 otherwise. [Try it online!][TIO1]

Alternate version, 155 bytes

As before, the entire code is executed. The difference is that and every single byte affects the output.

Prints 010 for convenient palindromes, -100 otherwise. [Try it online!][TIO2]

. # Duplicate the input string. 4:ab-1:ba # Save 4 in “ab” and -1 in “ba”. =; # Compare 4 to -1 and discard the result. 1% # Save every element from the input string in a new string. ab% # Reverse the input string. { # For each character in the input string: ... # Duplicate the character thrice. fi # Variable “fi” is undefined; this does nothing. @@= # Verify that the character is equal to itself; push 1. c43 # Variable “c43” is undefined; this does nothing. .=; # Verify that 1 is equal to itself and discard the result. )( # Increment and decrement the character. '"([{}])"'~ # Push that string and evaluate it. Result: '([{}])' ? # Retrieve the character's position in '([{}])'. -1 means not presentfound. ~ # Negate the position.. Examples: -1 -> 0 0 -> -1 2 -> -3 '"([{}])"') # Push that string and pop its last element. Result: '"([{}])' 34 (; # Decrement 34 (the ASCII code of a double quote) and discard. = # Retrieve the corresponding character. .34 # Duplicate the character and push 34. c # Variable “c” is undefined; this does nothing. = # If the character is a double quote, the index was -1. @@if # In that case, replace the double quote with the original character. ... # Duplicate the new character thrice. }% # ab% # Save every fourth element in a new string. Thisto discardsdiscard dummy values. 1; # Push 1 and discard. = # Push 1 if the modified string matches the original one and, 0 otherwise. ab:1- # Save 4 in “1” and subtract. ba:4. # Save -1 in “4” and duplicate. 
presentfound
ExamplesEx.
0| 0
1| 1
UnshiftPop
the
one and,
.[TIO1]: http://golfscript
tryitonline.net/#code=LjQ6YWItMTpiYT07MSViYSV7Li4uZmlAQD1jNDMuPTspKCciKFt7fV0pIid-P34nIihbe31dKSInKSg7PS4zNGM9QEBpZi4uLn0lYWIlMTs9YWI6MS1iYTo0Lg&input=LjQ6YWItMTpiYT07MQolYmEley4uLmZpQEA9CmM0My49OykoJyIoW3sKfV0pIid-P34nIihbewp9XSkiJykoOz0uMzRjCj1AQGlmLi4ufSVhYiUKMTs9YWI6MS1iYTo0Lg[TIO2]: http://golfscript.tryitonline.net/#code=MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOy4uLj07MSVhYiV7Li4uLmlAZkBAZmlAQD1ALj1AXCkrIiInIihbe31dKSInfis_K34nIihbe31dKSInIiIrKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLjthYjo5O2JhOjEtO2k6MDtmOjA7KDo7XHshfTEqITA&input=MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOwouLi49OzElYWIley4uLi5pQGZAQGZpQEA9QC49QFwpCisiIiciKFt7fV0pIid-Kz8rficiKFt7fV0pIiciIisKKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLgo7YWI6OTtiYToxLTtpOjA7ZjowOyg6O1x7IX0xKiEwOw

GolfScript, 107 91 / 155 bytes

As before, the entire code is executed. The difference is that every single byte affects the output.

. # Duplicate the input string. 4:ab-1:ba # Save 4 in “ab” and -1 in “ba”. =; # Compare 4 to -1 and discard the result. 1% # Save every element from the input string in a new string. ab% # Reverse the input string. { # For each character in the input string: ... # Duplicate the character thrice. fi # Variable “fi” is undefined; this does nothing. @@= # Verify that the character is equal to itself; push 1. c43 # Variable “c43” is undefined; this does nothing. .=; # Verify that 1 is equal to itself and discard the result. )( # Increment and decrement the character. '"([{}])"'~ # Push that string and evaluate it. Result: '([{}])' ? # Retrieve the character's position in '([{}])'. -1 means not present. ~ # Negate the position.. Examples: -1 -> 0 0 -> -1 2 -> -3 '"([{}])"') # Push that string and pop its last element. Result: '"([{}])' 34 (; # Decrement 34 (the ASCII code of a double quote) and discard. = # Retrieve the corresponding character. .34 # Duplicate the character and push 34. c # Variable “c” is undefined; this does nothing. = # If the character is a double quote, the index was -1. @@if # In that case, replace the double quote with the original character. ... # Duplicate the new character thrice. }% # ab% # Save every fourth element in a new string. This discards dummy values. 1; # Push 1 and discard. = # Push 1 if the modified string matches the original one and 0 otherwise. ab:1- # Save 4 in “1” and subtract. ba:4. # Save -1 in “4” and duplicate. 
present
Examples
0
1
Unshift
the
one and

GolfScript, 107 91

Prints -3-1-1 for convenient palindromes, -4-1-1 otherwise. [Try it online!][TIO1]

Alternate version, 155 bytes

As before, the entire code is executed and every single byte affects the output.

Prints 010 for convenient palindromes, -100 otherwise. [Try it online!][TIO2]

. # Duplicate the input string. 4:ab-1:ba # Save 4 in “ab” and -1 in “ba”. =; # Compare 4 to -1 and discard the result. 1% # Save every element from the input string in a new string. ab% # Reverse the input string. { # For each character in the input string: ... # Duplicate the character thrice. fi # Variable “fi” is undefined; this does nothing. @@= # Verify that the character is equal to itself; push 1. c43 # Variable “c43” is undefined; this does nothing. .=; # Verify that 1 is equal to itself and discard the result. )( # Increment and decrement the character. '"([{}])"'~ # Push that string and evaluate it. Result: '([{}])' ? # Retrieve the character's position in '([{}])'. -1 means not found. ~ # Negate the position.. Examples: -1 -> 0 0 -> -1 2 -> -3 '"([{}])"') # Push that string and pop its last element. Result: '"([{}])' 34 (; # Decrement 34 (the ASCII code of a double quote) and discard. = # Retrieve the corresponding character. .34 # Duplicate the character and push 34. c # Variable “c” is undefined; this does nothing. = # If the character is a double quote, the index was -1. @@if # In that case, replace the double quote with the original character. ... # Duplicate the new character thrice. }% # ab% # Save every fourth element in a new string to discard dummy values. 1; # Push 1 and discard. = # Push 1 if the modified string matches the original, 0 otherwise. ab:1- # Save 4 in “1” and subtract. ba:4. # Save -1 in “4” and duplicate. 
found
Ex.
| 0
| 1
Pop
,
.[TIO1]: http://golfscript
tryitonline.net/#code=LjQ6YWItMTpiYT07MSViYSV7Li4uZmlAQD1jNDMuPTspKCciKFt7fV0pIid-P34nIihbe31dKSInKSg7PS4zNGM9QEBpZi4uLn0lYWIlMTs9YWI6MS1iYTo0Lg&input=LjQ6YWItMTpiYT07MQolYmEley4uLmZpQEA9CmM0My49OykoJyIoW3sKfV0pIid-P34nIihbewp9XSkiJykoOz0uMzRjCj1AQGlmLi4ufSVhYiUKMTs9YWI6MS1iYTo0Lg[TIO2]: http://golfscript.tryitonline.net/#code=MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOy4uLj07MSVhYiV7Li4uLmlAZkBAZmlAQD1ALj1AXCkrIiInIihbe31dKSInfis_K34nIihbe31dKSInIiIrKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLjthYjo5O2JhOjEtO2k6MDtmOjA7KDo7XHshfTEqITA&input=MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOwouLi49OzElYWIley4uLi5pQGZAQGZpQEA9QC49QFwpCisiIiciKFt7fV0pIid-Kz8rficiKFt7fV0pIiciIisKKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLgo7YWI6OTtiYToxLTtpOjA7ZjowOyg6O1x7IX0xKiEwOw
edited body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
. # Duplicate the input string.  4:ab-1:ba  # Save 4 in “ab” and -1 in “ba”. =; # Compare 4 to -1 and discard the result. 1% # Save every element from the input string in a new string. ab% # Reverse the input string. { # For each character in the input string: ... # Duplicate the character thrice. fi # Variable “fi” is undefined; this does nothing. @@= # Verify that the character is equal to itself; push 1. c43 # Variable “c43” is undefined; this does nothing. .=; # Verify that 1 is equal to itself and discard the result. )( # Increment and decrement the character. '"([{}])"'~ # Push that string and evaluate it. Result: '([{}])' ? # Retrieve the character's position in '([{}])'. -1 means not present. ~ # Negate the position.. Examples: -1 -> 0 0 -> -1 2 -> -3 '"([{}])"') # Push that string and pop its last element. Result: '"([{}])' 34 (; # IncrementDecrement 34 (the ASCII code of a double quote) and discard. = # Retrieve the corresponding character. .34 # Duplicate the character and push 34. c # Variable “c” is undefined; this does nothing. = # If the character is a double quote, the index was -1. @@if # In that case, replace the double quote with the original character. ... # Duplicate the new character thrice. }% # ab% # Save every fourth element in a new string. This discards dummy values. 1; # Push 1 and discard. = # Push 1 if the modified string matches the original one and 0 otherwise. ab:1- # Save 4 in “1” and subtract. ba:4. # Save -1 in “4” and duplicate. 
. # Duplicate the input string.  4:ab-1:ba # Save 4 in “ab” and -1 in “ba”. =; # Compare 4 to -1 and discard the result. 1% # Save every element from the input string in a new string. ab% # Reverse the input string. { # For each character in the input string: ... # Duplicate the character thrice. fi # Variable “fi” is undefined; this does nothing. @@= # Verify that the character is equal to itself; push 1. c43 # Variable “c43” is undefined; this does nothing. .=; # Verify that 1 is equal to itself and discard the result. )( # Increment and decrement the character. '"([{}])"'~ # Push that string and evaluate it. Result: '([{}])' ? # Retrieve the character's position in '([{}])'. -1 means not present. ~ # Negate the position.. Examples: -1 -> 0 0 -> -1 2 -> -3 '"([{}])"') # Push that string and pop its last element. Result: '"([{}])' 34 (; # Increment 34 (the ASCII code of a double quote) and discard. = # Retrieve the corresponding character. .34 # Duplicate the character and push 34. c # Variable “c” is undefined; this does nothing. = # If the character is a double quote, the index was -1. @@if # In that case, replace the double quote with the original character. ... # Duplicate the new character thrice. }% # ab% # Save every fourth element in a new string. This discards dummy values. 1; # Push 1 and discard. = # Push 1 if the modified string matches the original one and 0 otherwise. ab:1- # Save 4 in “1” and subtract. ba:4. # Save -1 in “4” and duplicate. 
. # Duplicate the input string. 4:ab-1:ba  # Save 4 in “ab” and -1 in “ba”. =; # Compare 4 to -1 and discard the result. 1% # Save every element from the input string in a new string. ab% # Reverse the input string. { # For each character in the input string: ... # Duplicate the character thrice. fi # Variable “fi” is undefined; this does nothing. @@= # Verify that the character is equal to itself; push 1. c43 # Variable “c43” is undefined; this does nothing. .=; # Verify that 1 is equal to itself and discard the result. )( # Increment and decrement the character. '"([{}])"'~ # Push that string and evaluate it. Result: '([{}])' ? # Retrieve the character's position in '([{}])'. -1 means not present. ~ # Negate the position.. Examples: -1 -> 0 0 -> -1 2 -> -3 '"([{}])"') # Push that string and pop its last element. Result: '"([{}])' 34 (; # Decrement 34 (the ASCII code of a double quote) and discard. = # Retrieve the corresponding character. .34 # Duplicate the character and push 34. c # Variable “c” is undefined; this does nothing. = # If the character is a double quote, the index was -1. @@if # In that case, replace the double quote with the original character. ... # Duplicate the new character thrice. }% # ab% # Save every fourth element in a new string. This discards dummy values. 1; # Push 1 and discard. = # Push 1 if the modified string matches the original one and 0 otherwise. ab:1- # Save 4 in “1” and subtract. ba:4. # Save -1 in “4” and duplicate. 
deleted 49 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
$ base64 > palindrome.gs -d <<< LjQ6YWItMTpiYT07MSViYSV7Li4uZmlAQD1jNDMuPTspKCciKFt7fV0pIid+P34nIihbe31dKSInKSg7PS4zNGM9QEBpZi4uLn0lYWIlMTs9YWI6MS1iYTo0Lg== $ wc -c palindrome.gs 91 palindrome.gs $ rev palindrome.gs | tr '([{}])' ')]}{[(' | diff - palindrome.gs $ echo -n 'r(a[c{"e"}c]a)r' | golfscript palindrome.gs -3-1-1 $ echo -n 'totallynotapalindrome' | golfscript palindrome.gs -4-1-1 $ $ base64 > palindromepal.gs -d <<< MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOy4uLj07MSVhYiV7Li4uLmlAZkBAZmlAQD1ALj1AXCkrIiInIihbe31dKSInfis/K34nIihbe31dKSInIiIrKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLjthYjo5O2JhOjEtO2k6MDtmOjA7KDo7XHshfTEqITA= $ wc -c palindromepal.gs 155 palindromepal.gs $ rev palindromepal.gs | tr '([{}])' ')]}{[(' | diff - palindromepal.gs $ echo -n 'r(a[c{"e"}c]a)r' | golfscript palindromepal.gs 010 $ echo -n 'totallynotapalindrome' | golfscript palindromepal.gs -100 $ for i in {1..154}; do head -c $i pal.gs > tmp.gs; tail -c +$[i+2] pal.gs >> tmp.gs > [ "$(echo -n 'r(a[c{"e"}c]a)r' | golfscript tmp.gs 2> /dev/null)" = "010" ] && echo $i > done; rm tmp.gs 1 for i in {1..154}; do head -c $i pal.gs > tmp.gs; tail -c +$[i+2] pal.gs >> tmp.gs > [ "$(echo -n '42' | golfscript tmp.gs 2> /dev/null)" = "-100" ] && echo $i > done | grep '^1$'; rm tmp.gs 
$ base64 > palindrome.gs -d <<< LjQ6YWItMTpiYT07MSViYSV7Li4uZmlAQD1jNDMuPTspKCciKFt7fV0pIid+P34nIihbe31dKSInKSg7PS4zNGM9QEBpZi4uLn0lYWIlMTs9YWI6MS1iYTo0Lg== $ wc -c palindrome.gs 91 palindrome.gs $ rev palindrome.gs | tr '([{}])' ')]}{[(' | diff - palindrome.gs $ echo -n 'r(a[c{"e"}c]a)r' | golfscript palindrome.gs -3-1-1 $ echo -n 'totallynotapalindrome' | golfscript palindrome.gs -4-1-1 $ $ base64 > palindrome.gs -d <<< MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOy4uLj07MSVhYiV7Li4uLmlAZkBAZmlAQD1ALj1AXCkrIiInIihbe31dKSInfis/K34nIihbe31dKSInIiIrKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLjthYjo5O2JhOjEtO2k6MDtmOjA7KDo7XHshfTEqITA= $ wc -c palindrome.gs 155 palindrome.gs $ rev palindrome.gs | tr '([{}])' ')]}{[(' | diff - palindrome.gs $ echo -n 'r(a[c{"e"}c]a)r' | golfscript palindrome.gs 010 $ echo -n 'totallynotapalindrome' | golfscript palindrome.gs -100 $ for i in {1..154}; do head -c $i pal.gs > tmp.gs; tail -c +$[i+2] pal.gs >> tmp.gs > [ "$(echo -n 'r(a[c{"e"}c]a)r' | golfscript tmp.gs 2> /dev/null)" = "010" ] && echo $i > done; rm tmp.gs 1 for i in {1..154}; do head -c $i pal.gs > tmp.gs; tail -c +$[i+2] pal.gs >> tmp.gs > [ "$(echo -n '42' | golfscript tmp.gs 2> /dev/null)" = "-100" ] && echo $i > done | grep '^1$'; rm tmp.gs 
$ base64 > palindrome.gs -d <<< LjQ6YWItMTpiYT07MSViYSV7Li4uZmlAQD1jNDMuPTspKCciKFt7fV0pIid+P34nIihbe31dKSInKSg7PS4zNGM9QEBpZi4uLn0lYWIlMTs9YWI6MS1iYTo0Lg== $ wc -c palindrome.gs 91 palindrome.gs $ rev palindrome.gs | tr '([{}])' ')]}{[(' | diff - palindrome.gs $ echo -n 'r(a[c{"e"}c]a)r' | golfscript palindrome.gs -3-1-1 $ echo -n 'totallynotapalindrome' | golfscript palindrome.gs -4-1-1 $ $ base64 > pal.gs -d <<< MCEqMXshfVw7Oik7MDpmOzA6aTstMTphYjs5OmJhOy4uLj07MSVhYiV7Li4uLmlAZkBAZmlAQD1ALj1AXCkrIiInIihbe31dKSInfis/K34nIihbe31dKSInIiIrKFxAPS5APUBAaWZAQGZAaS4uLi59JWJhJTE7PS4uLjthYjo5O2JhOjEtO2k6MDtmOjA7KDo7XHshfTEqITA= $ wc -c pal.gs 155 pal.gs $ rev pal.gs | tr '([{}])' ')]}{[(' | diff - pal.gs $ echo -n 'r(a[c{"e"}c]a)r' | golfscript pal.gs 010 $ echo -n 'totallynotapalindrome' | golfscript pal.gs -100 $ for i in {1..154}; do head -c $i pal.gs > tmp.gs; tail -c +$[i+2] pal.gs >> tmp.gs > [ "$(echo -n 'r(a[c{"e"}c]a)r' | golfscript tmp.gs 2> /dev/null)" = "010" ] && echo $i > done; rm tmp.gs 1 for i in {1..154}; do head -c $i pal.gs > tmp.gs; tail -c +$[i+2] pal.gs >> tmp.gs > [ "$(echo -n '42' | golfscript tmp.gs 2> /dev/null)" = "-100" ] && echo $i > done | grep '^1$'; rm tmp.gs 
Bounty Awarded with 100 reputation awarded by Ilmari Karonen
Bounty Awarded with 100 reputation awarded by algorithmshark
added 2310 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 340 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 3142 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading