Skip to main content
added 50 characters in body
Source Link
pommicket
  • 3.2k
  • 2
  • 14
  • 20

C, 8484 83 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]r=c[*s++]-2)r=1;return?1:r;return r;}

Try it online!Try it online!

f() returns 1 if the list is not a list of Noah, and 0 otherwise.

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined, and it won't work if INT_MAX < 100000.

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 7574 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}

Thanks to @ceilingcat for -1 byte!

C, 84 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]-2)r=1;return r;}

Try it online!

f() returns 1 if the list is not a list of Noah, and 0 otherwise.

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined, and it won't work if INT_MAX < 100000.

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 75 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}

C, 84 83 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)r=c[*s++]-2?1:r;return r;}

Try it online!

f() returns 1 if the list is not a list of Noah, and 0 otherwise.

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined, and it won't work if INT_MAX < 100000.

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 74 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}

Thanks to @ceilingcat for -1 byte!

added 75 characters in body; added 39 characters in body
Source Link
pommicket
  • 3.2k
  • 2
  • 14
  • 20

C, 84 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]-2)r=1;return r;}

Try it online!

f() returns 1 if the list is not a list of Noah, and 0 otherwise.

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined.., and it won't work if INT_MAX < 100000.

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 75 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}

C, 84 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]-2)r=1;return r;}

Try it online!

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined...

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 75 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}

C, 84 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]-2)r=1;return r;}

Try it online!

f() returns 1 if the list is not a list of Noah, and 0 otherwise.

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined, and it won't work if INT_MAX < 100000.

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 75 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}
Source Link
pommicket
  • 3.2k
  • 2
  • 14
  • 20

C, 84 bytes

c['   '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]-2)r=1;return r;}

Try it online!

The variable s should point to the beginning of the array, and e should point to the end. Note that after f() is called, c must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined...

If I/O is very flexible, and outputting to a variable is enough, the return r; is unnecessary, and it can be reduced to 75 bytes.

De-golfed:

int counts[100001], return_value;

int f(int *start, int *end) {
        int *ptr;
        for (ptr = start; ptr < end; ptr++)
                counts[*ptr]++;
        for (ptr = start; ptr < end; ptr++) {
                if (counts[*ptr] != 2) {
                        return_value = 1;
                }
        }
        return return_value;
}