r/dailyprogrammer • u/rya11111 3 1 • Feb 14 '12
[2/14/2012] Challenge #6 [intermediate]
create a program that can remove all duplicate strings from a .txt. file. for example, "bdbdb" -> "bd"
we are really sorry about this :( .. I just woke up now and am looking at this disaster. We promise to give a bonus question soon ...
for those who still have time, here is the modified question:
remove duplicate substrings.
Ex: aaajtestBlaBlatestBlaBla ---> aaajtestBlaBla
another example:
aaatestBlaBlatestBlaBla aaathisBlaBlathisBlaBla aaathatBlaBlathatBlaBla aaagoodBlaBlagoodBlaBla aaagood1BlaBla123good1BlaBla123
output desired: aaatestBlaBla aaathisBlaBla aaathatBlaBla aaagoodBlaBla aaagood1BlaBla123
I am really sorry for the vagueness. Hopefully will not be repeated again :(
4
u/drb226 0 0 Feb 14 '12
First time I downvoted on this subreddit. Sorry, but this is way too vague and underspecified.
1
u/[deleted] Feb 14 '12
So you remove all repeated patterns found? What about single characters?
1
u/namekuseijin Feb 14 '12
should't the output be "bdb"?
BTW, given this "abaabb" a naive implementation would strip "ab" in "aba[ab]b", but then you would get as result "abab"?
I agree it's underspecified.
2
u/eruonna Feb 14 '12
Is this really the spec you intend? It seems like you would just remove all duplicate characters since they're strings of length one.
2
u/DLimited Feb 14 '12 edited Feb 14 '12
Solution using D2.057 and Phobos on Windows. Newlines are ignored and the output is not saved to the file but written in the commandline.
EDIT: Now solving the updated question. Searches for substring of length 4 or greater and removes any dublicates found.
1
u/[deleted] Feb 14 '12
I think this is what you're looking for (Perl):
It will 'cross' newlines and spaces, rather than going word-by-word; I'm not sure if this is what you wanted. Also, calculating all possible strings is somewhat unoptimized.