Skip to main content
added 41 characters in body
Source Link
xibu
  • 601
  • 3
  • 7

C (gcc), 93 93 92 bytes

-1 Byte thanks to ceilingcat

D;I;C(N){N=N?C(N/10)+(N%10==D):0;}F(N){for(D=I=0;D<10;C(N)>C(I*I)+C(I*I*I)?D=!++I,D=0:++D);I=I;}

Try it online!Try it online!

ungolfed:

int D;
int I;

int CNT(N)  // count occurrences of digit D in number N
{
    if (N)
        return CNT(N / 10) + (N % 10 == D);
    return 0;
}

int F(N)
{
    for (D = I = 0; D < 10; ++I)
    {
        for (D = 0; D < 10; ++D)
            if (CNT(N) > CNT(I * I) + CNT(I * I * I))
                break;
    }

    return I-1;
}

C (gcc), 93 bytes

D;I;C(N){N=N?C(N/10)+(N%10==D):0;}F(N){for(D=I=0;D<10;C(N)>C(I*I)+C(I*I*I)?++I,D=0:++D);I=I;}

Try it online!

ungolfed:

int D;
int I;

int CNT(N)  // count occurrences of digit D in number N
{
    if (N)
        return CNT(N / 10) + (N % 10 == D);
    return 0;
}

int F(N)
{
    for (D = I = 0; D < 10; ++I)
    {
        for (D = 0; D < 10; ++D)
            if (CNT(N) > CNT(I * I) + CNT(I * I * I))
                break;
    }

    return I-1;
}

C (gcc), 93 92 bytes

-1 Byte thanks to ceilingcat

D;I;C(N){N=N?C(N/10)+(N%10==D):0;}F(N){for(D=I=0;D<10;C(N)>C(I*I)+C(I*I*I)?D=!++I:++D);I=I;}

Try it online!

ungolfed:

int D;
int I;

int CNT(N)  // count occurrences of digit D in number N
{
    if (N)
        return CNT(N / 10) + (N % 10 == D);
    return 0;
}

int F(N)
{
    for (D = I = 0; D < 10; ++I)
    {
        for (D = 0; D < 10; ++D)
            if (CNT(N) > CNT(I * I) + CNT(I * I * I))
                break;
    }

    return I-1;
}
Source Link
xibu
  • 601
  • 3
  • 7

C (gcc), 93 bytes

D;I;C(N){N=N?C(N/10)+(N%10==D):0;}F(N){for(D=I=0;D<10;C(N)>C(I*I)+C(I*I*I)?++I,D=0:++D);I=I;}

Try it online!

ungolfed:

int D;
int I;

int CNT(N)  // count occurrences of digit D in number N
{
    if (N)
        return CNT(N / 10) + (N % 10 == D);
    return 0;
}

int F(N)
{
    for (D = I = 0; D < 10; ++I)
    {
        for (D = 0; D < 10; ++D)
            if (CNT(N) > CNT(I * I) + CNT(I * I * I))
                break;
    }

    return I-1;
}