Anagrams Problem

Back to Problem Solutions forum

Curio_Amigo     2020-11-04 03:36:56

Hello Folks!!!

I got problems with the problem #127. The checker gives to me always an answer that dosen't check with mine. It's seems to be that the ckecker is programmed to gives a different answer, and I can't go through it.

Looking forward for help,

Curio Amigo

Curio_Amigo     2020-11-04 03:57:47

Hello Folks!!!

I was able gives the answer of checker's answer by change my answer gusseing an algorithm against cheat.

Please, I really wonder to know if my code is correct.

Looking Forward,

Curio_Amigo

qwerty     2020-11-05 06:34:30

I'm sorry to say that, but your code is totally wrong. I submitted it several times and it never suceeded. Seems you was lucky to have it accepted.

Try this simple test:
words.txt:
cat
act
ant
input:
cat
your program should output:
2
but it outputs:
1

Alexandr Milovantsev     2020-11-05 07:04:02

Code seems to be correct, but it definitely is not optimal.

Alexandr Milovantsev     2020-11-05 07:10:24

qwerty_one:

Answer should contain the number of anagrams for each word (not including the word itself).

Following this task condition, right answet to your test data is 1, not 2.

qwerty     2020-11-05 11:33:04

Alexander, I'm sorry, there was a lot of time after I solved this task myself, so I forgot problem statement a bit.

Still, can't agree his code is correct, as a submitted it several times and never suceeded. Perhaps after some adaptation it may work, but why I should fix third party code?

qwerty     2020-11-05 11:41:07

And even if everything is ok with his code, I feel angry that he suspects checker of foul play. Please Curio Amigo, never do that ever again. Think about it, so many people solved this task, and no one noticed anything suspicious about checker. Perhaps you was looking for problem in wrong way??

Alexandr Milovantsev     2020-11-05 16:00:55

So, I downloaded Curio_Amigo code, run it and have to say that it is wrong indeed. Curio, method of counting anagrams using permutations gives excess positives counts with words containing the same letter sever times. For example, if I use dictionary with only one word "chupakabra" and test the same word "chupakabra", than your program gives output 5 and expected output is 0.

Curio_Amigo     2020-11-07 02:49:04

Sorry about that qwerty_one! I dind't mean the checker is playing against the people whom try harder to learn how to do a good codes.

I'm using Python's itertools module . I've imported it into my code and work wit it.

I pressume that the shuffling with the words is going wrong, wich I doubt, or, what I am belive most, the iteration with the dictionarie is going wrong. I will try harder do try to find the trouble but please, I am not cheat any tasks in this wonderful website.

I am still learn how to do good codes in Python and I am working to growing my knowledgs in this marvelous language.

Thanks for all comments!

Curio_Amigo

Curio_Amigo     2020-11-07 04:09:46

Helloe dears!!!

I was able to solve the task. I don't know exactlly why the reason of the error before, but I achanged the items append in a lista by instead using sets to append items and the result was correct.

By the way, I had to setup the incremment as -1 to eliminate empty set, and my list had not anymore repeated items.

Thanks you so much for your help.

I will post the correct code!

Curio_Amigo

Alexandr Milovantsev     2020-11-07 13:11:18

Initialization of counter with -1 to circumvent excess increment in case of equality of test word and dictionary's one is not correct in all cases. Imagine that you will be asked to test word, which is not in dictionary and does not have anagrams in dictionary.

Than the right answer would be 0 and your program answer would be -1.

Alexandr Milovantsev     2020-11-07 13:28:23

If you want to increase your programming skill, try to find a way to check if two words are anagrams without using permutations at all. Then you can move this code to separated function to clear code. And you will understand that this task is quiet easy!

Curio_Amigo     2020-11-07 17:44:04

All rigth Alexandr!!!

I'll try to do the task like you said.

Thanks a lot!!!

qwerty     2020-11-08 07:52:34

I'm sorry too, for being not very kind to you.

And Alexander is right, there is an another way to check if two words are anagrams.

Curio_Amigo     2020-11-09 00:13:38

Hello my dear friends, that's fine, you are rigth to stand defending this great site, the CodeAbbey website.

I was think wrong about this task. I was counting the words given and yours anagrams.

The task is to find out the amount of anagrams for a determined word given wich can be found in the dictionary.

I made some changes in the code.

I will post it again the correct code.

Thanks a lot for yours supports.

Please login and solve 5 problems to be able to post at forum