Skip to content

Instantly share code, notes, and snippets.

@aligo
Created October 20, 2012 02:51
Show Gist options
  • Select an option

  • Save aligo/3921810 to your computer and use it in GitHub Desktop.

Select an option

Save aligo/3921810 to your computer and use it in GitHub Desktop.

Revisions

  1. aligo revised this gist Oct 20, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions b.c
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,7 @@

    int main()
    {
    unsigned int i;
    unsigned int temp, base;
    unsigned long int i, temp, base;
    unsigned char j, k;
    unsigned char count[10];

  2. aligo revised this gist Oct 20, 2012. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions b.c
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@ int main()
    unsigned int i;
    unsigned int temp, base;
    unsigned char j, k;
    unsigned char str[10];
    unsigned char count[10];

    for( i = 1e9; i < 1e10; i++ )
    @@ -34,8 +33,7 @@ int main()
    {
    if (j == 9)
    {
    sprintf(str, "%010u", i);
    printf("succeeded: %s\n", str);
    printf("succeeded: %010u\n", i);
    }
    }
    else
    @@ -44,7 +42,7 @@ int main()
    }
    }
    failed:;
    // printf("tested: %s\n", str);
    // printf("tested: %010u\n", i);
    }

    return 0;
  3. aligo revised this gist Oct 20, 2012. 1 changed file with 20 additions and 5 deletions.
    25 changes: 20 additions & 5 deletions b.c
    Original file line number Diff line number Diff line change
    @@ -3,32 +3,47 @@
    int main()
    {
    unsigned int i;
    unsigned char j;
    unsigned int temp, base;
    unsigned char j, k;
    unsigned char str[10];
    unsigned char count[10];

    for( i = 1e9; i < 1e10; i++ )
    {
    memset(count, 1, 10);
    sprintf(str, "%010u", i);
    base = 1e9;
    temp = i;
    for( j = 0; j < 10; j++ )
    {
    count[(int)(str[j] - '0')]++;
    k = temp / base;
    temp = temp % base;
    base = base / 10;
    count[k]++;
    if ( count[k] > 9 ) {
    goto failed;
    }
    }
    base = 1e9;
    temp = i;
    for( j = 0; j < 10; j++ )
    {
    if ( (int)( str[j] - '0' ) == count[j] )
    k = temp / base;
    temp = temp % base;
    base = base / 10;
    if ( k == count[j] )
    {
    if (j == 9)
    {
    sprintf(str, "%010u", i);
    printf("succeeded: %s\n", str);
    }
    }
    else
    {
    break;
    goto failed;
    }
    }
    failed:;
    // printf("tested: %s\n", str);
    }

  4. aligo revised this gist Oct 20, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions b.c
    Original file line number Diff line number Diff line change
    @@ -7,17 +7,17 @@ int main()
    unsigned char str[10];
    unsigned char count[10];

    for( i = 0; i < 1e10; i++ )
    for( i = 1e9; i < 1e10; i++ )
    {
    memset(count, 0, 10);
    memset(count, 1, 10);
    sprintf(str, "%010u", i);
    for( j = 0; j < 10; j++ )
    {
    count[(int)(str[j] - '0')]++;
    }
    for( j = 0; j < 10; j++ )
    {
    if ( (int)( str[j] - '0' ) == ( count[j] + 1 ) )
    if ( (int)( str[j] - '0' ) == count[j] )
    {
    if (j == 9)
    {
  5. aligo created this gist Oct 20, 2012.
    36 changes: 36 additions & 0 deletions b.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #include <stdio.h>

    int main()
    {
    unsigned int i;
    unsigned char j;
    unsigned char str[10];
    unsigned char count[10];

    for( i = 0; i < 1e10; i++ )
    {
    memset(count, 0, 10);
    sprintf(str, "%010u", i);
    for( j = 0; j < 10; j++ )
    {
    count[(int)(str[j] - '0')]++;
    }
    for( j = 0; j < 10; j++ )
    {
    if ( (int)( str[j] - '0' ) == ( count[j] + 1 ) )
    {
    if (j == 9)
    {
    printf("succeeded: %s\n", str);
    }
    }
    else
    {
    break;
    }
    }
    // printf("tested: %s\n", str);
    }

    return 0;
    }