Skip to main content
deleted 72 characters in body
Source Link
VolAnd
  • 296
  • 3
  • 8

C, 65 5757 60 bytes

 r;f(char*s){for(;*++s&&r=0;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

but this solution works correctly with any data only at single function call (when the global variable r is initialized to zero), to work in a multiple the initialization should be added (extending code to 60 bytes):fix of

r;f(char*s){for(r=0;*++s&&;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

that works correctly with any data only at single function call (when the global variable r is initialized to zero).

C, 65 57 bytes

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

but this solution works correctly with any data only at single function call (when the global variable r is initialized to zero), to work in a multiple the initialization should be added (extending code to 60 bytes):

r;f(char*s){for(r=0;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

C, 65 57 60 bytes

 r;f(char*s){for(r=0;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

is fix of

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

that works correctly with any data only at single function call (when the global variable r is initialized to zero).

added 317 characters in body
Source Link
VolAnd
  • 296
  • 3
  • 8

C, 65 57 bytes

but this solution works correctly with any data only at single function call (when the global variable r is initialized to zero), to work in a multiple the initialization should be added (extending code to 60 bytes):

r;f(char*s){for(r=0;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

But in any case this is shorter than previous solution (65 bytes) due to use of for instead of while. But previous (the following) is a little easier to understand:

#include <stdio.h>
#include <string.h>

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

int main(void)
{
    char * Truthy[] = { "ABA", 
                        "ABB", 
                        "BAB",
                        "BUMP",
                        "BALD",
                        "BALDY",
                        "UPWARD",
                        "EXAMINATION",
                        "AZBYCXDWEVFUGTHSIRJQKPLOMN" };
    char * Falsey[] = { "AAA",
                        "BBA",
                        "ACE",
                        "THE",
                        "BUMPY",
                        "BALDING",
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int posTestNum = sizeof(Truthy) / sizeof(char *);
    int negTestNum = sizeof(Falsey) / sizeof(char *);
    int i;
    int rate = 0;
    int tests = 0;
    int res = 0;
    printf("Truthy (%d tests):\n", posTestNum);
    for (i = 0; i < posTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Truthy[i], f(Truthy[i]) ? (rate++, "OK") : "Fail");
        r = 0;
    }
    printf("\nFalsey (%d tests):\n", negTestNum);
    for (i = 0; i < negTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Falsey[i], f(Falsey[i]) ? "Fail" : (rate++, "OK"));
        r = 0;
    }
    printf("\n%d of %d tests passed\n", rate, tests);
    return 0;
}

C, 57 bytes

is shorter than previous solution (65 bytes) due to use of for instead of while. But previous (the following) is a little easier to understand:

#include <stdio.h>
#include <string.h>

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

int main(void)
{
    char * Truthy[] = { "ABA", 
                        "ABB", 
                        "BAB",
                        "BUMP",
                        "BALD",
                        "BALDY",
                        "UPWARD",
                        "EXAMINATION",
                        "AZBYCXDWEVFUGTHSIRJQKPLOMN" };
    char * Falsey[] = { "AAA",
                        "BBA",
                        "ACE",
                        "THE",
                        "BUMPY",
                        "BALDING",
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int posTestNum = sizeof(Truthy) / sizeof(char *);
    int negTestNum = sizeof(Falsey) / sizeof(char *);
    int i;
    int rate = 0;
    int tests = 0;
    int res = 0;
    printf("Truthy (%d tests):\n", posTestNum);
    for (i = 0; i < posTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Truthy[i], f(Truthy[i]) ? (rate++, "OK") : "Fail");
    }
    printf("\nFalsey (%d tests):\n", negTestNum);
    for (i = 0; i < negTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Falsey[i], f(Falsey[i]) ? "Fail" : (rate++, "OK"));
    }
    printf("\n%d of %d tests passed\n", rate, tests);
    return 0;
}

C, 65 57 bytes

but this solution works correctly with any data only at single function call (when the global variable r is initialized to zero), to work in a multiple the initialization should be added (extending code to 60 bytes):

r;f(char*s){for(r=0;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

But in any case this is shorter than previous solution (65 bytes) due to use of for instead of while. But previous (the following) is a little easier to understand:

#include <stdio.h>
#include <string.h>

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

int main(void)
{
    char * Truthy[] = { "ABA", 
                        "ABB", 
                        "BAB",
                        "BUMP",
                        "BALD",
                        "BALDY",
                        "UPWARD",
                        "EXAMINATION",
                        "AZBYCXDWEVFUGTHSIRJQKPLOMN" };
    char * Falsey[] = { "AAA",
                        "BBA",
                        "ACE",
                        "THE",
                        "BUMPY",
                        "BALDING",
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int posTestNum = sizeof(Truthy) / sizeof(char *);
    int negTestNum = sizeof(Falsey) / sizeof(char *);
    int i;
    int rate = 0;
    int tests = 0;
    int res = 0;
    printf("Truthy (%d tests):\n", posTestNum);
    for (i = 0; i < posTestNum; i++)
    {
        tests++;
        printf("%s - %s\n", Truthy[i], f(Truthy[i]) ? (rate++, "OK") : "Fail");
        r = 0;
    }
    printf("\nFalsey (%d tests):\n", negTestNum);
    for (i = 0; i < negTestNum; i++)
    {
        tests++;
        printf("%s - %s\n", Falsey[i], f(Falsey[i]) ? "Fail" : (rate++, "OK"));
        r = 0;
    }
    printf("\n%d of %d tests passed\n", rate, tests);
    return 0;
}
added 1400 characters in body
Source Link
VolAnd
  • 296
  • 3
  • 8

UPDATE:

Code for testing:

#include <stdio.h>
#include <string.h>

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

int main(void)
{
    char * Truthy[] = { "ABA", 
                        "ABB", 
                        "BAB",
                        "BUMP",
                        "BALD",
                        "BALDY",
                        "UPWARD",
                        "EXAMINATION",
                        "AZBYCXDWEVFUGTHSIRJQKPLOMN" };
    char * Falsey[] = { "AAA",
                        "BBA",
                        "ACE",
                        "THE",
                        "BUMPY",
                        "BALDING",
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int posTestNum = sizeof(Truthy) / sizeof(char *);
    int negTestNum = sizeof(Falsey) / sizeof(char *);
    int i;
    int rate = 0;
    int tests = 0;
    int res = 0;
    printf("Truthy (%d tests):\n", posTestNum);
    for (i = 0; i < posTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Truthy[i], f(Truthy[i]) ? (rate++, "OK") : "Fail");
    }
    printf("\nFalsey (%d tests):\n", negTestNum);
    for (i = 0; i < negTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Falsey[i], f(Falsey[i]) ? "Fail" : (rate++, "OK"));
    }
    printf("\n%d of %d tests passed\n", rate, tests);
    return 0;
}

UPDATE:

Code for testing:

#include <stdio.h>
#include <string.h>

r;f(char*s){for(;*++s&&(r=~r&1<<(*s>*(s-1))););return r;}

int main(void)
{
    char * Truthy[] = { "ABA", 
                        "ABB", 
                        "BAB",
                        "BUMP",
                        "BALD",
                        "BALDY",
                        "UPWARD",
                        "EXAMINATION",
                        "AZBYCXDWEVFUGTHSIRJQKPLOMN" };
    char * Falsey[] = { "AAA",
                        "BBA",
                        "ACE",
                        "THE",
                        "BUMPY",
                        "BALDING",
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int posTestNum = sizeof(Truthy) / sizeof(char *);
    int negTestNum = sizeof(Falsey) / sizeof(char *);
    int i;
    int rate = 0;
    int tests = 0;
    int res = 0;
    printf("Truthy (%d tests):\n", posTestNum);
    for (i = 0; i < posTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Truthy[i], f(Truthy[i]) ? (rate++, "OK") : "Fail");
    }
    printf("\nFalsey (%d tests):\n", negTestNum);
    for (i = 0; i < negTestNum; i++)
    {
        tests++;
        r = 0;
        printf("%s - %s\n", Falsey[i], f(Falsey[i]) ? "Fail" : (rate++, "OK"));
    }
    printf("\n%d of %d tests passed\n", rate, tests);
    return 0;
}
added 216 characters in body
Source Link
VolAnd
  • 296
  • 3
  • 8
Loading
added 201 characters in body
Source Link
VolAnd
  • 296
  • 3
  • 8
Loading
Source Link
VolAnd
  • 296
  • 3
  • 8
Loading