6 kyu
Valid string
2,051 of 2,515ryandao
Loading description...
Strings
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.
C#: Wrong method name in initial solution -->
ValidateWord
should beValidateString
This comment has been hidden.
x, ts, xtgk, xupq, qy, qyv, x, oow, y, tvbf
Такое чувство, будто кейсы писали , ударив кота головой об клаву..)
О, а вот и ты с rss)
ye, надо других тянуть за собой)
полностью согласен) тесты нормально проходят, а потом начинается свистопляска
This comment has been hidden.
Please use the
spoiler
tag if you are going to post solution code (even non-working) in the discourse. Also, if you decide to post code, use markdown formatting:```
your code
```
Otherwise, we can't make heads or tails from what you wrote (indentation matters in python).
This comment has been hidden.
this is the code above its not passing for test cases like these:
kindly review it Thanks!
What you are doing with
l
has no effect on thefor
loop, in case you are relying on that somehow. You might as well writefor o in range(0, len(word)):...
Also,m
just keeps accumulating letters without discrimination. In the end it will simply be a concatenation of the input sequence.yeah actually i removed
l
from the outer loop though it had no effect andm
just accumulates the words that are present in the dictionary but for cases likeit isn't working!
This comment has been hidden.
This comment has been hidden.
done (hopefully without me putting more mistakes in the random tests...)
Hello. Could someone explain why this scenario is False with C#? RandomTests(({ e,ace,a,e,a,afjk,b,bd }, aceaebd, False))
Thanks
see above
This comment has been hidden.
This comment has been hidden.
also faced this problem. 1 test fails. Not clear logic of kata. Nobody can answer?
'ab' + 'bc' does not equal 'abc', while 'a' + 'bc' does.
lots of mistakes in c# test sequences, here are some you can check easily:
RandomTests(({ befo,acj,bdh,ag,aef,fhk,iwx,f,imnp,cg,cd,b,ceim,acdf }, befo, False))
RandomTests(({ cirb,bd,d,c,ilnbeh,behj }, dcbd, False))
RandomTests(({ ac,fg,bgmr,acdg,bc,a,bij,abcd,ef,cnrw,b,abc,a,eino }, acbgmr, False))
RandomTests(({ adef,adgn,a,abb,be,fj,bjabc,abce,fe,efja,aci,a,mnf,fjmc,ce,adhi,bd,fde,deh,b,de,ecj,cjlna,abceac,acd,bjblm,blmp,e }, adef, False))
RandomTests(({ abja,ac,ba,al,def,ege,efa,acef,c,ce,efjlkm,kmoqd,dgh,bcc,cgknb,bfcd,cdfg,bef,ejop,adadf,adfl,ba,acce,cef,bb,bdf }, ac, False))
see above
I prepared a code in Python and tried to test it, I got error in test like that --> word: ugodozdozdozutqjuugondkddozugondkddozutqju, seq: ['doz', 'utqju', 'ndkd', 'nzyv', 'ugo'] expected: True This is incorrec, there is no letter "y" in word, here we have seq[3] = "nzyv", how can the andwer here is TRUE.
The word needs to consist of concatenations of words from the sequence. But not all words from that sequence must be used.
ok, got it, thanks!
This comment has been hidden.
Most solutions traverse the word from left to right and try to match parts of the word they encounter with any given key in the dictionary until they reach the end of the word. You'd have to figure out a way to do that.
JS migrated to latest test framework, and Python, C# and JS have better test coverage now (in fixed tests).
This comment has been hidden.
It expects True when I try to reproduce this. I can't explain why you get False as expected. I have added the expected result in the test description. Let's wait and see the audit when it happens again.
If you still experience this issue, could you provide your code (with a spoiler tag) so I could verify?
This comment has been hidden.
This comment has been hidden.
holy... I found it...
@dfhwze: don't forget that the ref solution is... well... recursive (quite an usual problem, when implementing the ref solution... x) )
This comment has been hidden.
yeah, me too... A lot... XD
Me too, not the first time. Fixed
I guess it's ok, now
( JS, possibly others )
This allows for overlapping dictionary words in the string, which is not tested for and may not even be intended.
The "description" and the "Task" are inconsistent.
I'd suggest "Test if the string can be formed entirely from words in the dictionary." ( Do not take this as gospel; I think it can be improved upon still. )
Isn't it tested in the sample tests?
[['ab', 'a', 'bc'], 'abc', true]
ab and bc overlap, and a is contained by ab
first char 'a' is part of substrings 'ab' and 'a', both words in the dictionary second char 'b' is part of substrings 'ab' and 'bc', both words in the dictionary third char 'c' is part of substring 'bc', a word in the dictionary
so each char is part of a substring (or more than one) that is a word in the dictionary.
no, he's actually talking about the exact same thing than I did 3 thread below. ;)
?
(missing the related tests, then)
word: abc, seq: ['ab', 'bc'] -> False
Ok, overlapping words are not allowed. I just found out =D
Description updated. Additional random tests are still required for edge cases.
Edge cases should have fixed tests.
word: abc, seq: ['ab', 'bc'] -> False
would be perfect.(it's already added to python. JS and C# are waiting for the random tests to be stabilized, I guess)
random tests Python updated with edge cases for overlapping words
looks pretty good, but the occurence of the edge case is rather rare (around 3-4/100 random tests). Could make it more probable? (or just increase to 200 random tests overall?)
I'm a fan of increasing the number of test cases. I'll increase the amount to 200.
sounds good to me. Can you update JS and C# too?
I'm looking for volunteers for those ;-)
I'll resolve this one. Random tests are being covered in another issue.
This comment has been hidden.
Please verify whether it's ok now.
:+1:
word: tiq, seq: ['gr', 'kbwhl', 'tiq', 'x', 'ef', 'yz'], expected: False, actual: True Why is the solution False?
In which language? Python: word: tiq, seq: ['gr', 'kbwhl', 'tiq', 'x', 'ef', 'yz'], expected: True, actual: True
I have noticed the same problem . I don't really understand it because in the test we have test.assert_equals(valid_word(['code', 'wars'], 'code'), True)
I haven't witnessed this behavior in Python. I ran 10,000 tests.
In Python. There are multiple similar test cases word: wqy, seq: ['f', 'br', 'tjucg', 'cheyq', 'f', 'wqy'], expected: False, actual: True True should equal False
the
it
block is using the array after it has been passed to the user. I bet it's a poblem about the user mutating the input, so the message isn't trustful anymore.ok retry now please
This comment has been hidden.
@jamad: word: c, seq: ['d', 'nqk', 'n', 'gui', 'jzd', 'vsxk', 'q', 'hqvlf', 'lc', 'ep', 'pic', 'c', 'quav', 'aga', 'mmhb', 'gosvf', 'm', 'sroz', 'myeus', 'pifgp', 'v', 'vs', 's', 'wf', 'kxtd'], expected = True
It expects True. Also, your solution is timing out. When did you notice this?
Fixed an issue in the ref solution.
resolved
I feel like one of those two shouldn't be valid...
they aren't doing the same thing (the first could find matches where the second cannot)
If I undestand the kata correctly, the first shouldn't be true.
example from author:
word = 'abc', dictionary = ('ab', 'a', 'bc') -> True
The first link can be invalidated only through at test expecting False. It will alwys find True when needed. It would match
"abc"
coming from['ab','bc']
while the ref solution couldn't.The description should be clarified about that
Gitter :)
.
add some random test cases which results in true, or else you'll get tons of solutions like mine haha!
I'm curious why you wrap all your booleans in brackets?
just a shtick
A very instructive kata, I really don't understand the satisfaction rating...
Thanks to the author.
Author is inactive for almost 7 years now, perhaps it's time someone else takes care of the description debacle. I edited the description, please verify whether it is clear enough.
Nice work!
You may add some of latest examples in sample tests.
I liked some of the previous examples : 'StarCodeWars' (ok), 'CodeStarsWar' (not ok), 'WarsStarCode' (ok) with ['Star', 'Code', 'Wars']
Python: Done. I also pimped the random test case layout. Who wants to add random tests to JS and C#?
This comment has been hidden.
Because "star" + "wars" == "starwars" ? Order in dictionary doesn't matter.
This comment has been hidden.
Approved, thanks :)
No random tests.
JS random tests added. Please verify.
C# random tests added.
The solution template for C# has the method named
ValidateWord
, while the tests expect it to be namedValidateString
Fixed.
C#: I just can't shake the feeling that more thorough test cases would break my feeble solution..
C# fixed and random tests available.
I suggest to add test Test.expect(validWord(['a', 'b', 'c', 'f'], 'abcdef') === false);
This comment has been hidden.
This comment has been hidden.
Your solution will fail a case like dict = ['ab', 'abc', 'd'], word = "abcd".
Thank you so much ryandao! That is a big help to me. We'll see if I can make this approach work, or if I'll need to start over. =)
Hi, Have you tested a case with the word 'codewars' and the dictionary such as ['c', 'co', 'cod', 'code', 'codew', 'war', 'wa', 'wars']?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Yep, that one works. Can you please send me some other edge cases?
This comment has been hidden.
Thanks a lot man.
Nice idea. The description needs some work, however. It doesn't explicitely say what you need to do. Write a function that returns true if the
word
passed in is made up of one or more words in thedictionary
passed in. The example's pretty confusing, also. You're almost there; just need to write more instructions to make things super clear.This comment has been hidden.
This comment has been hidden.
This is the first one I've had to skip because what's being asked for in the description doesn't SEEM to match what the tests expect. Something doesn't make sense. Others seem to be on the right track, so...? Seemed straightfoward: are any of the words in the dictionary present in the given string? I'd enjoy having this clarified, if my interpretation is wrong. :P
Well it's not that straightforward. Your task is to check if the word is completely made up by combining words from the dictionary. So if dict=['code', 'wars'], combining the 2 words, we have 'codewars', while 'codewar' is impossible. Is it clearer for you?
I think the description you just gave is much much better then the official one, Ryando.
A couple more tests, for out-of-order dictionary and repetition:
The first will catch anyone only checking combinations, rather than permutations, which seems to be what the kata is looking for.
The second is a little more gray-area, but as the description stands now, repeated words should be marked as valid, so there should be an explicit test for this.
Good point! Added the test cases. Thanks.
In the latter case, my solution breaks :(
Overlapping doesn't count, so that would be false.
A suggestion for a test case, to break laoris' brilliant solution:
I'm laoris, and I approve this message.
This comment has been hidden.
FYI: you don't even need to do that much, they've added
Test.randomize
to the test suite, so it becomes:Even better! I'll use Test.randomize for future kata :D
What about overlapping words? The words in ['cod', 'dewa', 'ars'] together would spell 'coddewaars', but overlapped they spell 'codewars'. Should we only worry about combined words?
This problem only concerns with strictly combined words, so overlapping words should return false.
You say it should false for overlapping but test case expects true, this is so annoying!
Which test case says overlapping should be true?
Word:
abc
Dictionary:
[ 'ab', 'a', 'bc' ]
Expected output:
true
bruh...
a
+bc
=>abc
amirite