All pastes #538085 Raw Edit

mastermind1

public shellscript v1 · immutable
·published 2007-06-04 23:04 UTC
rendered paste body
#!/bin/bashif [ "$#" -eq 0 ]; then							#elegxos parametrwnawk '{	colors=6        for (i=0;i<4;i++)        {                pegs[i]= int((rand()*100)%colors)+40			                printf("\033[%dm      \033[0m",pegs[i])  		#na ginei sxolio        }	printf("\nGive 1=Black 2=Red 3=Green 4=Brown 5=Blue 6=Purple\n")			do	{		found_correct=0						#midenismos metritwn		found=0		i=0		while(i<4)		{			getline user_given[i]			user_given[i]=user_given[i]+39	#metatropi, na tairiazei me to pegs[i]			for(j=0;j<4;j++)			{				if (i==j)				{					if (user_given[i]== pegs[j]) 	#elegxos swstis yparksis					{						found_correct++					}				}				else				{					if (user_given[i] == pegs[j])	#elegxos yparksis					{							found++					}				}			}			i++						#epomeno peg 		}			for(i=0;i<4;i++)							{			printf("\033[%dm      \033[0m",user_given[i])	#emfanisi user_given		}		printf("\t%d / %d\n", found_correct, found)	}while(found_correct!=4)	exit }'fiif [ $# -eq 1 ]; then	awk -v temp=$1 '{		if (temp >= 10)		{			pegs_number=10		}		else		{			pegs_number=temp		}				colors=6       	 	for (i=0;i<pegs_number;i++)        	{                	pegs[i]=int(rand()*100%colors)+40                	printf("\033[%dm      \033[0m",pegs[i])  	#na ginei sxolio        	}			printf("\nGive 1=Black 2=Red 3=Green 4=Brown 5=Blue 6=Purple\n")		do		{			found_correct=0			#midenismos metritwn			found=0			i=0		while(i<pegs_number)		{			getline user_given[i]			user_given[i]=user_given[i]+39  #metatropi, na tairiazei me to pegs[i]			for(j=0;j<pegs_number;j++)			{				if (i==j)				{					if (user_given[i]==pegs[j])   #elegxos an yparxei swsta					{						found_correct++						found++					}				}				else				{						if ((user_given[i] == pegs[j]) && (i!=j))		#elegxos an yparxei genika					{							found++					}				}				}			i++		#epomeno user_given		}		for(k=0;k<pegs_number;k++)							{			printf("\033[%dm      \033[0m",user_given[k])	#emfanisi xrwmatwn xristi		}			printf("\t%d / %d\n", found, found_correct)	#emfanisi posa sta posa				}while(found_correct!=pegs_number)	exit }'fiif [ $# -eq 2 ]; thenawk -v temp1=$1 temp2=$2 '{	if(temp1>= 10)		#arithmos pegs	{		pegs_number=10	}	else	{		pegs_number=temp1	}		if(temp2>8)		#arithmos xrwmatwn	{		colors=8	}	else if(temp2<3)	{		colors=3	}	else	{		colors=temp2	}		for (i=0;i<pegs_number;i++)       	{               	pegs[i]=int(rand()*100%colors)+40               	printf("\033[%dm      \033[0m",pegs[i])  	#na ginei sxolio       	}		if(colors=3)	{		printf("\nGive 1=Black 2=Red 3=Green\n")	}	if(colors=4)	{		printf("\nGive 1=Black 2=Red 3=Green 4=Brown\n")	}	if(colors=5)	{		printf("\nGive 1=Black 2=Red 3=Green 4=Brown 5=Blue\n")	}	if(colors=6)	{		printf("\nGive 1=Black 2=Red 3=Green 4=Brown 5=Blue 6=Purple\n")	}	if(colors=7)	{		printf("\nGive 1=Black 2=Red 3=Green 4=Brown 5=Blue 6=Purple 7=Cyan\n")	}	if(colors=8)	{		printf("\nGive 1=Black 2=Red 3=Green 4=Brown 5=Blue 6=Purple 7=Cyan 8=White\n")	}	do	{		found_correct=0			#midenismos metritwn		found=0		i=0		while(i<pegs_number)		{			getline user_given[i]			user_given[i]=user_given[i]+39  #metatropi, na tairiazei me to pegs[i]						for(j=0;j<pegs_number;j++)			{				if (i==j)				{					if (user_given[i]==pegs[j])   #elegxos an yparxei swsta					{						found_correct++						found++					}				}				else				{						if ((user_given[i] == pegs[j]) && (i!=j)) #elegxos an yparxei genika					{							found++					}				}				}			i++		#epomeno user_given		}		for(k=0;k<pegs_number;k++)							{			printf("\033[%dm      \033[0m",user_given[k])	#emfanisi xrwmatwn xristi		}			printf("\t%d / %d\n", found, found_correct)	#emfanisi posa sta posa				}while(found_correct!=pegs_number)	exit }'fi