4 added 19 characters in body
source | link

C++, 107 (miscounted), 100100 (miscounted), 81

string s;for(int c:t)if(isalnum(c))s.push_back(c|32);returns+=c|32;return s==string(s.rbegin(),s.rend());
  • Exploits ASCII bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.

    #include <string>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(isalnum(c))s.push_back(c|32);returns+=c|32;return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    

C++, 107, 100

string s;for(int c:t)if(isalnum(c))s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Exploits ASCII bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.

    #include <string>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(isalnum(c))s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    

C++, 107 (miscounted), 100 (miscounted), 81

string s;for(int c:t)if(isalnum(c))s+=c|32;return s==string(s.rbegin(),s.rend());
  • Exploits ASCII bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.

    #include <string>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(isalnum(c))s+=c|32;return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    
3 deleted 236 characters in body
source | link

C++, 107107, 100

string s;for(int c:t)if(47<c&c<58|64<c&isalnum(c|32c)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Abuses details ofExploits ASCII layout and bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.
  • Exploits operator precedence to omit parentheses.
  • It might be possible to save two more characters by usingUses ?:int instead of if-statementbecause it's shorter than char or auto.

    #include <algorithm>
    #include <string>
    #include <utility>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(47<c&c<58|64<c&isalnum(c|32c)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    

C++, 107

string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Abuses details of ASCII layout and bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.
  • Exploits operator precedence to omit parentheses.
  • It might be possible to save two more characters by using ?: instead of if-statement.

    #include <algorithm>
    #include <string>
    #include <utility>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    

C++, 107, 100

string s;for(int c:t)if(isalnum(c))s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Exploits ASCII bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.

    #include <string>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(isalnum(c))s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    
2 added 2 characters in body
source | link

C++, 107

string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Abuses details of ASCII layout and bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.
  • Exploits operator precedence to omit parentheses.
  • It might be possible to save two more characters by using ?: instead of if-statement.

    #include <algorithm>
    #include <string>
    #include <utility>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Evan"Eva, can I stab bats in a cave.?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    

C++, 107

string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Abuses details of ASCII layout and bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.
  • Exploits operator precedence to omit parentheses.
  • It might be possible to save two more characters by using ?: instead of if-statement.

    #include <algorithm>
    #include <string>
    #include <utility>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Evan can stab bats in a cave."));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    

C++, 107

string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
  • Abuses details of ASCII layout and bit patterns.
  • Relies on an evil using namespace std;.
  • Uses bitwise AND and OR instead of the logical operators.
  • Uses int because it's shorter than char or auto.
  • Exploits operator precedence to omit parentheses.
  • It might be possible to save two more characters by using ?: instead of if-statement.

    #include <algorithm>
    #include <string>
    #include <utility>
    using namespace std;
    
    bool IsPalindrome(const string & t) {
    string s;for(int c:t)if(47<c&c<58|64<c&(c|32)<123)s.push_back(c|32);return s==string(s.rbegin(),s.rend());
    }
    
    #include <cassert>
    
    int main() {
        assert(!IsPalindrome("gorilla"));  // simple failure
        assert( IsPalindrome("racecar"));  // simple success
        assert( IsPalindrome("Hannah"));   // case blind
        assert(!IsPalindrome("1999"));     // digit failure
        assert( IsPalindrome("2002"));     // digit success
        // Ignore spacing, punctuation, and case:
        assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
        assert( IsPalindrome("A man, a plan, a canal: Panama."));
        assert( IsPalindrome("Eva, can I stab bats in a cave?"));
        assert( IsPalindrome(""));  // empty string
        return 0;
    }
    
1
source | link