6 kyu
Check if two words are isomorphic to each other
670 of 1,456rasmus_ri
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Failed test with a = "ABCBACCBA" and b = "ABCBACCAB": True should equal False Expected True
Your solution does not solve the problem. It's not just about counting the characters, it's also about checking if the corresponding characters are in the same locations thorough the string. In your example, the strings are not isomorphic because one string cannot be turned into the other by changing every occurrence of one letter to another letter:
Either i'm missing something or this kata has a bug. I am passing all but 9 tests.
This example is failing: 'a: ABCBACCBA b: ABCBACCAB'. (1 1 1 1 1 2 1 1)
The patterns and length match up perfectly here so im returning true, but it's expecting false? I've been racking my brain over this for a while now and re-reading the instructions. I cannot figure out how this is expected to be false. Any advise?
Those two strings are not isomorphic, you cannot get from one to the other with a 1:1 substitution cipher.
ahh, I see it now! Thanks
Scala translation
CoffeeScript translation
zhaev ikfdp whhyyyyy it`s true .......
Because each string can be mapped 1:1 with the other string
There's an issue with random tests on Ruby. It shows the error message when trying to submit.
Adding "require 'set'" to the solution solves the problem, but I am not using 'set' in my solution, so it seems that the reference solution simply forces me to require an unnecessary module.
idk ruby but I moved that method since it has no business being in preloaded, as well as added the import: ruby fork
need someone to press green shiny button.
your fork has been approved
issue fixed
This one messed with me for a while. Nice kata.
No one doesn't ask. What is the isomorphic word at this kata? I looked to what is the isomorphic from internet? But it isn't same with this kata. So I think the description must give more information about isomorphic.
Lua translation
Why is RAMBUNCTIOUSLY THERMODYNAMICS True but AB CC is not?
I assumed the Q meant each letter in a can only map to one other letter in b. E.g: A -> B or D -> Z but NOT: A -> B and Z -> B.
This is clearly stated in the first paragraph of the description.
....and reverse: in the first example, R in the first word can be mapped only to T in the second word, and T in the second word can be mapped only to R in the first word.
In your example, C from the second word cannot be unambiguously mapped to any letter from the first word.
Now I read the description, I am not exactly sure about whether it's clear enough. I think it puts pressure on the mapping only in one direction (from A to B), but I am not sure which part would clearly state that B also must map to A...
Well, reading it again, actually, doesn't it say twice the same? I think the first sentence is actually sufficient.
C translation (author gone)
Approved. But maybe consider some changes based on comments by Hobovsky on the translation page.
In ruby
completely random tests
always expectfalse
on casual inspection this no longer seems to be the case
Go translation
D translation
Rust translation
C# translation transferred from duplicate kata.
Crystal translation transferred from duplicate kata.
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/104.
Please join the discussion to share your opinions, and help us identify duplicate kata and retire them.
This one was decided to stay
Python (did not check other languages): all random tests expect
False
.JS and Haskell are ok. For Ruby, I think the randomness is bad (alternate a fixed number of isomorphics, a fixed number of non isomorphics, and a fixed number of full random, with prolly a low probability to generate isomorphics; needs to be checked better, and in all case all random tests should be shuffled in one set only to make sense).
Fixed for Python.
I close since ejini raised a specific issue for Ruby
Python new test framework should be used (Refer this & this for more detail)
Done
Haskell translation
Approved.
This comment has been hidden.
Thanks for letting me know! It already exists in Python and JavaScript so I guess the Ruby translator forgot to add it to his version. I've added the test so the problem should be fixed.
This comment has been hidden.
I get following error message for
should handle completely random tests
nvm, I forgot to define
isomorph_sol(a,b)
. Thanks!Perhaps add this test (or similar):
Test.assertEquals(isomorph("ttww","ffrt"),false);
To invalidate some incorrect solutions (that are passing with the current tests).
I don't understand why they wouldn't pass that test. I've tried a few solutions and all of them seem to pass.
Reopening because somebody closed this prematurely.
(JS, possibly others)
Needs
Test.assertEquals(isomorph("abcdefghijk","abcdefghijba"),false);
.Either that, or specify that there can only be max 10 different letters in a word.
( I could have composed an example that has the same length as well. )
Thanks for pointing it out, I didn't thought of that when I created the kata. Added to Python and Javascript.
Added to Ruby.
You're welcome! :]
I see you stole my solution as well. :D Apart from that bug, I rather liked your old solution though; it was very clear in its logic, much clearer than mine. I'm going to try to reimplement it without the bug but with the clarity.
Guys, do not you know why at my ruby 2.3.3p222 line
"string".each_char.to_set
dose not works? but in MRI 2.3.0 here in CodeWars it works.I found that it works in my irb after
require "set"
. But here is still a question, why we do not need to require in CodeWars?Interesting, nice to know... Apparently, the testing framework
require
s it: https://github.com/Codewars/codewars-runner-cli/blob/master/frameworks/ruby/cw-2.rb and only these are available without requiring: https://ruby-doc.org/core-2.3.0/got it, thank you.
(JS, possibly others)
Needs
Test.assertEquals(isomorph("abcdefghijk","abcdefghijba"),false);
.Either that, or specify that there can only be max 10 different letters in a word.
( I could have composed an example that has the same length as well. )
Those two strings are of different lengths (11 and 12), so they're automatically not isomorphic. Unless I'm missing something big, there's no limit to letter differences.
My code outputs the following, and I passed all tests with no issue:
isomorph("ABCDEFGHIJKLNOPQRSTUVWXYZ", "ZYXWVUTSRQPONLKJIHGFEDCBA") true
You're missing the point.
This would expose a bug in the reference solution.
Ruby translation submitted
Approved
Thanks! My first (approved) translation haha :)
How about a test like
'aa', 'bbb'
? Some solutions that pass the current tests would fail.Yes, that's because those words are not isomorphic.
He means that you should add that edge case into your fixed tests because some solutions does not take account into that.
Okay, but in that case would basically every solution fail.
A correct solution returns false for that test case.
The problem is that some solution doesn't. That's why you need to add that to get rid of those solutions that doesn't.
Ahh, I missunderstood you; I thought you wanted me to return
True
for it.I've added it to the kata.
This comment has been hidden.
That's not an issue, that's a question.
Also, order is important.
Ah, thanks. (Sorry, I marked it as an issue before revising it after thinking I'd probably just missed something. Forgot to untag it)
I made the exact same mistake. The description does not mention order is important. I was left thinking that maybe
X
should map toX
if it existed inb
, but could map to something else if not. That wasn't it either. Then I read the comments, and discovered the actual intent of the kata.All this might be in the definition of "isomorphic". But I don't know that. I think the kata would be better if the conditions were explained better.
I didn't realize that people may not think about that. I've tried to clearify that in the description now. If there's something else that can easily be missunderstood, just tell me and I'll add it too.
interesting! The behaviour of indexing helps :)
approved
Highly related: https://www.codewars.com/kata/word-patterns
This is a copy with another title.
Ahh, I did just search for tags like "isomorphic" when I made this kata, so the "Word Patterns"-kata did not show up. >_<
However, in the "Word Patterns"-kata is the pattern already given. Further does it ask you to check if the word sequence is following the given pattern. Not if each character in two given words follows the same pattern, like in mine - note that the pattern is not given. So even if some similarities are quite striking does the kata you provided not want you to check if two words are isomorphic.
I know, that's why I just briefly pointed at it and didn't raise an issue ;-)
The kata more similar to this kata is: https://www.codewars.com/kata/simple-fun-number-31-is-substitution-cipher
The differences (as far as I've noticed) are that this kata has a wider range of test cases: input strings of different lengths, longer input strings, and input strings containing uppercase letters.
It doesen't work.
plenty explicative, and absolutely helpful... Especially when... well... when it workes perfectly, actually
;)
This comment has been hidden.
Very interesting. But needs random tests... ;)
Yes, agreed. However, I don't really know how I should make them when the chance of both words being isomorphic is incredibly low. Thus, if I'd generate random words, the probability of them being
False
(not isomorphic) would be very high. Right?you could use something like tis:
with the same trick you used in your solution (very clever, btw!) it's quite easy to generate true isomorphic words. ;)
I'll try it out, thanks!
Added random tests
Nice :)
You should add descriptors for the tests:
Okay, descriptors has been added now.