For all you C# geeks: Knock yourselves out [modified]
-
My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes. ;)
Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
Write a command-line program as follows:First the program will take as input a +ve integer from the user, let's call it
the TARGET.It will then take in a set of +ve integers from the user, and here the user gets
to specify how many integers he/she wants to enter. Let's call this set the
RANGE.Now the program should compute as follows:
-
Find all combinations in the RANGE, the sum of which add up to the
target. Print such combinations at the command prompt. In a combination,
repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
in the combination must be unique. -
In case a user enters a RANGE element greater than the target, it should be immediately
discarded and the user must be prompted for the element again. -
Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
separately is unnecessary and MUST be avoided. -
In case no combinations exist, the program should report so.
-
Add exception handling code where necessary.
Example Run:
Enter Target: 15
How many set elements?: 5
Enter Element1: 7
Enter Element2: 8
Enter Element3: 12
Enter Element4: 3
Enter Element5: 22
Sorry. That element is larger than your target. Try again.
Enter Element5: 4Combinations are:
1] 7+8
2] 8+3+4
3] 12+3Time: 45 mins.
(At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)
modified on Tuesday, November 4, 2008 2:13 PM
-
-
My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes. ;)
Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
Write a command-line program as follows:First the program will take as input a +ve integer from the user, let's call it
the TARGET.It will then take in a set of +ve integers from the user, and here the user gets
to specify how many integers he/she wants to enter. Let's call this set the
RANGE.Now the program should compute as follows:
-
Find all combinations in the RANGE, the sum of which add up to the
target. Print such combinations at the command prompt. In a combination,
repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
in the combination must be unique. -
In case a user enters a RANGE element greater than the target, it should be immediately
discarded and the user must be prompted for the element again. -
Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
separately is unnecessary and MUST be avoided. -
In case no combinations exist, the program should report so.
-
Add exception handling code where necessary.
Example Run:
Enter Target: 15
How many set elements?: 5
Enter Element1: 7
Enter Element2: 8
Enter Element3: 12
Enter Element4: 3
Enter Element5: 22
Sorry. That element is larger than your target. Try again.
Enter Element5: 4Combinations are:
1] 7+8
2] 8+3+4
3] 12+3Time: 45 mins.
(At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)
modified on Tuesday, November 4, 2008 2:13 PM
-
-
My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes. ;)
Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
Write a command-line program as follows:First the program will take as input a +ve integer from the user, let's call it
the TARGET.It will then take in a set of +ve integers from the user, and here the user gets
to specify how many integers he/she wants to enter. Let's call this set the
RANGE.Now the program should compute as follows:
-
Find all combinations in the RANGE, the sum of which add up to the
target. Print such combinations at the command prompt. In a combination,
repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
in the combination must be unique. -
In case a user enters a RANGE element greater than the target, it should be immediately
discarded and the user must be prompted for the element again. -
Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
separately is unnecessary and MUST be avoided. -
In case no combinations exist, the program should report so.
-
Add exception handling code where necessary.
Example Run:
Enter Target: 15
How many set elements?: 5
Enter Element1: 7
Enter Element2: 8
Enter Element3: 12
Enter Element4: 3
Enter Element5: 22
Sorry. That element is larger than your target. Try again.
Enter Element5: 4Combinations are:
1] 7+8
2] 8+3+4
3] 12+3Time: 45 mins.
(At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)
modified on Tuesday, November 4, 2008 2:13 PM
You should stick this over in Math & Algs. The interesting bit here is how your candidates go about solving the subset-sum problem, which is NP-Complete. The input half would be done in first year uni.
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Alpha release: Entanglar: Transparant multiplayer framework for .Net games. -