Topic: Challenge to all d programmers out dere.....
varun1varun's photo
Sat 01/04/14 08:31 AM
create a program for:
(u can use any language...)
There's a chemist , author ,doctor , biologist,,,
Mohit, Rajesh, Samarth and Udit are at their monthly business meeting. Their occupations are author, biologist, chemist and doctor, but not necessarily in that order. Udit just told the biologist that Samarth was on his way to home. Mohit is sitting across from the doctor and next to the chemist. The doctor was thinking that Rajesh was a very good name for parent's to choose, but didn't say anything. What is each person's occupation?

roden01's photo
Sun 01/19/14 11:44 PM
Edited by roden01 on Sun 01/19/14 11:45 PM

create a program for:
(u can use any language...)
There's a chemist , author ,doctor , biologist,,,
Mohit, Rajesh, Samarth and Udit are at their monthly business meeting. Their occupations are author, biologist, chemist and doctor, but not necessarily in that order. Udit just told the biologist that Samarth was on his way to home. Mohit is sitting across from the doctor and next to the chemist. The doctor was thinking that Rajesh was a very good name for parent's to choose, but didn't say anything. What is each person's occupation?


Using Pseudocode:

// Set up arrays for the professions and people

Professions = array('Chemist', 'Author', 'Doctor', 'Biologist');
People = array('Mohit', 'Rajesh', 'Samarth', 'Udit');

// Initialise loop counter variables

k = 0;
j = 0;

// Loop through all people professions and set all values to 0

while k < length(Professions)
while j < length(People)
Matrix[k][j] = 0;
j++;
k++;

// Fill in the information available, setting true to 1, false to -1
// The example below uses named references for clarity, but you would need to find the numeric array reference that corresponds with the text in the profession and people arrays.

Matrix['Biologist']['Udit'] = -1 // Udit is speaking to the biologist
Matrix['Biologist'['Samarth'] = -1 // The biologist is told about Samarth
Matrix['Doctor']['Mohit'] = -1 // Mohit is across from the Doctor
Matrix['Chemist']['Mohit'] = -1 // Mohit is next to the Chemist
Matrix['Doctor']['Rajesh'] = -1 // The doctor is presumably called Rajesh
Matrix['Doctor']['Samarth'] = -1 // Samarth is on his way home so cannot be sitting across from Mohit
Matrix['Chemist']['Samarth'] = -1 // Samarth is on his way home so cannot be sitting next to Mohit

// From here, create function CheckLine() to search for
// (a) a value of 1 in a row or column, and call a function to set the rest of the row or column to -1 (one person per role)
// (b) three values of -1, meaning that the fourth value must be 1 (at least one of the four people must fill the role)
// $row is passed as a parameter to switch from checking values in rows to values in columns.

CheckLine($row = True)
{
$tempcounter = 0; // used to check for completeness, reset each function call

// check for rows/columns that do not have a value equivalent to 0 (===), and if so, increment $tempcounter by 1
// else if the row/column has a value of 1, ensure all other values in that row and column are set to -1
// else if the count of '-1' in the row/column is (n-1), in this case 3, set the remaining value to 1 and mark all other column/row values to -1
// if all rows are checked, and the counter equals the number of rows, the program can end, otherwise call CheckRows recursively, alternating between row and column, to start again. E.g.
// if $row == True: CheckLine(False); else CheckLine(True);
}

The result is as follows:

1. Samarth is not a biologist, doctor or chemist, so must be an author.
2. The doctor is not Samarth, Mohit or Rajesh, so must be Udit.
3. Once the appropriate values are set to 1, a subsequent loop will place a value of -1 for Udit as a chemist/author, and Mohit/Rajesh as an author.
4. Mohit becomes the biologist, and Rajesh becomes the chemist.
5. The remaining entry for Rajesh vs the biologist is marked as -1 and the program can end.

The program can be extended by counting the number of names and roles.

---

Any programmer chicks out there?

Mirage4279's photo
Wed 01/22/14 11:57 PM
Edited by Mirage4279 on Thu 01/23/14 12:01 AM


create a program for:
(u can use any language...)
There's a chemist , author ,doctor , biologist,,,
Mohit, Rajesh, Samarth and Udit are at their monthly business meeting. Their occupations are author, biologist, chemist and doctor, but not necessarily in that order. Udit just told the biologist that Samarth was on his way to home. Mohit is sitting across from the doctor and next to the chemist. The doctor was thinking that Rajesh was a very good name for parent's to choose, but didn't say anything. What is each person's occupation?


Using Pseudocode:

// Set up arrays for the professions and people

Professions = array('Chemist', 'Author', 'Doctor', 'Biologist');
People = array('Mohit', 'Rajesh', 'Samarth', 'Udit');

// Initialise loop counter variables

k = 0;
j = 0;

// Loop through all people professions and set all values to 0

while k < length(Professions)
while j < length(People)
Matrix[k][j] = 0;
j++;
k++;

// Fill in the information available, setting true to 1, false to -1
// The example below uses named references for clarity, but you would need to find the numeric array reference that corresponds with the text in the profession and people arrays.

Matrix['Biologist']['Udit'] = -1 // Udit is speaking to the biologist
Matrix['Biologist'['Samarth'] = -1 // The biologist is told about Samarth
Matrix['Doctor']['Mohit'] = -1 // Mohit is across from the Doctor
Matrix['Chemist']['Mohit'] = -1 // Mohit is next to the Chemist
Matrix['Doctor']['Rajesh'] = -1 // The doctor is presumably called Rajesh
Matrix['Doctor']['Samarth'] = -1 // Samarth is on his way home so cannot be sitting across from Mohit
Matrix['Chemist']['Samarth'] = -1 // Samarth is on his way home so cannot be sitting next to Mohit

// From here, create function CheckLine() to search for
// (a) a value of 1 in a row or column, and call a function to set the rest of the row or column to -1 (one person per role)
// (b) three values of -1, meaning that the fourth value must be 1 (at least one of the four people must fill the role)
// $row is passed as a parameter to switch from checking values in rows to values in columns.

CheckLine($row = True)
{
$tempcounter = 0; // used to check for completeness, reset each function call

// check for rows/columns that do not have a value equivalent to 0 (===), and if so, increment $tempcounter by 1
// else if the row/column has a value of 1, ensure all other values in that row and column are set to -1
// else if the count of '-1' in the row/column is (n-1), in this case 3, set the remaining value to 1 and mark all other column/row values to -1
// if all rows are checked, and the counter equals the number of rows, the program can end, otherwise call CheckRows recursively, alternating between row and column, to start again. E.g.
// if $row == True: CheckLine(False); else CheckLine(True);
}

The result is as follows:

1. Samarth is not a biologist, doctor or chemist, so must be an author.
2. The doctor is not Samarth, Mohit or Rajesh, so must be Udit.
3. Once the appropriate values are set to 1, a subsequent loop will place a value of -1 for Udit as a chemist/author, and Mohit/Rajesh as an author.
4. Mohit becomes the biologist, and Rajesh becomes the chemist.
5. The remaining entry for Rajesh vs the biologist is marked as -1 and the program can end.

The program can be extended by counting the number of names and roles.

---

Any programmer chicks out there?






:laughing:

Your psuedocode reminds of my first year in java LoL....


It's just the way you set the variables as a two dimensional array with length of persons and length of professions as opposed to something simple such as

String bobsProf;
String joesProf;
String garysProf;


so on and so forth... and turning it into a 2d array LoL....



Mirage4279's photo
Thu 01/23/14 12:06 AM
The question is very hard to program for and not for beginners...

DaveCatalina's photo
Sat 02/01/14 07:52 PM
When I post a reply here, how do I embed a picture from my computer into the post?

no photo
Sat 02/08/14 06:08 AM
try to type:
death 00
01of
server02
03like
cuted04
05duck
you can root