Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Efficient censorship

Post

Efficient censorship

+7
−0

You are a low-level censor working for the Ministry of Media Accuracy. Part of your job is to make sure that certain words don't appear in publications. Every morning you get a fresh stack of next week's newspapers and its your job to comb through them and fix any of the words that were mistakenly included. A naive censor might simply remove the entire word completely, but you know that if you remove part of the word that still prevents the word from appearing in print. So for you it is a point of pride to remove as little of the offending word as possible while still ensuring it does not appear in print.

Task

Given strings $X$ and $Y$ output the longest substring of $X$ which does not contain $Y$ as a contiguous substring

This is code-golf so the goal is to minimize the size of your source code as measured in bytes.

Test cases

For each input output pair a possible correct output is given, your output should always be the same length, but it is not necessary to reproduce these outputs exactly.

chat, cat -> chat
escathe, cat -> esathe
homology, o -> hmlgy
ccatt, cat -> cctt
aababbabab, abab -> aaabbbab
ababab, abab -> abbab
aaaaaaaa, aaa -> aa
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Maximum input (3 comments)
Maximum input
H_H‭ wrote over 1 year ago

What is the maximum length of string X and string Y? In bytes. And how many characters do i have to remove at maximum?

WheatWizard‭ wrote over 1 year ago

You don't get to assume a maximum on these values.

H_H‭ wrote over 1 year ago · edited over 1 year ago

This means basically every real world programming language can't be used since they don't support a infinity amount of memory (they neither support an infinite amount of integers (or characters, .... whatever you prefer) / infinite long strings nor an infinitely high value for a single integer ).