add-memberalign-toparrow-leftarrow-rightbellblockcalendarcamerachatchevron-leftchevron-rightchevron-small-downchevron-upcircle-with-crosscomposecrossfacebookflagfolderglobegoogleimagesinstagramkeylocation-pinmedalmoremuplabelShape 3 + Rectangle 1pagepersonpluspollsImported LayersImported LayersImported LayersshieldstartwitterwinbackClosewinbackCompletewinbackDiscountyahoo

Re: [ruby-99] You weekly code fix

From: Ramki B.
Sent on: Monday, August 15, 2011 12:59 PM
The code finds most of the combinations but not all. I assumed any string with legal words.

As an example, the word "butterflywheel" should yield:
  butter fly wheel
  butterfly wheel
  butter flywheel

Here's one attempt:

def wordBreak(word, dict)

  results = []
  results.push(word) if dict[word]

  1.upto(word.size-MINSIZE-1) do |part|
    prefix,tail = word[0, part+1], word[part+1..-1]
    next unless dict[prefix]

    wordBreak(tail, dict).each do |wb|
      results.push("#{prefix} #{wb}")
  return results

On Mon, Aug 15, 2011 at 11:00 AM, Carl Tanner <[address removed]> wrote:

A word problem, solution and comparison for those of us that like to exercise our coding muscles:

Word Break in Closure and Ruby Laziness in Ruby:

Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Carl Tanner ([address removed]) from Silicon Valley Ruby Meetup.
To learn more about Carl Tanner, visit his/her member profile

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy