Re: Need a function that re-arranges words(!)

2003-11-26 Thread Thomas J McGrath III
I think the code looks pretty!

FWIW Tom

I love the way if then else's slide to the right.

On Nov 26, 2003, at 8:29 AM, Bruce Laidlaw wrote:

I run a mile from any maths, but I did something randomly and then 
rejecting the result it I had it already. And it would give my 
students something to watch for a minute! I didn't do globals either! 
I could debug it easier this way. But it's not pretty! Oh, and it 
draws the line at the joined words ("mycat fat") (or rather, I got 
tired :)) And it can't distinguish between similar words "fat fate 
fatty"

on mouseup
 put cd fld "data" & return into cd fld "display" -- put 3 or 4 words 
into "data"
 repeat
   put any word of line 1 of cd fld "display" & " " after cd fld 
"display"
   if number of words of last line of cd fld "display" = 1 then next 
repeat
   cut last word of last line of cd fld "display"
   put the clipboarddata into cd fld "trash"
   if word 1 of cd fld "trash" is in last line of cd fld "display" then
 put " " after cd fld "display"
 next repeat
   else
 put the clipboarddata & " " after last line of cd fld "display"
 if the number of words in last line of cd fld "display" = number 
of words in line 1 of cd fld "display" then
   repeat until offset("  ",last line of cd fld "display") = 0
 delete char offset("  ",last line of cd fld "display") of 
last line of cd fld "display"
   end repeat
   if last char of cd fld "display" is " " then delete last char 
of cd fld "display"
   cut last line of cd fld "display"
   put clipboarddata into cd fld "trash"
   if char 1 of cd fld "trash" = return then delete char 1 of cd 
fld "trash"
   if line 1 of cd fld "trash" is not among the lines of cd fld 
"display" then put return & cd fld "trash" & return after cd fld 
"display"
 else put return after cd fld "display"
 end if
   end if
  if number of words in cd fld "data" is 3 then put 6 into maxy
 if number of words in cd fld "data" is 4 then put 24 into maxy
 if number of words in cd fld "data" is 5 then put 120 into maxy
     if number of lines in cd fld "display" > maxy then
   delete last line of cd fld "display"
   sort cd fld "display"
   exit to top
 end if
 end repeat
end mouseup

Bruce Laidlaw
Sydney, Australia
http://go.to/reading.writing/
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 3:32 PM
To: How to use Revolution
Subject: Need a function that re-arranges words(!)
Hi all,

Help! :) I've been trying to figure this out but it's been a mess, 
even
though I think it's probably an easy one.

What I need is rev code that can do this:

Given any phrase, e.g.: "my fat cat"

Spit out all of the following (no need to be in this order):

my fat cat
my cat fat
fat my cat
fat cat my
cat my fat
cat fat my
myfat cat
my fatcat
myfatcat
mycat fat
my catfat
mycatfat
fatmy cat
fat mycat
fatmycat
fatcat my
fat catmy
fatcatmy
catmy fat
cat myfat
catmyfat
catfat my
cat fatmy
catfatmy
Conditions:

1. The input phrase can be *any* number of words (not just 3).

2. Each line of the results must contain all the words within (no 
missing
words).

Any takers? Thanks in advance! :)

Valetia




___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution

Macintosh PowerBook G-4 OSX 10.3.1, OS 9.2.2, 1.25 GHz, 512MB RAM, Rev 
2.1.2

Advanced Media Group
Thomas J McGrath III  2003  [EMAIL PROTECTED]
220 Drake Road, Bethel Park, PA 15102


___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Need a function that re-arranges words(!)

2003-11-26 Thread Bruce Laidlaw
I run a mile from any maths, but I did something randomly and then 
rejecting the result it I had it already. And it would give my students 
something to watch for a minute! I didn't do globals either! I could 
debug it easier this way. But it's not pretty! Oh, and it draws the line 
at the joined words ("mycat fat") (or rather, I got tired :)) And it 
can't distinguish between similar words "fat fate fatty"

on mouseup
 put cd fld "data" & return into cd fld "display" -- put 3 or 4 words 
into "data"
 repeat
   put any word of line 1 of cd fld "display" & " " after cd fld "display"
   if number of words of last line of cd fld "display" = 1 then next repeat
   cut last word of last line of cd fld "display"
   put the clipboarddata into cd fld "trash"
   if word 1 of cd fld "trash" is in last line of cd fld "display" then
 put " " after cd fld "display"
 next repeat
   else
 put the clipboarddata & " " after last line of cd fld "display"
 if the number of words in last line of cd fld "display" = number 
of words in line 1 of cd fld "display" then
   repeat until offset("  ",last line of cd fld "display") = 0
 delete char offset("  ",last line of cd fld "display") of last 
line of cd fld "display"
   end repeat
   if last char of cd fld "display" is " " then delete last char of 
cd fld "display"
   cut last line of cd fld "display"
   put clipboarddata into cd fld "trash"
   if char 1 of cd fld "trash" = return then delete char 1 of cd 
fld "trash"
   if line 1 of cd fld "trash" is not among the lines of cd fld 
"display" then put return & cd fld "trash" & return after cd fld "display"
 else put return after cd fld "display"
 end if
   end if
  if number of words in cd fld "data" is 3 then put 6 into maxy
 if number of words in cd fld "data" is 4 then put 24 into maxy
 if number of words in cd fld "data" is 5 then put 120 into maxy
     if number of lines in cd fld "display" > maxy then
   delete last line of cd fld "display"
   sort cd fld "display"
   exit to top
 end if
 end repeat
end mouseup

Bruce Laidlaw
Sydney, Australia
http://go.to/reading.writing/
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
[EMAIL PROTECTED]
Sent: Monday, November 24, 2003 3:32 PM
To: How to use Revolution
Subject: Need a function that re-arranges words(!)
Hi all,

Help! :) I've been trying to figure this out but it's been a mess, even
though I think it's probably an easy one.
What I need is rev code that can do this:

Given any phrase, e.g.: "my fat cat"

Spit out all of the following (no need to be in this order):

my fat cat
my cat fat
fat my cat
fat cat my
cat my fat
cat fat my
myfat cat
my fatcat
myfatcat
mycat fat
my catfat
mycatfat
fatmy cat
fat mycat
fatmycat
fatcat my
fat catmy
fatcatmy
catmy fat
cat myfat
catmyfat
catfat my
cat fatmy
catfatmy
Conditions:

1. The input phrase can be *any* number of words (not just 3).

2. Each line of the results must contain all the words within (no missing
words).
Any takers? Thanks in advance! :)

Valetia

   

 

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Need a function that re-arranges words(!)

2003-11-26 Thread Geoff Canyon
How many words do you want to handle? You say *any* but the number of 
permutations increases very quickly, so you'd have to come up with a 
different way of solving it if you wanted to handle 100 words, for 
example. If N is the number of words, the number of strings to generate 
is

N!*2^(N-1)

So 2 words have 4 arrangements, 3 words have 24 arrangements (as shown 
below), 4 words have 192 arrangements...10 words have 1,857,945,600 
permutations, etc.

For rearranging the words, a recursive function would work nicely. For 
selectively pulling out the spaces my first guess would be to count 
from 0 to 2^(N-1) -1, convert each number to binary using baseConvert, 
and use the 1s and 0s of the resulting string as a guide to inserting a 
space or not. As it turned out, it was better to count from 2^(N-1) to 
2^N - 1 and then pull the leading "1" in order to get the leading 
zeroes.

This will do the trick, but will quickly choke out on longer strings. 
Try it with "test this code" or "this is a test" or "fuzzy wuzzy was a 
bear" but save your work before attempting "peter piper picked a peck 
of pickled peppers" -- it would produce a string over 200MB in size 
(assuming your system's virtual memory system is up to the task).

local sResultList

on rearrangeWords pString,pWordList
  if the number of words of pWordList is 1 then
put enumerateSpaces(pString && pWordList) after sResultList
exit rearrangeWords
  end if
  repeat with i = 1 to the number of words in pWordList
put pWordList into tWordList
delete word i of tWordList
rearrangeWords pString && word i of pWordList,tWordList
  end repeat
end rearrangeWords
function enumerateSpaces pString
  put empty into tReturn
  put the number of words in pString into tWC
  repeat with i = 2^(tWC -1) to 2^(tWC)-1
put char 2 to -1 of baseConvert(i,10,2) into tBitString
put 0 into tCounter
repeat for each word W in pString
  add 1 to tCounter
  if tCounter is tWC then
put W & cr after tReturn
  else
if char tCounter of tBitString is 1 then
  put W & space after tReturn
else
  put W after tReturn
end if
  end if
end repeat
  end repeat
  return tReturn
end enumerateSpaces


regards,

Geoff Canyon
[EMAIL PROTECTED]
On Nov 24, 2003, at 3:32 PM, [EMAIL PROTECTED] wrote:

Hi all,

Help! :) I've been trying to figure this out but it's been a mess, even
though I think it's probably an easy one.
What I need is rev code that can do this:

Given any phrase, e.g.: "my fat cat"

Spit out all of the following (no need to be in this order):

my fat cat
my cat fat
fat my cat
fat cat my
cat my fat
cat fat my
myfat cat
my fatcat
myfatcat
mycat fat
my catfat
mycatfat
fatmy cat
fat mycat
fatmycat
fatcat my
fat catmy
fatcatmy
catmy fat
cat myfat
catmyfat
catfat my
cat fatmy
catfatmy
Conditions:

1. The input phrase can be *any* number of words (not just 3).

2. Each line of the results must contain all the words within (no 
missing
words).

Any takers? Thanks in advance! :)

Valetia



___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Need a function that re-arranges words(!)

2003-11-25 Thread Alex Rice
On Nov 24, 2003, at 4:32 PM, [EMAIL PROTECTED] wrote:

Conditions:

1. The input phrase can be *any* number of words (not just 3).

2. Each line of the results must contain all the words within (no 
missing
words).

Any takers? Thanks in advance! :)
This sounds suspiciously like Math homework. Here are some ideas to get 
you started.

Counting "my fat cat" and "my cat fat" differently means this is an 
ordered selection or permutation.

Combining adjacent words like "myfat cat"... It's still a permutation 
problem, but you are significantly expanding the input word set before 
doing the real work to enumerate the permutation. Two problems rolled 
into one. Trickee!

In my college textbook there are algorithms for "The Next 
k-Combination" and "Enumerating All Subsets". The latter involves 
representing the set as a binary vector and ticking off the 
combinations much like a car odometer. But the former is what I think 
you want. For K input words, you want all k-combinations.

I'm drawing a blank as for translating these algorithms into transcript 
though. See _Applied Combinatorics with Problem Solving_ by Jackson and 
Thoro, Section 4.3

Now Watch someone whip out a 1 liner in Transcript. I will laugh at 
myself then :-)

Alex Rice <[EMAIL PROTECTED]> | Mindlube Software | 


what a waste of thumbs that are opposable
to make machines that are disposable  -Ani DiFranco
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


RE: Need a function that re-arranges words(!)

2003-11-25 Thread Phil Davis
You're right - this is a math puzzle. If you represent each word as a single
digit, you can see a pattern as you make lines showing all combinations.
Like this, using 4 "words":

1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2

2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1

3 1 2 4
... and so on.

So the challenge is, how to express the pattern, or the set of relations
among the "words", mathematically. If anyone can do that, then it's not a
giant leap from there to scripting a "generator".

Phil Davis


> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> [EMAIL PROTECTED]
> Sent: Monday, November 24, 2003 3:32 PM
> To: How to use Revolution
> Subject: Need a function that re-arranges words(!)
>
>
> Hi all,
>
> Help! :) I've been trying to figure this out but it's been a mess, even
> though I think it's probably an easy one.
>
> What I need is rev code that can do this:
>
> Given any phrase, e.g.: "my fat cat"
>
> Spit out all of the following (no need to be in this order):
>
> my fat cat
> my cat fat
> fat my cat
> fat cat my
> cat my fat
> cat fat my
>
> myfat cat
> my fatcat
> myfatcat
>
> mycat fat
> my catfat
> mycatfat
>
> fatmy cat
> fat mycat
> fatmycat
>
> fatcat my
> fat catmy
> fatcatmy
>
> catmy fat
> cat myfat
> catmyfat
>
> catfat my
> cat fatmy
> catfatmy
>
>
> Conditions:
>
> 1. The input phrase can be *any* number of words (not just 3).
>
> 2. Each line of the results must contain all the words within (no missing
> words).
>
> Any takers? Thanks in advance! :)
>
> Valetia
>
>
>
> ___
> use-revolution mailing list
> [EMAIL PROTECTED]
> http://lists.runrev.com/mailman/listinfo/use-revolution

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Need a function that re-arranges words(!)

2003-11-24 Thread [EMAIL PROTECTED]
Hi all,

Help! :) I've been trying to figure this out but it's been a mess, even
though I think it's probably an easy one.

What I need is rev code that can do this:

Given any phrase, e.g.: "my fat cat"

Spit out all of the following (no need to be in this order):

my fat cat
my cat fat
fat my cat
fat cat my
cat my fat
cat fat my

myfat cat
my fatcat
myfatcat

mycat fat
my catfat
mycatfat

fatmy cat
fat mycat
fatmycat

fatcat my
fat catmy
fatcatmy

catmy fat
cat myfat
catmyfat

catfat my
cat fatmy
catfatmy


Conditions:

1. The input phrase can be *any* number of words (not just 3).

2. Each line of the results must contain all the words within (no missing
words).

Any takers? Thanks in advance! :)

Valetia



___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution