/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 0; tab-width: 4 -*-  */
/*
 * shannon.c
 * Copyright (C) 2018 TikalonLLC <gualtieri@ieee.org>
 * 
 * Shannon is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Shannon is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
 References:
 The American Mathematical Monthly, vol. 40, No. 8 (October, 1933), pp. 491-492.
 The American Mathematical Monthly, vol. 41, No. 3 (March, 1934), pp. 191-192.
 */

#include <stdio.h>
#include <time.h>
#include <math.h>

int J,L,M,N,R,S,T,U,X,Y;
float tmp;
int   tmp_mod;
clock_t start;
clock_t stop;


int testShannon(int J, int L, int M, int N, int R, int S, int T, int U, int X, int Y)
{
    if(((100*U*L)+(10*U*M)+(U*N))==((1000*R)+(100*T)+(10*Y)+X))
    {
        if((((100*S)+(10*T)+(U))-((100*T)+(10*Y)+X) == ((100*T)+(10*Y)+Y)) )
        {
            if(((100*X*L)+(10*X*M)+(X*N))==((1000*T)+(100*Y)+(10*Y)+J))
            {
                if((N-J)==Y)
                {
                    return 1;
                }
            }
        }
    }

    return 0;
}



int main()
{
    start = clock();

    for (L=0;L<10;L++)
    {
        for (M=0;M<10;M++)
        {
            for (N=0;N<10;N++)
            {
                for (R=0;R<10;R++)
                {
                    for (S=0;S<10;S++)
                    {
                        for (T=0;T<10;T++)
                        {
                            for (U=1;U<10;U++)
                            {
                                if( (R*S*T*U*N) != 0)
                                {
                                    tmp     = (float)((R*10000) + (S*1000) + (T*100) + (U*10) + N) / (float)( (L*100) + (M*10) + N);
                                    tmp_mod = ((R*10000) + (S*1000) + (T*100) + (U*10) + N) % ( (L*100) + (M*10) + N);
                                    
                                    if( (tmp > 9) && (tmp < 100) && (tmp_mod < 10) )
                                    {
                                        for (J=0;J<10;J++)
                                        {
                                            for (U=1;U<10;U++)
                                            {
                                                for (X=1;X<10;X++)
                                                {
                                                    for (Y=1;Y<10;Y++)
                                                    {
                                                        if( testShannon(J, L, M, N, R, S, T, U, X, Y) )
                                                        {
                                                            printf("J = %d\tL = %d\tM = %d\tN = %d\tR = %d\tS = %d\tT = %d\tU = %d\tX = %d\tY = %d\n",J,L,M,N,R,S,T,U,X,Y);
                                                            stop = clock();
                                                            printf("Elapsed time to program end (sec) = %f\n",(double)(stop - start)/1E6);
                                                            return 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                                    
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }



    return 0;
}
