//	This source and compression method apply to GNU General Public License. 
//			Copyright (C) 2010 and later by Jasenko Dzinleski 



//		This program 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 2 of the
//	License, or (at your option) any later version. 

//	This program 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, write to the Free Software Foundation, Inc.,
//	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.



//
//			binary factor number merit scale routine
//			written by Dzinleski Jasenko December,2010
//
//			to Maria Dzinleska





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

char 	infn[255]="maria2.wav";

FILE	*f1;

int 	ba16[16][16][16][16][2];	int	ba16i=0;

int		b12=((0xffff>>4 )<<4 );
int		b11=((0xffff>>5 )<<5 );
int		b10=((0xffff>>6 )<<6 );
int		b09=((0xffff>>7 )<<7 );
int		b08=((0xffff>>8 )<<8 );
int		b07=((0xffff>>9 )<<9 );
int		b06=((0xffff>>10)<<10);
int		b05=((0xffff>>11)<<11);
int		b04=((0xffff>>12)<<12);


int main()
{

	char	fbyte;
	int		i,j,k,l,m,n,p,r,nH,nL;
	int		a,b,c,d,e;
	int		ai,gc1,gc2,gc3,gc4;
	__int64	lb,la;
	__int64	ga[4][2];



	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l){
		ba16[i][j][k][l][0]=-1;ba16[i][j][k][l][1]=0;ba16[i][j][k][l][2]=0;
	}}}}ba16i=0;
		
	f1=fopen(infn,"rb");
	j=0;
	while(!feof(f1))
	{
		nH=getc(f1);++j;nL=getc(f1);++j;
		n=((nH<<8)&0xff00)|(nL&0x00ff);
		if(ba16[(n&0xf000)>>12][(n&0x0f00)>>8][(n&0x00f0)>>4][(n&0x000f)>>0][0]==-1)
		{
			ba16[(n&0xf000)>>12][(n&0x0f00)>>8][(n&0x00f0)>>4][(n&0x000f)>>0][0]=ba16i;
			ba16[(n&0xf000)>>12][(n&0x0f00)>>8][(n&0x00f0)>>4][(n&0x000f)>>0][1]=1;
			++ba16i;
		}else{
			++ba16[(n&0xf000)>>12][(n&0x0f00)>>8][(n&0x00f0)>>4][(n&0x000f)>>0][1];
		}
	}
	fclose(f1);

	for(i=0;i<16;++i){for(j=0;j<16;++j){for(k=0;k<16;++k){for(l=0;l<16;++l){
	
		if(ba16[i][j][k][l][0]!=-1)
		{

			n=(i<<12)|(j<<8)|(k<<4)|(l<<0);
			ga[0][0]=0;ga[0][1]=0;for(c=0;c<16;++c){if(ba16[c][j][k][l][0]!=-1){++ga[0][1];ga[0][0]+=ba16[c][j][k][l][1];}}
			ga[1][0]=0;ga[1][1]=0;for(c=0;c<16;++c){if(ba16[i][c][k][l][0]!=-1){++ga[1][1];ga[1][0]+=ba16[i][c][k][l][1];}}
			ga[2][0]=0;ga[2][1]=0;for(c=0;c<16;++c){if(ba16[i][j][c][l][0]!=-1){++ga[2][1];ga[2][0]+=ba16[i][j][c][l][1];}}
			ga[3][0]=0;ga[3][1]=0;for(c=0;c<16;++c){if(ba16[i][j][k][c][0]!=-1){++ga[3][1];ga[3][0]+=ba16[i][j][k][c][1];}}
						
			b=-1;for(a=0;a<4;++a){if(b==-1){b=ga[a][0];ai=0;}else{if(b<ga[a][0]){b=ga[a][0];ai=a;}}}

			//printf("%d ",n);

			if((ba16[i][j][k][l][1]*ga[ai][1])>0&&ga[ai][0]>0)
			{
				if(log((double)ga[ai][0]/(double)(ba16[i][j][k][l][1]*ga[ai][1]))>=1.0)
				{printf("%d\t%e\n",n,log((double)ga[ai][0]/(double)(ba16[i][j][k][l][1]*ga[ai][1])));}
			}

		}

	}}}}

	return(0);

}