Retired
Word Patterns (retired)
246 of 785joh_pot
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.
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.
Kata retired.
This comment has been hidden.
Ruby 3.0 should be enabled, see this to learn how to do it
Kata retired.
Please use new python test framework.
Kata retired.
The example pattern= 'abba', string= 'dog dog dog dog' => False expected is clearly abusive in view of the description.
What do you mean by abusive? The description has
('aaaa', 'dog dog dog dog') == true
Maybe I meant "misleading" and not "abusive" (my poor English...). From this example, one cannot logically deduce that ('abba', 'dog dog dog dog') should return False. It still follows the sequence in the pattern, if one assumes that 'a' <=> 'dog' and 'b' <=> 'dog', which does not contradicts the description. FArekkusu said it just below: "It's not mentioned that each letter in the pattern stands for a distinct word."
I'm not sure I fully understand your issue. Do you think that a=dog and b=dog make sense? If that was the case, then the entire kata would be pointless because then you can say that every single char in the pattern can be equal to anything in the word.
It makes sense to me, question of point of view. Is this really absurd? :
Why wouldn't this make sense? Every single char in the pattern cannot be equal to anything in the word, 'aaaa', 'cat cat dog cat' remains impossible in all cases. You cannot say the entire kata would be pointless, 'abba' 'dog dog dog dog' is the only case test that relies on this implicit statement "each letter in the pattern stands for a distinct word". It may seem obvious to you but actually it is not, and it should be mentioned in the description.
It seems quite obvious to me that a letter implies a distinct word, it can even be seen in the example test cases. I have added it to the description for those that skim read.
Python 3 should be enabled.
done
It's not mentioned that each letter in the pattern stands for a distinct word.
Description updated
Great kata but description is lacking some info which cannot be comprehended by given examples alone (in current state they are somehow misleading). It should be stated that string can contain various number of words and that words can be mapped into whichever possible character in the pattern.
passed all the example test cases, and, upon hitting submit, I'm getting 75 passed, 1 failed. Is there any way to get info on the failed test case? The failed case result I'm getting back just says "Let us get started".
It is a random test, so the best I can advise is to just print out the (
console.log(pattern, string)
) args and test your current solution with the args and what is expectedI'm getting the same issue. For some reason even console.logging it doesn't work for the random cases. Maybe it is a codewars issue?
Did you manage to do something about it? I'm having the same issue and I've tried a lot of things... And yeah the console.log works only on local tests...
Try again. After the Codewars upgrade, it seems if you have an
it('text that describes tests', function(){})
it would not show any output anymore. I have removed that block and it seems to be working fine now.That helped me solve the problem. It's funny how some factors for test cases that don't pass are unexpectedly obvious. Thanks for the kata, joh_pot.
This comment has been hidden.
Ya, I think having no spaces in between the words would be harder (would break my solution for this kata). Interesting idea though, I'm going to try and write a solution for my own amusement.
Thanks for the tip!
After a good amount of Googling, it seems one suggested approach is by using the Depth First Search (DFS) method, but all the sources seem to relate it to graphs. I'll see if I can code a function that can take a non-breaking input string and determine if it matches the pattern input. I figure recursion may be necessary to do so.
Returned false but was expecting true for c# - I believe this is an error, the first three don't match.
Hi My solution does return False for that pattern/string combination. Could you post your code so I can have a look?
in Javascript 10th test looks like
it's wrong
please fix it
Why do you think that the test is wrong?
I wrote
and got
aaffggiilp != ccfppssca but test expected true answer
Hi! In this case, cow and chicken are two different entities. I think you're looking at just the first character?
So
pattern = aafggiilp / str = cow cow fly pig pig sheep sheep chicken aardvark
:a = cow, f = fly, g = pig, i = sheep, l = chicken, p = aardvark
cow(a)cow(a)fly(f)pig(g)pig(g)sheep(i)sheep(i)chicken(l)arrdvark(p)
Thank you, now all cleared :-)
thanks
Hello! Thanks for the kata. It is really interesting. But i keep failing 11th test...just 11th...can U show me the parametrs of it? or some hint)
Hi
You can do a
console.log(str + ' ' + pattern);
in js to see your args.Can you advise parameters for last random test? I'm failing to pass only the last random test and want to see what the parameters are so that I can check and edit my code.
Just do a
console.log(str + ' ' + pattern);
in js to see your args.That appears to work for the example test cases, but not for the kata's test fixtures.
The description should state that all pattern characters need to have another word, e.g.
(In other words, say that the pattern mapping has to be injective)
hello and thanks for this kata, i am enjoying it BUT!! i keep failing one test. Is it possible for the pattern to contain at least one element that is a number greater than 9? Thank you.
Hi ecocode
There is only one number test and that is in the
Initial Tests
section. For the random tests, all the strings are chars.This is one of the test cases:
Test.assert_equals(word_pattern('abba', 'car truck truck car'), true)
I was wondering why I kept failing the tests.
I need more info than that man.
I was working through the ruby version. If you need more info than that let me know what you need.
I need to know why you think your solution should pass. Why is your solution returning
false
? For patternabba
and strcar truck truck car
, you can see thata = car
andb = truck
. Soa(car)b(truck)b(truck)a(car)
. Your solution should returntrue
Ok I must be completely mistaken about how the kata should be working. I thought the string should include the letter in the pattern? Truck does not include the letter b. In the other examples this holds true and is what I was trying to achieve.
Haha I see it now. Thanks for your patience!
Would you be interested in some edited language in the descriptions so other's don't make the same mistake as I did? For example: given a
pattern
and a stringstr
, find ifstr
follows the same sequence aspattern
.The examples, as written, can be taken two different ways also, so maybe something like:
word_pattern('abab', 'truck car truck car') == true
word_pattern('aaaa', 'dog dog dog dog') == true
word_pattern('abab', 'apple banana banana apple') == false
word_pattern('aaaa', 'cat cat dog cat') == false
Sure. I have changed the description and examples to reflect your suggestions. Thanks for your contribution!
I like this kata, thanks @joh_pot!
My only (minor) issue is the description. I think it would be more helpful to add an example of the input/output to the description.
Hmmm, you're right, I thought the Ruby and Python translator would have merged that into the description. Give me a sec, I'll go add them quickly.
Done.
Perfect, thanks!
Upvoted, ranked, translated: enjoy and let me know if you approve them, so that I can edit the description :)
Thanks bro, approved.