Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,622 members, 7,823,735 topics. Date: Friday, 10 May 2024 at 02:09 PM

Facebook Programming Challenge Question - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Facebook Programming Challenge Question (7608 Views)

Programming Challenge For Beginners Competition Two N20000 -SEASON 2- / Programming Challenge For Beginners N20000 / English Language Programming Challenge (2) (3) (4)

(1) (Reply) (Go Down)

Facebook Programming Challenge Question by eazyd(m): 3:38am On Sep 08, 2012
Test your skills- use your fav language.

Facebook Programming Challenge
Back to Question List Time Remaining: 01:42:32
Question 1 / 1

Mastermind is a game of two players. In the beginning, first player decides a secret key, which is a sequence (s1,s2,...sk) where 0 < si <= n, Then second player makes guesses in rounds, where each guess is of form (g1,g2, ...gk), and after each guess first player calculates the score for the guess. Score for a guess is equal to number of i's for which we have gi = si.

For example if the secret key is (4,2,5,3,1) and the guess is (1,2,3,7,1),then the score is 2, because
g2 = s2 and g5 = s5.

Given a sequence of guesses, and scores for each guess, your program must decide if there exists at least one secret key that generates those exact scores.

Input

First line of input contains a single integer C (1 <=C <= 100). C test-cases follow. First line of each test-case contains three integers n,k and q. (1 <=n,k <=11, 1<=q<=8 ). Next q lines contain the guesses.

Each guess consists of k integers gi,1, gi,2,....gi,k separated by a single space, followed by the score for the guess bi (1 <= gi,j <=n for all 1 <=i <=q, 1 <=j <=k; and 0 <= bi <=k )

Output

For each test-case, output "Yes" (without quotes), if there exists at least a secret key which generates those exact scores, otherwise output "No".

Sample Input
2

4 4 2
2 1 2 2 0
2 2 1 1 1
4 4 2
1 2 3 4 4
4 3 2 1 1

Sample Output

Yes
No
Re: Facebook Programming Challenge Question by Javanian: 9:23pm On Sep 08, 2012
I just decided to give it a try, although am not sure its correct

import java.util.Scanner;
public class puzzule
{
int NumberOfGuessesAllowed;
int guessedNumbers;
static int numberOfCases;
int N;
int K;
int Q;
static Scanner read;
int[] guess;
int[] answer;
boolean compare;

public static void main(String[] args)
{
puzzule p = new puzzule();

System.out.println("Enter a number from 1 to 100"wink;
read = new Scanner(System.in);
int c = read.nextInt();
numberOfCases = c;

System.out.println("Enter the first test case(n): (1<=n)"wink;
int n = read.nextInt();

System.out.println("Enter the second test case(k): (k<=11)"wink;
int k = read.nextInt();

System.out.println("Enter the third test case(q): (1<=q<=cool"wink;
int q = read.nextInt();

for(int i =0; i<numberOfCases; i++)
{
p.validateTestCases(n, k, q);
System.out.println("Starting Number test " + (i+1) + "/" + numberOfCases + "..."wink;
p.vailidateGuesses();
p.validateAnswers();
p.compareGuessesAndAnswers();
System.out.println(""wink;
}
}
public void validateTestCases(int n, int k, int q)
{
if(1<=n && k<=11 && (1<=q && q<=cool)
{
System.out.println("Test passed...."wink;
}
else
{
System.out.println("You Values did not pass the validation test"wink;
System.exit(0);
}
NumberOfGuessesAllowed = q;
guessedNumbers = k;
N = n;
K = k;
Q = q;
}
public void vailidateGuesses()
{
guess = new int[guessedNumbers];

{
for(int i =0; i<guessedNumbers; i++)
{
System.out.println("Enter No " + (i+1) + " guess"wink;
guess[i]= read.nextInt();
if(guess[i]<1)
{
System.out.println("You Values did not pass the validation test"wink;
System.exit(0);
}
}
}
}
public void validateAnswers()
{
answer = new int[guessedNumbers];
for(int i =0; i<guessedNumbers; i++)
{
System.out.println("Enter No " + (i+1) + " answer"wink;
answer[i]= read.nextInt();
if(answer[i]>guessedNumbers)
{
System.out.println("You Values did not pass the validation test"wink;
System.exit(0);
}
}
}
public void compareGuessesAndAnswers()
{
for(int i =0; i< guessedNumbers; i++)
{

if(compare=guess[i]==answer[i]==true)
{
break;
}

}
System.out.println(compare);
}

}

Re: Facebook Programming Challenge Question by Javanian: 9:28pm On Sep 08, 2012
Re: Facebook Programming Challenge Question by eazyd(m): 5:02pm On Sep 09, 2012
Javanian: http://pastebin.com/q4zJuRey

http://pastebin.ca/2202376

why this links? well still working on my code in php, will post in a few.
Re: Facebook Programming Challenge Question by Javanian: 5:38pm On Sep 09, 2012
eazyd:
why this links?
even if you have never heard of pastebin before...did you check the links?
Re: Facebook Programming Challenge Question by eazyd(m): 1:17pm On Sep 11, 2012
i jst did tho and yea i know pastebin bt i dont click on links like that..you shoulda stated the question on pastebin before posting the code.Nice job!

(1) (Reply)

A New Search Engine / Signs That You Are Not Meant To Be A Programmer / Which Programming Language Is Best For Building An Hospital Management Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.