C function in metaTalk?

eric.allen.engle at justice.com eric.allen.engle at justice.com
Thu Mar 13 08:14:01 EST 2003


I'm trying to translate the following C functions into
hypertalk.
If done properly they take as input a string, say ABC
and then 
permutate it into
a
a b
a b c
b 
b c
c

UGLY C***************************************
void permsWithPrefix(string s, string prefix)

public static void printPerms(String s)
{
permsWithPrefix(s, "");
}

public static void permsWithPrefix(String s, string
prefix)
{
if (s.length() < 2)
{
System.out.println(prefix + s);
}

else

{
String remainder;
for (int i = 0; i < s.length(); ++i)
{
remainder = s.substring(0,i) + s.substring(i+1);
permsWithPrefix(remainder, prefix + s.charAt(i));
}
}
}

The closest I've gotten turning this into hypertalk is:



SWEET METATALK:*************
on permswithprefix s, prefix
  
  if the length of s < 2 then put prefix & s & return
after cd fld 1 
else
    
    repeat with  i = 0 to the length of s
      put character 0 to i of s into remainder
      put character i+1 of s after remainder
      permswithprefix remainder, prefix & character i
of s
    end repeat
  end if
  
end permswithprefix


on printperms s
  permswithprefix s, ""
end printperms




on mouseUp
  printperms abc
end mouseUp


*************

But it still doesn't work, apparently because the
substring function in 
c will deliver 1 character(!) if you say
"eric".substring(2,3) 
// -- returns r, if I remember correctly

Any ideas? I would really like to just translate this
function.

Thanks!

My Home Page with free online legal information
Page perso avec liens juridiques

http://www.lexnet.bravepages.com/ind.htm
_________________________________________________
FindLaw - Free Case Law, Jobs, Library, Community
http://www.FindLaw.com
Get your FREE @JUSTICE.COM email!
http://mail.Justice.com



More information about the metacard mailing list