The Student Room Group

Need help writing an Algorithm for an ocr challenge? (A lvl Computer Science)

Hi,

I am having problem writing a pseudocode for a challenge question on the OCR challenges document.

Question Below!!!!

""" A thief has managed to find out the four digits for an online PIN code, but doesn’t know the correct sequence needed to hack into the account. Design and write a program that displays all the possible combinations for any four numerical digits entered by the user. The program should avoid displaying the same combination more than once.

"""

Any helps appreciated. Thanks.
Original post by Csman123
Hi,

I am having problem writing a pseudocode for a challenge question on the OCR challenges document.

Question Below!!!!

""" A thief has managed to find out the four digits for an online PIN code, but doesn’t know the correct sequence needed to hack into the account. Design and write a program that displays all the possible combinations for any four numerical digits entered by the user. The program should avoid displaying the same combination more than once.

"""

Any helps appreciated. Thanks.


Input a,b,c,d which are not necessarily unique.

Generate all the combinations and sort them in order..


<rest for you to work out>

Good luck
Reply 2
Original post by Kevin De Bruyne
Input a,b,c,d which are not necessarily unique.

Generate all the combinations and sort them in order..


<rest for you to work out>

Good luck


That would only give the lowest to highest and highest to lowest. I also want other possible combinations.

For example: if i had to find the possible combinations of 4537. If i apply your method i will only get 4357 and 3457.
Original post by Csman123
That would only give the lowest to highest and highest to lowest. I also want other possible combinations.

For example: if i had to find the possible combinations of 4537. If i apply your method i will only get 4357 and 3457.


Note that I did not give a complete method but with what I've given, I disagree with what you've said - I included a line that says 'generate all combinations'
Reply 4
Original post by Kevin De Bruyne
Note that I did not give a complete method but with what I've given, I disagree with what you've said - I included a line that says 'generate all combinations'


I would be so grateful, if you can write me an understandable pesudocode.

Thanks.
Original post by Csman123
I would be so grateful, if you can write me an understandable pesudocode.

Thanks.


Then you would not be able to reproduce one in the exam.

I've given you a conceptual start (kind of in pseudocode.. pretty much..) and you understand that, from what I have written, there are all the possible combinations of the 4 numbers sorted in order and now you just need to finish it off...

Happy to answer any questions but not prepared to do any work for you - it's against the ethos of the study help forum and also not good for your own learning.
Reply 6
Original post by Kevin De Bruyne
Then you would not be able to reproduce one in the exam.

I've given you a conceptual start (kind of in pseudocode.. pretty much..) and you understand that, from what I have written, there are all the possible combinations of the 4 numbers sorted in order and now you just need to finish it off...

Happy to answer any questions but not prepared to do any work for you - it's against the ethos of the study help forum and also not good for your own learning.


Thanks for your reply. Using inbuilt functions in VB. Net I have managed to create a program that works fine. However I am not sure how to write that into pseudocode. Can I state in the pesudocode that I've made use of inbuilt functions, and is that allowed?

Thanks.
Reply 7
you could use a recursive algorithm that takes an input array (called arr) containing the digits and an optional input string called s.

rough pseudocode for the algorithm
display(arr, s):
if arr is empty:
print(s)

else:
for i in arr:
display(arr with i removed, s+i)


you could also use dynamic programming (memoisation) to make this more efficient
(edited 6 years ago)

Quick Reply

Latest