It appears that the list c is being passed to the comparison unevaluated in the second case but not in the first. That means that LCM(n,m) is not evaluated in the initial list. Sort© must evaluate c before sorting else it couldn’t sort. That’s why that comparison works.
The other two cases operate on a list of LCM() and the comparison fails. The final case probably crashes MathStudio due to a type mismatch in the Element statement.
I tested several variations including evaluating the comparison before the If() statement. Even when the comparison yields 0 the x value seems to be appended to the output list. There is an issue with If() or the append operator @= or both.
after a bit of consideration:
If I interpret the behavior of @= correctly instead of appending the value at the current location of the list pointer in For x in c, it replaces c3 with c(1…current position of pointer)
Nope, I’m wrong. The script fails only for some instances of the comparison.
The first failure is the second occurrence of 12 which @? fails to find in the list c3 appends it to the list. After which it evaluates the 4 which is not in c3 but evaluates to 1.
A similar event occurs after it evaluates 28 then fails to append the 8.
Holy cow, Is it failing on 4 and 8 because 24 & 28 are in c3?
Nope, It also fails on 5 and 10.
There is something very screwy happening here.
remove duplicates.If only.math (884 Bytes)