is among - problem

Rob Cozens rcozens at pon.net
Sat Nov 22 09:43:21 EST 2003


Morning Everyone,

My virgin attempt at recursion apparently gave no one a rush except me.

Be that as it may, now that I've written a recursive handler, I'm 
motivated to take it a step farther and generalize the handler to 
deal with strings of any number of unique characters (albeit of equal 
length):

on mouseUp
   put sansDuplicates(field "My List") into field "My List"
end mouseUp

function sansDuplicates numberList
    if the number of lines of numberList < 2 then return numberList
    put line 1 of numberList into targetLine
    delete line 1 of numberList
    get allCombinations(targetLine)
    repeat for each line aPattern in it
      get offset(aPattern,numberList)
      repeat while it > 0
         delete char it to (it+3) of numberList
         get offset(aPattern,numberList)
      end repeat
    end repeat
    return targetLine&return&sansDuplicates(numberList)
end sansDuplicates

function allCombinations theDigits
   if length(theDigits) < 2 then return theDigits
   put 0 into charNumber
   put empty into theCombinations
   repeat for each char aDigit in theDigits
     add 1 to charNumber
     put theDigits into digitString
     delete char charNumber of digitString
     get allCombinations(digitString)
     repeat for each line aCombination in it
       put aDigit&aCombination&return after theCombinations
     end repeat
   end repeat
   return theCombinations
end allCombinations

-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)


More information about the use-livecode mailing list