My code is meant to unscramble words but I don't get all possible solutions [closed]











up vote
-6
down vote

favorite












I have a "solution" to a problem but I am not satisfied with it. I will first pose the question, show my solution, and then explain my issues with my solution.



Question:
In a computer network, data must be transmitted between different nodes (devices). Unfortunately, this is not an error-proof
process. Transmission problems can garble a message, leading to errors in the data that is received. Luckily, the errors are
(usually) randomly distributed, so they will occur in different places each time a message is transmitted. By transmitting
the same message multiple times and comparing the results, we can gather data that will help us to reconstruct the original
message. To do this, we examine each position of each message copy. The value that occurs most frequently in a specific
position is (usually) the correct value for that position.
For example, consider the following repeated/retransmitted message (in this example, spaces have been inserted between
each letter for clarity):



f e l n o w o w l d



h e j w o a p r o d



g e l q h w k b p y



h p r s e w o r l d



h e l l b m o r l d



h e g l o x l r h d



h h l l o w e r k u



h t l k q w x s l d



In the first column/position, we have 1 f, 1 g, and 6 h’s. Since "h" is the most common value for the first letter, we can guess
that the first letter of the original message was most likely "h". The second position has 5 e’s, 1 h, 1 p, and 1 t, so "e" is the
most likely second character. Repeat this process for each position in the message copies. In this case, the original message
turns out to be "helloworld".
Complete the recoverMessage() function, which takes a list of equal-length strings as its single argument. You may
assume that each string ONLY contains lowercase letters; there are no spaces, digits, uppercase letters, or punctuation
symbols in any of the source strings The function returns a single string whose length is equal to that of any one of the
source strings.



My solution:



def recoverMessage(x):
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
unscrambled = ""
sidestring = ""
for i in range(len(x[0])):
for j in range(len(x)):
alphabet[x[j][i]] = alphabet[x[j][i]] + 1
y = max(alphabet.values())
for letters in alphabet:
if alphabet.get(letters) == y:
sidestring = sidestring + letters
unscrambled = unscrambled + sidestring[0]

sidestring = ""
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}

return (unscrambled)


The issue I have with my solution is that it doesn't output all possible solutions. For example, if you manually do this for the function call



recoverMessage(["citputejncienje", "cebautersmjynzt",


"comcntewsciunwb", "foxuuterscienfe",
"jomvuzerociiavn", "tojeotesstfdiqe",
"computezsciryce"]),



you should get computerscienje OR
computerscience. My issue is in my code I incorporate the max function. But a tie could result. How can I save all these letters that come in a tie and output all possible "correct" words.










share|improve this question













closed as off-topic by 200_success, Jamal Dec 8 at 6:38


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    Broken code is off-topic for Code Review.
    – 200_success
    Dec 8 at 5:49










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    Dec 8 at 5:51






  • 1




    See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    Dec 8 at 5:52










  • @200_success My code does not output all solutions it output ones. It does indeed output a correct solution. I am asking for a user to cleverly go around to get all solutions. So no, it is not broken.
    – GentGjonbalaj
    Dec 8 at 5:54






  • 2




    It is very much broken, because the standard here is that the code must produce the intended output to be considered on-topic, and you are clearly asking for debugging help, which we do not provide here.
    – 200_success
    Dec 8 at 5:55















up vote
-6
down vote

favorite












I have a "solution" to a problem but I am not satisfied with it. I will first pose the question, show my solution, and then explain my issues with my solution.



Question:
In a computer network, data must be transmitted between different nodes (devices). Unfortunately, this is not an error-proof
process. Transmission problems can garble a message, leading to errors in the data that is received. Luckily, the errors are
(usually) randomly distributed, so they will occur in different places each time a message is transmitted. By transmitting
the same message multiple times and comparing the results, we can gather data that will help us to reconstruct the original
message. To do this, we examine each position of each message copy. The value that occurs most frequently in a specific
position is (usually) the correct value for that position.
For example, consider the following repeated/retransmitted message (in this example, spaces have been inserted between
each letter for clarity):



f e l n o w o w l d



h e j w o a p r o d



g e l q h w k b p y



h p r s e w o r l d



h e l l b m o r l d



h e g l o x l r h d



h h l l o w e r k u



h t l k q w x s l d



In the first column/position, we have 1 f, 1 g, and 6 h’s. Since "h" is the most common value for the first letter, we can guess
that the first letter of the original message was most likely "h". The second position has 5 e’s, 1 h, 1 p, and 1 t, so "e" is the
most likely second character. Repeat this process for each position in the message copies. In this case, the original message
turns out to be "helloworld".
Complete the recoverMessage() function, which takes a list of equal-length strings as its single argument. You may
assume that each string ONLY contains lowercase letters; there are no spaces, digits, uppercase letters, or punctuation
symbols in any of the source strings The function returns a single string whose length is equal to that of any one of the
source strings.



My solution:



def recoverMessage(x):
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
unscrambled = ""
sidestring = ""
for i in range(len(x[0])):
for j in range(len(x)):
alphabet[x[j][i]] = alphabet[x[j][i]] + 1
y = max(alphabet.values())
for letters in alphabet:
if alphabet.get(letters) == y:
sidestring = sidestring + letters
unscrambled = unscrambled + sidestring[0]

sidestring = ""
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}

return (unscrambled)


The issue I have with my solution is that it doesn't output all possible solutions. For example, if you manually do this for the function call



recoverMessage(["citputejncienje", "cebautersmjynzt",


"comcntewsciunwb", "foxuuterscienfe",
"jomvuzerociiavn", "tojeotesstfdiqe",
"computezsciryce"]),



you should get computerscienje OR
computerscience. My issue is in my code I incorporate the max function. But a tie could result. How can I save all these letters that come in a tie and output all possible "correct" words.










share|improve this question













closed as off-topic by 200_success, Jamal Dec 8 at 6:38


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    Broken code is off-topic for Code Review.
    – 200_success
    Dec 8 at 5:49










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    Dec 8 at 5:51






  • 1




    See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    Dec 8 at 5:52










  • @200_success My code does not output all solutions it output ones. It does indeed output a correct solution. I am asking for a user to cleverly go around to get all solutions. So no, it is not broken.
    – GentGjonbalaj
    Dec 8 at 5:54






  • 2




    It is very much broken, because the standard here is that the code must produce the intended output to be considered on-topic, and you are clearly asking for debugging help, which we do not provide here.
    – 200_success
    Dec 8 at 5:55













up vote
-6
down vote

favorite









up vote
-6
down vote

favorite











I have a "solution" to a problem but I am not satisfied with it. I will first pose the question, show my solution, and then explain my issues with my solution.



Question:
In a computer network, data must be transmitted between different nodes (devices). Unfortunately, this is not an error-proof
process. Transmission problems can garble a message, leading to errors in the data that is received. Luckily, the errors are
(usually) randomly distributed, so they will occur in different places each time a message is transmitted. By transmitting
the same message multiple times and comparing the results, we can gather data that will help us to reconstruct the original
message. To do this, we examine each position of each message copy. The value that occurs most frequently in a specific
position is (usually) the correct value for that position.
For example, consider the following repeated/retransmitted message (in this example, spaces have been inserted between
each letter for clarity):



f e l n o w o w l d



h e j w o a p r o d



g e l q h w k b p y



h p r s e w o r l d



h e l l b m o r l d



h e g l o x l r h d



h h l l o w e r k u



h t l k q w x s l d



In the first column/position, we have 1 f, 1 g, and 6 h’s. Since "h" is the most common value for the first letter, we can guess
that the first letter of the original message was most likely "h". The second position has 5 e’s, 1 h, 1 p, and 1 t, so "e" is the
most likely second character. Repeat this process for each position in the message copies. In this case, the original message
turns out to be "helloworld".
Complete the recoverMessage() function, which takes a list of equal-length strings as its single argument. You may
assume that each string ONLY contains lowercase letters; there are no spaces, digits, uppercase letters, or punctuation
symbols in any of the source strings The function returns a single string whose length is equal to that of any one of the
source strings.



My solution:



def recoverMessage(x):
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
unscrambled = ""
sidestring = ""
for i in range(len(x[0])):
for j in range(len(x)):
alphabet[x[j][i]] = alphabet[x[j][i]] + 1
y = max(alphabet.values())
for letters in alphabet:
if alphabet.get(letters) == y:
sidestring = sidestring + letters
unscrambled = unscrambled + sidestring[0]

sidestring = ""
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}

return (unscrambled)


The issue I have with my solution is that it doesn't output all possible solutions. For example, if you manually do this for the function call



recoverMessage(["citputejncienje", "cebautersmjynzt",


"comcntewsciunwb", "foxuuterscienfe",
"jomvuzerociiavn", "tojeotesstfdiqe",
"computezsciryce"]),



you should get computerscienje OR
computerscience. My issue is in my code I incorporate the max function. But a tie could result. How can I save all these letters that come in a tie and output all possible "correct" words.










share|improve this question













I have a "solution" to a problem but I am not satisfied with it. I will first pose the question, show my solution, and then explain my issues with my solution.



Question:
In a computer network, data must be transmitted between different nodes (devices). Unfortunately, this is not an error-proof
process. Transmission problems can garble a message, leading to errors in the data that is received. Luckily, the errors are
(usually) randomly distributed, so they will occur in different places each time a message is transmitted. By transmitting
the same message multiple times and comparing the results, we can gather data that will help us to reconstruct the original
message. To do this, we examine each position of each message copy. The value that occurs most frequently in a specific
position is (usually) the correct value for that position.
For example, consider the following repeated/retransmitted message (in this example, spaces have been inserted between
each letter for clarity):



f e l n o w o w l d



h e j w o a p r o d



g e l q h w k b p y



h p r s e w o r l d



h e l l b m o r l d



h e g l o x l r h d



h h l l o w e r k u



h t l k q w x s l d



In the first column/position, we have 1 f, 1 g, and 6 h’s. Since "h" is the most common value for the first letter, we can guess
that the first letter of the original message was most likely "h". The second position has 5 e’s, 1 h, 1 p, and 1 t, so "e" is the
most likely second character. Repeat this process for each position in the message copies. In this case, the original message
turns out to be "helloworld".
Complete the recoverMessage() function, which takes a list of equal-length strings as its single argument. You may
assume that each string ONLY contains lowercase letters; there are no spaces, digits, uppercase letters, or punctuation
symbols in any of the source strings The function returns a single string whose length is equal to that of any one of the
source strings.



My solution:



def recoverMessage(x):
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
unscrambled = ""
sidestring = ""
for i in range(len(x[0])):
for j in range(len(x)):
alphabet[x[j][i]] = alphabet[x[j][i]] + 1
y = max(alphabet.values())
for letters in alphabet:
if alphabet.get(letters) == y:
sidestring = sidestring + letters
unscrambled = unscrambled + sidestring[0]

sidestring = ""
alphabet = {"a" : 0, "b" : 0, "c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,
"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,
"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}

return (unscrambled)


The issue I have with my solution is that it doesn't output all possible solutions. For example, if you manually do this for the function call



recoverMessage(["citputejncienje", "cebautersmjynzt",


"comcntewsciunwb", "foxuuterscienfe",
"jomvuzerociiavn", "tojeotesstfdiqe",
"computezsciryce"]),



you should get computerscienje OR
computerscience. My issue is in my code I incorporate the max function. But a tie could result. How can I save all these letters that come in a tie and output all possible "correct" words.







python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 8 at 5:48









GentGjonbalaj

11




11




closed as off-topic by 200_success, Jamal Dec 8 at 6:38


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by 200_success, Jamal Dec 8 at 6:38


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 3




    Broken code is off-topic for Code Review.
    – 200_success
    Dec 8 at 5:49










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    Dec 8 at 5:51






  • 1




    See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    Dec 8 at 5:52










  • @200_success My code does not output all solutions it output ones. It does indeed output a correct solution. I am asking for a user to cleverly go around to get all solutions. So no, it is not broken.
    – GentGjonbalaj
    Dec 8 at 5:54






  • 2




    It is very much broken, because the standard here is that the code must produce the intended output to be considered on-topic, and you are clearly asking for debugging help, which we do not provide here.
    – 200_success
    Dec 8 at 5:55














  • 3




    Broken code is off-topic for Code Review.
    – 200_success
    Dec 8 at 5:49










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    Dec 8 at 5:51






  • 1




    See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    Dec 8 at 5:52










  • @200_success My code does not output all solutions it output ones. It does indeed output a correct solution. I am asking for a user to cleverly go around to get all solutions. So no, it is not broken.
    – GentGjonbalaj
    Dec 8 at 5:54






  • 2




    It is very much broken, because the standard here is that the code must produce the intended output to be considered on-topic, and you are clearly asking for debugging help, which we do not provide here.
    – 200_success
    Dec 8 at 5:55








3




3




Broken code is off-topic for Code Review.
– 200_success
Dec 8 at 5:49




Broken code is off-topic for Code Review.
– 200_success
Dec 8 at 5:49












@200_success What do you mean by "Broken code"? My code works.
– GentGjonbalaj
Dec 8 at 5:51




@200_success What do you mean by "Broken code"? My code works.
– GentGjonbalaj
Dec 8 at 5:51




1




1




See the the help center. Your title very obviously states that your code doesn't work correctly.
– 200_success
Dec 8 at 5:52




See the the help center. Your title very obviously states that your code doesn't work correctly.
– 200_success
Dec 8 at 5:52












@200_success My code does not output all solutions it output ones. It does indeed output a correct solution. I am asking for a user to cleverly go around to get all solutions. So no, it is not broken.
– GentGjonbalaj
Dec 8 at 5:54




@200_success My code does not output all solutions it output ones. It does indeed output a correct solution. I am asking for a user to cleverly go around to get all solutions. So no, it is not broken.
– GentGjonbalaj
Dec 8 at 5:54




2




2




It is very much broken, because the standard here is that the code must produce the intended output to be considered on-topic, and you are clearly asking for debugging help, which we do not provide here.
– 200_success
Dec 8 at 5:55




It is very much broken, because the standard here is that the code must produce the intended output to be considered on-topic, and you are clearly asking for debugging help, which we do not provide here.
– 200_success
Dec 8 at 5:55















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар