is among - problem
Geoff Canyon
gcanyon at inspiredlogic.com
Sat Nov 22 03:19:01 EST 2003
So the first question is, you have a list of three digit numbers, some
of which are transposed copies of each other. You want to filter the
list so that any transposed duplicates are removed. This should work:
put empty into tNewList
repeat for each line L in tList
put sortChars(L) into tCandidate
if tHitList[tCandidate] is not empty then next repeat
put 1 into tHitList[tCandidate]
put L & return after tNewList
end repeat
function sortChars p
put empty into r
repeat for each char c in p
put c & comma after r
end repeat
sort items of r
replace comma with empty in r
return r
end sortChars
On to the second problem, which is really the first since you wouldn't
have the above problem to solve if you could generate the answer to the
below directly. This code should do the trick. It produces a list of 35
three-digit numbers, which we'll verify as the right number:
on mouseUp
put empty into tList
repeat with i = 1 to 5
repeat with j = i + 1 to 6
repeat with k = j + 1 to 7
put i & j & k & cr after tList
end repeat
end repeat
end repeat
put tList
end mouseUp
It's hard-coded, but for this case that isn't much of an issue. To
verify that there are 35 solutions, consider that this problem
translates to: choose three numbers from the set "1,2,3,4,5,6,7" To
solve that, find 7C3, which is (7*6*5)/(3*2*1) That's 210/6, or 35
regards,
Geoff Canyon
gcanyon at inspiredlogic.com
On Nov 21, 2003, at 5:59 PM, Thomas J McGrath III wrote:
> A group of three items from the list 1,2,3,4,5,6,7 with no duplicates
> in any order = 123 but no 213 or 312 or 231 or 321 and no doubles or
> triples = 111 or 112 or 323 or 322 etc. (WOW my daughter is only 13
> and this in my opinion is complex until I figured it out)
More information about the use-livecode
mailing list