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











up vote
-3
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







New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Broken code is off-topic for Code Review.
    – 200_success
    16 mins ago










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    14 mins ago










  • See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    13 mins ago










  • @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
    11 mins ago










  • 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
    9 mins ago















up vote
-3
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







New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Broken code is off-topic for Code Review.
    – 200_success
    16 mins ago










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    14 mins ago










  • See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    13 mins ago










  • @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
    11 mins ago










  • 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
    9 mins ago













up vote
-3
down vote

favorite









up vote
-3
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







New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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







New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 16 mins ago









GentGjonbalaj

11




11




New contributor




GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






GentGjonbalaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Broken code is off-topic for Code Review.
    – 200_success
    16 mins ago










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    14 mins ago










  • See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    13 mins ago










  • @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
    11 mins ago










  • 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
    9 mins ago














  • 1




    Broken code is off-topic for Code Review.
    – 200_success
    16 mins ago










  • @200_success What do you mean by "Broken code"? My code works.
    – GentGjonbalaj
    14 mins ago










  • See the the help center. Your title very obviously states that your code doesn't work correctly.
    – 200_success
    13 mins ago










  • @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
    11 mins ago










  • 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
    9 mins ago








1




1




Broken code is off-topic for Code Review.
– 200_success
16 mins ago




Broken code is off-topic for Code Review.
– 200_success
16 mins ago












@200_success What do you mean by "Broken code"? My code works.
– GentGjonbalaj
14 mins ago




@200_success What do you mean by "Broken code"? My code works.
– GentGjonbalaj
14 mins ago












See the the help center. Your title very obviously states that your code doesn't work correctly.
– 200_success
13 mins ago




See the the help center. Your title very obviously states that your code doesn't work correctly.
– 200_success
13 mins ago












@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
11 mins ago




@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
11 mins ago












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
9 mins ago




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
9 mins ago















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






GentGjonbalaj is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209257%2fmy-code-is-meant-to-unscramble-words-but-i-dont-get-all-possible-solutions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








GentGjonbalaj is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















GentGjonbalaj is a new contributor. Be nice, and check out our Code of Conduct.













GentGjonbalaj is a new contributor. Be nice, and check out our Code of Conduct.












GentGjonbalaj is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209257%2fmy-code-is-meant-to-unscramble-words-but-i-dont-get-all-possible-solutions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python