Stephen,

OK, there is essentially one problem to solve in your homework assignment. You 
have a list of words, and the list of scrambled words. For each scrambled 
word, you want to see how many words it can "match". The number of words it 
can match is zero or more.

I think you'll have earned your grade if you can solve that problem.

I'll get you to the point you can focus on that problem.

Let's get that file into two lists: the words and the scrambled words.

Save your data to a file called "data". (I put it in "/tmp/data").

        "/tmp/data" file-lines

If you happen to be using a bleeding edge Factor from the git repository, 
you'll have to do this:

        "/tmp/data" utf8 file-lines

Now take a loot at what you have:

        dup .

        =>

{
    "tarp"
    "given"
    "score"
    "refund"
    "only"
    "trap"
    "work"
    "earn"
    "course"
    "pepper"
    "part"
    "XXXXXX"
    "resco"
    "nfudre"
    "aptr"
    "sett"
    "oresuc"
    "XXXXXX"
}

Let's eliminate the final "XXXXXX" element:

        1 head*

Let's make sure that did the trick:

        dup .

{
    "tarp"
    "given"
    "score"
    "refund"
    "only"
    "trap"
    "work"
    "earn"
    "course"
    "pepper"
    "part"
    "XXXXXX"
    "resco"
    "nfudre"
    "aptr"
    "sett"
    "oresuc"
}

Now let's split that list into the two segments we need:

        "XXXXXX" over index cut

Let's see what we have:

        .s

        =>

        { "tarp" "given" "score" "refund" "only" "trap" "work" "earn"...
        { "XXXXXX" "resco" "nfudre" "aptr" "sett" "oresuc" }

We're almost there. The second list has that "XXXXXX" at the head, so let's 
get rid of it:

        1 tail

Now you're left with two things on the stack. The list of words and the list 
of scrambled items.

Here's your first problem. Write this word:

        : match-first? ( word scrambled -- ? ) ... ;

It should take a word and a scrambled word. It returns 't' if the first letter 
of 'scrambled' is in 'word'.

Here's your reading list.

        1) Documentation for the word 'member?'
        2) Documentation for the word 'first'

Let me know when you solve this problem.

Ed

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to