7 kyu
Remove duplicate words
9,506 of 21,443e.mihaylin
Loading description...
Strings
Regular Expressions
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 comment has been hidden.
TypeScript sample tests broken with error:
TSError: ⨯ Unable to compile TypeScript: test.ts:1:22 - error TS6053: File '/runner/typings/mocha/index.d.ts' not found.
Check again, after you reseted the trainer, it should be good now (ejini did the update). If so, don't forget to close the issue.
Cheers
Why does this kata have "Regular Expressions" tag, while easiest and most of solutions don't lie in this area?
Tags are indicative. There is no requirement to use regular expressions in this kata.
Golang random test still fail.
Expected : rUGzdJLvG ZS yD iYxLQj iRSVLgN UzUoRzDO to equal : rUGzdJLvG ZS yD iYxLQj iRSVLgN UzUoRzDO
Passes for me. Maybe you have spaces in places they shouldn't be - compare more carefully. In general, please provide enough information for others to reproduce the problem when you create an
issue
. Stating that you are not passing is usually not enough for it to be actionable.I got error:TypeError: a.filter is not a function at removeDuplicateWords (test.js:3:13) at Context. (test.js:16:24) at processImmediate (internal/timers.js:461:21) //// expected [ 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' ] to equal [ 'alpha beta gamma delta' ]
You have to call filter on an array (at least in javascript), I'm guessing in your case
a
is a string.whats wrong here ? In golang Expected : alpha beta gamma delta to equal : alpha beta gamma delta
Got any whitespace at start or at the end of your result?
yes at starting there is white space
Typescript 3.3 or above should be enabled
fixed
This comment has been hidden.
Your solution can't handles new words which are substrings of the previously seen words, e.g.
"aa a"
.This comment has been hidden.
This comment has been hidden.
Hi. Please use markdown tags to format your code or it is very discomfortable to read, see: how-to-format-code-in-markdown.
Hi akar-O,
Thanks for the tip! let me know if it works!
Regards
Arthur
There is an issue with random tests in Golang :
No idea what's the problem.
It seems we receive inputs with plenty of whitespaces, but we have no instructions about that, and in all cases there is here an unexplained behaviour we don't have in other languages (at least Python, Rust, JS and C++). Tests and expected results should be standardized.
I may be wrong, those tests pass by trimming my final result so it must be an issue with my code. However, there is also the issue pointed out by tjw1955 below: for example we receive "utZ t t utZ t utZ utZ utZ utZ t" and we're supposed to return "utZ", whereas it should be "utZ t".
I've looked at the translation page. The page does not check for duplicate words, it checks if the temporary result string does not contain the current string (which does not mean it would be the same word, but only a previously parsed word overlaps the current word), that's why we get those incorrect result.
This comment has been hidden.
ok, thanks :)
Make your code to pass the following tests:
Expect(RemoveDuplicateWords("my cat is my cat fat")).To(Equal("my cat is fat"))
Expect(RemoveDuplicateWords("my cat is fat ")).To(Equal("my cat is fat"))
This helped me.
Same here:
Solution: It turns out that the problem was space at the end of the string on my output. "qPG yMD Xl qkCjCLnef IuO OCNo XFiQCKl[space]" != "qPG yMD Xl qkCjCLnef IuO OCNo XFiQCKl"
random GO tests sometimes fail with input like "xYz x xYz x" expecting result "xYz" rather than "xYz x". Pattern is that the missing word of the solution is a single character long, and is a substring of the earlier string
I raise it as an issue.
This comment has been hidden.
done
Please review Go issue from akar-0, I'm not competent in Go.
This comment has been hidden.
C++ tests dont work, the "equal to" gets shoved into the answer and so they don't validate...
C++ keeps timing out with different solutions. The problem seems to be a word with over 2000 'a' characters.
It does not seem to be a kata issue, I was able to solve it without problems. You either have some error and fall into some infinite loop, or your solution is probably too slow, especially for long strings, and you'd have to think of some better approach.
You can post your solution here (see here how) and we can take a look.
Closing as not a kata issue, I will re-raise it if necessary.
This comment has been hidden.
It's not clear if input can have multiple consecutive spaces, leading and trailing spaces. From JS and Python it looks like it can't and published solutions work in different ways in those cases, so it should be specified in the description.
The reference implementation in CFML is incorrect; for
'aa a'
it expects'aa'
.Looks fixed.
CFML Translation!
approved
This comment has been hidden.
Julia translation
approved
Needs a test case where some words are a substring of previous words.
Example: "starborn star"
Is it possible to do it using regex in python?
doesn't sound so...
This comment has been hidden.
It's not a problem of the kind of quotes you use, you should choose the right version of Python for your code to work.
Why the kata is tagged with Regular Expressions?
Cause it can be solved with RegExp. So if you want to train RegExp, you can search and find this kata.
This comment has been hidden.
Don't post code in discourse, it's forbidden. There's no such thing as approving solutions.
This comment has been hidden.
Your function should return the result, not print it. Maybe there is another problem, but I don't know much C++.
I kow this was for testing reasons, it was on my IDE. it returns the desired output on my IDE, but when I try to submit the code it gives me an error. The first and last word are switched.
Okay, then make it return it in the other order. I don't know much about C++ either, somehow reverse the order of the for loop. I think something like this:
when I am doing the sample test before submitting I am getting the fail because the first and last word are switched. my code runs perfectly on my IDE. Could someone help please? Can I submit the code in this forum?
Yes, mark your post as having spoiler content and use markdown formatting.
Not an issue (a question). Also, 24 guys passed the C++ version, so it must be a code problem ;p
@Osama, FYI (and for later use):
Issue
: problem in the kata itself (description, wrong tests, wrong internal solution...)Suggestions
: well, I guess that part is clearQuestion
anything else that is related to you having a problem solving a kata -> that's you, currently.When you post issues:
When you post a question: well, most of the above apply too x)
I guess this isn't an issue, but since I don't do C++, I cannot check the tests, so I won't close it for now, but... (edit: steffan as been less cautious than me, apparently... x) )
Well, the C++ tests llok fine (to me) and the content of the text sounded like this "my code isn't working" thing. :p Also, how did you figure out it was C++?
;o
hehe... That's my magic power... ;p
This comment has been hidden.
Not a kata issue, try again later. I see you're new, but don't post code without marking the post as having spoiler content. And your function should return a string, not an array. Your code has another problem, but I'll let you to figure it out.
CoffeeScript translation :coffee: Crystal translation :gem:
accepted
Code keeps timing out in C++. Unlocked solutions, tried a few, and they're all timing out as well.
the problem persists yet?
Well, I cannot reproduce it.
resolved, I guess
I still have this problem. My solution uses unordered_set to check if a word was already present so I don't think the fault is because my code is slow.
I printed the words used in private tests with std::cout and there is a test with a word composed of 20000 times the character "a". (https://en.wikipedia.org/wiki/Longest_word_in_English) Probably what is causing the timing out for a lot of solutions is the execution time of hashing such a large word several times. In addition, this does not recreate a real case scenario, because long words like the ones that you can find in the wikipedia link, probably only appear once in a text, and then probably a short form is used. My point is that, if I am not wrong, a solution that uses unordered_set (or similar solutions), which stores hashes of the string is the best solution for the grand majority of cases, so if the solution fails because there is a strange input case, like several words of 20000 characters, all of them "a", the programmer should perform a deep analysis of the input cases and write an optimized version of the solution for those cases, which I don't think it's addecuate for a 7kyu problem.
In the random test cases for Rust, the following line appears:
assert_eq!(remove_duplicate_words(&r), remove_duplicate_words(&r));
This line doesn't test anything. It should read instead:
assert_eq!(remove_duplicate_words(&r), solution(&r));
fixed
Rust:
please check if fixed now
Not fixed yet.
guess it's fixed now
Not fixed yet.
can't remove
from sample and complete solutions and add it only to test case, where it is used the tests run ok, but I recieve an error on re-puplish (cause already submitted solutions fail) the only way is to add it to both solutions - it passed
Don't remove it from the solution if it needs that.
TypeScript translation has been provided. Please review and approve.
User should not have to add this in their code
use std::collections::HashSet;
to get it to work.
Needs to be in set up of test suite
( JavaScript )
Don't just have a gazillion huge random tests.
The tests have been replaced by more structured ones by now
This comment has been hidden.
Help us help you. Markup your quoted text, and tell us what language. Because, admittedly, this looks strange, but we have nothing much to go on.
( Might be a trailing newline somewhere )
This comment has been hidden.
done
Rust: Sample tests run perfectly, but I'm getting this mistake trying to attempt:
Had the same issue, but appending
use std::collections::HashSet;
at the beginning fixed it for me.resolved
C++ Translation
Please review and approve.
done
please review c++ issue above ^
In the Rust initial solution the return type should be
String
instead of&str
.done
@e.mihaylin , it's still defaulting the function signature to &str
Hi everyone. Where I should write about error in compilation for Rust lang? There is error with HashMap when I tried attend the solution. The error happen only on codewars in other place like official rust playground there no error.
Hi. If it is not related to kata, but to compilation engine, you can create a github issue: https://github.com/Codewars/codewars.com/issues
Thanks for the answer.
Same error, did you report it? or is it our fault?
Same with me 'Map' only refers to a type, but is being used as a value here. However on a local typescript / jasmine setup all tst cases pass.
I guess that Rust and Ts cases are different issues.
PHP translation, please check and approve :-)
This comment has been hidden.
This regexp simply doesn't work properly. For some cases it returns wrong word order, for some doesn't remove all the duplicates (1 symbol words, for example). You should analyze input, expected output and your result. Random cases may be tougher than basic.
Rust Translation has been added.
Please review and approve.
please review rust issues above ^
Thank you! Original version has been modifued. Published fixed fork. Please review and approve.
1 rust issue stills persists ^
maybe use this, not compitent in rust
Thanks. There is that "use" in the solution: http://prntscr.com/ourm82 I see no issues in the fork: http://prntscr.com/ourky5 Could you please elaborate regarding this
HashSet
declaration error?The tests use
HashSet
too. If a solution doesn't use it, there's an error.Right you are. I've update the solution. Here is a fixed fork. Please review and approve.
Also edited the original.
that's a duplicate... I already did that in python 1 month ago.
Well, it's a bit late, i guess. I couldn't find it and can't yet.
Ruby translation
Please reveiw and approve.
.
I just edited this, so that the example test cases also work. Please check, that everything works, before publishing the kata.
Haskell translation
Please review and approve
.
Python translation
Please review and approve.
.
For future, don't enforce using
const
, write initial solution asfunction
.Why not? Nevertheless, updated initial solution.
Could you clarify it?
thank you it was kata issue fixed
Thanks. It works!
random tests seems wrong
thank you fixed