Skip to main content
deleted 3 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84

C,  210  192190 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,*p++-35&t&&++s~*p++&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, *p++-35&t&&++s~*p++&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32?*p=l[--i]:0)
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}

C,  210  192 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32?*p=l[--i]:0)
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}

C, 190 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,~*p++&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, ~*p++&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32?*p=l[--i]:0)
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}
deleted 3 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84

C,  210  192 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32 && (?*p=l[--i]):0)
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}

C,  210  192 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32 && (*p=l[--i]))
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}

C,  210  192 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32?*p=l[--i]:0)
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}
deleted 3 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84

C,  210  195192 bytes

Thanks to @l4m2 for saving 1517 bytes!

i,k,t,s;f(char*g){char char*p=g,l[strlen(g)],*p=g;for];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)&&(?*p=32):0,*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32&&(k=i;i;t&*p==32?*p=l[--i]):0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)&&(?*p=32):0, *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32 && (*p=l[--i]))
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}

C,  210  195 bytes

Thanks to @l4m2 for saving 15 bytes!

i,k,t,s;f(char*g){char l[strlen(g)],*p=g;for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)&&(*p=32),*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32&&(*p=l[--i]))t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)&&(*p=32), *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32 && (*p=l[--i]))
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}

C,  210  192 bytes

Thanks to @l4m2 for saving 17 bytes!

i,k,t,s;f(char*g){char*p=g,l[strlen(g)];for(s=t=0;*p;*p>35&&(t?l[i++]=*p:1)?*p=32:0,*p++-35&t&&++s)t^=*p==35;for(k=i;i;t&*p==32?*p=l[--i]:0)t^=*--p==35;printf("%s\n%d",g,k?k-s?k*2<s?1:2:3:0);}

Outputs 0 for empty glass, 1 for mostly empty, 2 for mostly full, and 3 for full.

First loops through the input string counting the space inside the glass, marking down letters that are inside the glass, and changing all letters to spaces. Then loops through the string backwards placing all the letters that were in the glass at the bottom of the glass.

Try it online!

Unrolled:

i,k,t,s;
f(char*g)
{
    char l[strlen(g)], *p=g;
    for (s=t=0; *p; *p>35&&(t?l[i++]=*p:1)?*p=32:0, *p++-35&t&&++s)
        t ^= *p==35;
    for (k=i; i; t&*p==32 && (*p=l[--i]))
        t ^= *--p==35;
    printf("%s\n%d", g, k?k-s?k*2<s?1:2:3:0);
}
deleted 8 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading
added 49 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading
added 276 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading
added 276 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading
deleted 5 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading
added 40 characters in body
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading
Source Link
Steadybox
  • 16.5k
  • 5
  • 41
  • 84
Loading