All pastes #537947 Raw Edit

mastermind

public shellscript v1 · immutable
·published 2007-06-04 22:07 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=Yellow 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 wste na tairiazei me to pegs[i]			for(j=0;j<4;j++)			{				if (i==j)				{					if (user_given[i]== pegs[j]) 	#elegxos an yparxei sto idio simeio					{						found_correct++					}				}				else				{					if (user_given[i] == pegs[j])	#elegxos an yparxei genika					{							found++					}				}			}			i++						#auksisi tou metriti 		}			for(i=0;i<4;i++)							{			printf("\033[%dm      \033[0m",user_given[i])	#emfanisi xrwmatwn xristi		}		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=Yellow 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 wste 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 sto #idio simeio					{						found_correct++						found++					}				}				else				{						if ((user_given[i] == pegs[j]) && (i!=j))		#elegxos an yparxei genika					{							found++					}				}				}			i++		#auksisi tou metriti 		}		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