Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re (tilly) 1: Golf (Inspired): Repeated Phrases

by tilly (Archbishop)
on May 10, 2001 at 17:34 UTC ( #79393=note: print w/ replies, xml ) Need Help??


in reply to Golf (Inspired): Repeated Phrases

I find this question unclear. Suppose that $m is 2 and $n is 3. Given that the phrase "this is strange" appears, do you want to see ("this is strange") returned or ("this is strange", "this is", "is strange")?

From both a programming and a spec problem I like only looking for phrases of a given size (which was what was done in the story). From that you can derive your solution through:

sub p{ ($m,$n,@_)=@_;map{f($_,@_)}$m..$n }
An incidental note. The mathematician in me reads your phrase "a list of" and wants to offer the following cheat as a "solution":
sub p{()}
(It is a list, and everything in it is a phrase of the right size that appears in both lists!)

UPDATE
And, of course, I can show that all golf can be improved with the utterly ridiculous:

sub p{}


Comment on Re (tilly) 1: Golf (Inspired): Repeated Phrases
Select or Download Code
Replies are listed 'Best First'.
Re: Re (tilly) 1: Golf (Inspired): Repeated Phrases
by Masem (Monsignor) on May 10, 2001 at 17:56 UTC
    For sake of the golf problem, your example would return all 3 cases if m,n is 2,3. Extra credit for not including and/or removing phrases of x words that are part of phrases with y (y > x) words in the returned list.

    And the list must be of non-null words, so no trivial solutions :-)


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://79393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2015-07-29 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls