Sorting numbers by mathematicals properties
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Sorting numbers by mathematicals properties
Hello everyone,
So I have the project to make a stack that can sort a list of products quantities by their properties to make groups by mathematical similarity (equal, multiple, common divider,...)
I get a list of products in a datagrid
1 2500
2 3500
3 5000
4 7500
5 4000
6 3000
7 4000
8 3500
I would like to obtain :
EQUAL
into field Group1 : line1
into field Group2 : line6
into field Group3 : line2, line8
into field Group4 : line7
....
Common dividor
into field Group500 : line1,line2,line3,line4,line5,line6,line7,line8
into field Group1000 : line3,line5,line6,line7
into field Group1500 : line4,line6
....
Multiple
into field Group2500 : line1,line3,line4
into field GroupNone : Line2,line5,line6 .....
I'm not asking for an all code done answer but I really need to be helped to find stategy do to that.
Coudl someone help ?
Thank You
So I have the project to make a stack that can sort a list of products quantities by their properties to make groups by mathematical similarity (equal, multiple, common divider,...)
I get a list of products in a datagrid
1 2500
2 3500
3 5000
4 7500
5 4000
6 3000
7 4000
8 3500
I would like to obtain :
EQUAL
into field Group1 : line1
into field Group2 : line6
into field Group3 : line2, line8
into field Group4 : line7
....
Common dividor
into field Group500 : line1,line2,line3,line4,line5,line6,line7,line8
into field Group1000 : line3,line5,line6,line7
into field Group1500 : line4,line6
....
Multiple
into field Group2500 : line1,line3,line4
into field GroupNone : Line2,line5,line6 .....
I'm not asking for an all code done answer but I really need to be helped to find stategy do to that.
Coudl someone help ?
Thank You
Re: Sorting numbers by mathematicals properties
Hi matgarage,
I suggest you write a function for each category to make lists and work around it
Something like this one to get the list of divisors (Number,div1,div2...)
Best regards
Jean-Marc
I suggest you write a function for each category to make lists and work around it
Sorry a small script is easier for me than english explanationsI'm not asking for an all code done answer but I really need to be helped to find stategy do to that
Something like this one to get the list of divisors (Number,div1,div2...)
Code: Select all
on mouseUp
put the milliseconds into tDepTime
put empty into tListDivisorNumber
put "2500,3500,5000,7500,4000,3000,4000,3500" into tMynumber
repeat for each items tOneNumber in tMynumber
put tOneNumber & "," &MyDivisor(tOneNumber) & cr after tListDivisorNumber
end repeat
delete char -1 of tListDivisorNumber
put the milliseconds - tDepTime & cr & tListDivisorNumber
end mouseUp
function MyDivisor pNumber
put empty into tMyDivisor
repeat with i = 1 to 2500
put pNumber/ i into tResDiv
if "." is in tResDiv then next repeat
put i & "," after tMyDivisor
end repeat
delete char - 1 of tMyDivisor
return tMyDivisor
end MyDivisor
Jean-Marc
https://alternatic.ch
Re: Sorting numbers by mathematicals properties
Hi.
What Jean-Marc said.
This is a great way to both learn LiveCode, and to strengthen your coding skills. These are not the same. For example, what would your strategy be to find the terms that are "equal"? I first think of sorting them numerically. That puts the ones that are the same together in a list. Then can you think of a way to parse them out? How about a repeat loop that compares one line to its neighbor(s)?
That sort of thing. If you are good, you will make such a gadget, then throw it away because you made a better one.
Fun.
Craig Newman
What Jean-Marc said.
This is a great way to both learn LiveCode, and to strengthen your coding skills. These are not the same. For example, what would your strategy be to find the terms that are "equal"? I first think of sorting them numerically. That puts the ones that are the same together in a list. Then can you think of a way to parse them out? How about a repeat loop that compares one line to its neighbor(s)?
That sort of thing. If you are good, you will make such a gadget, then throw it away because you made a better one.
Fun.
Craig Newman
Re: Sorting numbers by mathematicals properties
Hi Jean-Marc and Craig,
But I get problem to understand the line quoted right up.
What is the mean of "MyDividor(tOneNumber)"
The function is MyDividor but what about the variable into () ?
We could speak in french by PM if it's possible...
Thanks again.
Thank you for the code. Your right, a piece of code is more clear than words for me too.jmburnod wrote: Sorry a small script is easier for me than english explanations
Something like this one to get the list of divisors (Number,div1,div2...)
Code: Select all
put tOneNumber & "," &MyDivisor(tOneNumber) & cr after tListDivisorNumber
But I get problem to understand the line quoted right up.
What is the mean of "MyDividor(tOneNumber)"
The function is MyDividor but what about the variable into () ?
We could speak in french by PM if it's possible...
Thanks again.
Re: Sorting numbers by mathematicals properties
Hi matgarage,
Sorry I'm wrong
, this one is better
Here is the result of scripts
targetnumber, div1,div2,div3 etc….
put MyDivisor(2500) = "2500,1,2,4,5,10,20,25,50,100,125,250,500,625,1250,2500"
Best regards
Jean-Marc
Sorry I'm wrong

Code: Select all
on mouseUp
put the milliseconds into tDepTime
put empty into tListDivisorNumber
put "2500,3500,5000,7500,4000,3000,4000,3500" into tMynumber
repeat for each items tOneNumber in tMynumber
put tOneNumber & "," &MyDivisor(tOneNumber) & cr after tListDivisorNumber
end repeat
delete char -1 of tListDivisorNumber
put the milliseconds - tDepTime & cr & tListDivisorNumber
end mouseUp
function MyDivisor pNumber
put empty into tMyDivisor
repeat with i = 1 to pNumber
put pNumber/ i into tResDiv
if "." is in tResDiv then next repeat
put i & "," after tMyDivisor
end repeat
delete char - 1 of tMyDivisor
return tMyDivisor
end MyDivisor
Only if that is necessary. I prefer english in this forum.We could speak in french by PM if it's possible...
tOneNumber is the target numberWhat is the mean of "MyDividor(tOneNumber)"
Here is the result of scripts
targetnumber, div1,div2,div3 etc….
put MyDivisor(2500) = "2500,1,2,4,5,10,20,25,50,100,125,250,500,625,1250,2500"
Best regards
Jean-Marc
https://alternatic.ch
Re: Sorting numbers by mathematicals properties
Hi Craig,dunbarx wrote:Hi.
For example, what would your strategy be to find the terms that are "equal"? I first think of sorting them numerically. That puts the ones that are the same together in a list. Then can you think of a way to parse them out? How about a repeat loop that compares one line to its neighbor(s)?
Craig Newman
Thank you for your interest in my post.
I've did exactly what you describe. Create a datagrid with my products quantities and a button with the sort function .
Then I think I need to ask if quantity of line 1 col 2 of my datagrid is equal to line 2 col 2
then put in equalList1
and repeat with the others lines by creating new equalList for each value.
My first problem is to write this with the correct syntax for code. I'm not already familiar with that and I'm trying to learn with existing example in revrun ressources, tutorials... and this fist post on the forum.
When I said that I'm not asking for an all done code, it was because I realy want to learn how to do.
I think coding require logicals approaches of the problem. For that I need to make link between my goal, the way to reach that point, ressources and tools avaible in livecode and the wau to put in together.
So I need help to give me tips and shortcuts more targeted than what I can find by myself.
Thank you again
Re: Sorting numbers by mathematicals properties
Ok it's more clear for me now.jmburnod wrote:Hi matgarage,
tOneNumber is the target number
Here is the result of scripts
targetnumber, div1,div2,div3 etc….
put MyDivisor(2500) = "2500,1,2,4,5,10,20,25,50,100,125,250,500,625,1250,2500"
Best regards
Jean-Marc
But what about the use of milliseconds function ?
I think i need already an explanation of loop funtion like in:
function MyDivisor pNumber
put empty into tMyDivisor
repeat with i = 1 to pNumber
put pNumber/ i into tResDiv
As I understand you create a function MyDivisor and a variable (asociated?) pNumper
You put empty into the tMydivisor new variable
Here you create a loop (array?) where the variable i = 1 to pNumber
and you put pNumber divided by the variable i into the variable tResDiv
So I can't understand what is the value of pNumber.
Did I make a mistake? Could you explain me that ?
Thank you it's fun
Re: Sorting numbers by mathematicals properties
You are well on your way. Can you find what is just a little wrong with this script to find the lines of equal value?
Assumes, of course, you have your data in "yourData".
Craig Newman
Code: Select all
on mouseUp
sort yourData numeric
repeat with y = 1 to the number of lines of yourData
if line y of yourData = line (y + 1) of yourData then put y & "," & (y + 1) & "," after equalList
end repeat
answer equalList
end mouseUp
Craig Newman
Re: Sorting numbers by mathematicals properties
Ok.dunbarx wrote:You are well on your way. Can you find what is just a little wrong with this script to find the lines of equal value?Assumes, of course, you have your data in "yourData".Code: Select all
on mouseUp sort yourData numeric repeat with y = 1 to the number of lines of yourData if line y of yourData = line (y + 1) of yourData then put y & "," & (y + 1) & "," after equalList end repeat answer equalList end mouseUp
Craig Newman
A good sleep this night give me solution. If I well understand in your first script, pNumber is the value associated with the function Mydivisor when it's called in the on mouseUp part of the script, into () so it's tOneNumber. Right ?
But for your second script, it look good, I can't find what is wrong.
Let me some time, I will search tonight...
Thank you

Re: Sorting numbers by mathematicals properties
Hi matgarage,
Best
YESA good sleep this night give me solution. If I well understand in your first script, pNumber is the value associated with the function Mydivisor when it's called in the on mouseUp part of the script, into () so it's tOneNumber. Right ?
Best
https://alternatic.ch
Re: Sorting numbers by mathematicals properties
Hi,dunbarx wrote:Craig NewmanCode: Select all
on mouseUp sort yourData numeric repeat with y = 1 to the number of lines of yourData if line y of yourData = line (y + 1) of yourData then put y & "," & (y + 1) & "," after equalList end repeat answer equalList end mouseUp
This code sort the line yourDatat by their value, but for the equality it answer the numeric name of the equal lines , without sorting by equal unique quantity.
I'm right ?
I need to create an equalList by equal values ? equalList(n) with n=1 to the number of unique equal values ( + 1 for the non equal) ?
Re: Sorting numbers by mathematicals properties
Hi
I think I make a mistake in my first analysis.
First the script sort item by the numeric function in yourData.
Does it mean that each item (line)is just numbered by their order in the field? Or sorted and numbered ?
Now for the loop, I need to understand this concept.
y = 1 to the number of item in the field
y + 1 : does it mean item1+1=item2, item2+1 = item3, ,...
If so, the code look only for the neighbors numbers, not for all the list.
Wrong, right ?
Thank you
I think I make a mistake in my first analysis.
First the script sort item by the numeric function in yourData.
Does it mean that each item (line)is just numbered by their order in the field? Or sorted and numbered ?
Now for the loop, I need to understand this concept.
y = 1 to the number of item in the field
y + 1 : does it mean item1+1=item2, item2+1 = item3, ,...
If so, the code look only for the neighbors numbers, not for all the list.
Wrong, right ?
Thank you
Re: Sorting numbers by mathematicals properties
Hi matgarage,
Sorry I haven't time to answer to your ask about Craig's script
I found an other way to get a list of equal numbers
Here is:
Best regards
Jean-Marc
Sorry I haven't time to answer to your ask about Craig's script
I found an other way to get a list of equal numbers
Here is:
Code: Select all
on mouseUp
put "2500,3500,5000,7500,4000,3000,4000,3500" into yourData
replace "," with cr in yourData
repeat for each line tNumber in yourData
put tNumber & "," after line tNumber of equalList
end repeat
filter equalList without empty
put equalList
end mouseUp
Jean-Marc
Last edited by jmburnod on Tue Apr 23, 2013 7:50 pm, edited 1 time in total.
https://alternatic.ch
Re: Sorting numbers by mathematicals properties
Hi Jean-Marc,
I will take a look at your new script shortly.
Thank you for your time spent on my question. Your help is usefull for me.
Best
I will take a look at your new script shortly.
Thank you for your time spent on my question. Your help is usefull for me.
Best
Re: Sorting numbers by mathematicals properties
Ok Jean-Marc,
When tNumber don't find equal tNumber it return empty and then the value ?
"Filter without empty" mean "remove empty" ?
I realy appreciate your help
Best
Matthieu
When tNumber don't find equal tNumber it return empty and then the value ?
"Filter without empty" mean "remove empty" ?
I realy appreciate your help
Best
Matthieu