3
\$\begingroup\$

You are writing a screen scraper application monitoring a text-only chat window. Text is added at the bottom of the window.

The application takes screenshot of the chat window. If a change has occurred since last screenshot (new_screenshot != old_screenshot), the screenshot is saved.

After X time, all images are merged to one image, where the oldest image is on the top. This large image is send to a server for OCR, and a string of text is returned.

Challenge: Sort out redundant text.

Example: Chat window is 5 lines high and is initially empty. The solution must work with empty and not-empty initial chat window. More than one line can be added at each screenshot.

Input to algorithm:

1 Lorem ipsum dolor sit amet,
1 Lorem ipsum dolor sit amet,
2 consectetur adipiscing elit
1 Lorem ipsum dolor sit amet,
2 consectetur adipiscing elit
3 Mauris porttitor enim sed tincidunt interdum.
1 Lorem ipsum dolor sit amet,
2 consectetur adipiscing elit
3 Mauris porttitor enim sed tincidunt interdum.
4 Morbi elementum erat nec nulla auctor, eget porta odio aliquet.
1 Lorem ipsum dolor sit amet,
2 consectetur adipiscing elit
3 Mauris porttitor enim sed tincidunt interdum.
4 Morbi elementum erat nec nulla auctor, eget porta odio aliquet.
5 Nam aliquet velit vel elementum tristique.
2 consectetur adipiscing elit
3 Mauris porttitor enim sed tincidunt interdum.
4 Morbi elementum erat nec nulla auctor, eget porta odio aliquet.
5 Nam aliquet velit vel elementum tristique.
6 Donec ac tincidunt urna.
3 Mauris porttitor enim sed tincidunt interdum.
4 Morbi elementum erat nec nulla auctor, eget porta odio aliquet.
5 Nam aliquet velit vel elementum tristique.
6 Donec ac tincidunt urna.
7 Proin pretium, metus non porttitor lobortis, tortor sem rhoncus urna
4 Morbi elementum erat nec nulla auctor, eget porta odio aliquet.
5 Nam aliquet velit vel elementum tristique.
6 Donec ac tincidunt urna.
7 Proin pretium, metus non porttitor lobortis, tortor sem rhoncus urna
8 quis finibus leo lorem sed lacus.
5 Nam aliquet velit vel elementum tristique.
6 Donec ac tincidunt urna.
7 Proin pretium, metus non porttitor lobortis, tortor sem rhoncus urna
8 quis finibus leo lorem sed lacus.
1 Lorem ipsum dolor sit amet,

Expected result:

1 Lorem ipsum dolor sit amet,
2 consectetur adipiscing elit
3 Mauris porttitor enim sed tincidunt interdum.
4 Morbi elementum erat nec nulla auctor, eget porta odio aliquet.
5 Nam aliquet velit vel elementum tristique.
6 Donec ac tincidunt urna.
7 Proin pretium, metus non porttitor lobortis, tortor sem rhoncus urna
8 quis finibus leo lorem sed lacus.
1 Lorem ipsum dolor sit amet,

UPDATE: I forgot an important detail in the original challenge: The same line can come multiple times, but never two times in a row so just deduplicating is not enough.

\$\endgroup\$

closed as unclear what you're asking by Shaggy, Digital Trauma, JayCe, NoOneIsHere, Οurous Aug 30 '18 at 20:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Welcome to PPCG! This site is a language-agnostic challenge site, it's not like StackOverflow. I've tried to edit your question to stay on topic. If you are looking for a solution to a problem you cannot solve, this may not be the site for you. \$\endgroup\$ – Stephen Aug 30 '18 at 16:53
  • \$\begingroup\$ Hi Vingtoft, and welcome to PPCG! As it stands, this question would likely be a better fit for StackOverflow. That said, if you add a win condition (usually code-golf), this could make for a good challenge. In the future, we also recommend running questions through the sandbox before posting here. \$\endgroup\$ – Mnemonic Aug 30 '18 at 16:55
  • 1
    \$\begingroup\$ @Vingtoft No worries. I hope we'll see you again for future challenges. Incidentally, what you're looking for is probably sorted(set(text.split('\n'))). \$\endgroup\$ – Mnemonic Aug 30 '18 at 17:02
  • 1
    \$\begingroup\$ so the output is the result of seven comparisons which in sequence add: [1,2] [3,4] [5] [6] [7] [8] [1 ?] \$\endgroup\$ – JayCe Aug 30 '18 at 19:39
  • 2
    \$\begingroup\$ Hi and welcome to PPCG. Generally it is frowned upon to change the question after answers have been given, especially if it invalidates existing answers. I just voted to close due to the question now being unclear. I'll delete my own answer for now, until I can understand exactly what is being asked. \$\endgroup\$ – Digital Trauma Aug 30 '18 at 19:42
0
\$\begingroup\$

Japt -R, 11 bytes

This passes the test case but the spec still isn't clear enough

·ò¨ mÌò¦ mg

Try it

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.