Re: Return Total of a Given Repeated Number in a List
just spitballing: let's call our containers "tSearchingFor" and "tSearchString" *set* the itemDelimiter to comma & tSearchString & comma *put* the number of items in tSearchingFor - 1 into tNum *if* tSearchString begins with tSearchingFor & comma *then* *add* 1 to tNum *if* tSearchString ends with comma & tSearchingFor *then* *add* 1 to tNum On Thu, May 23, 2024 at 10:08 PM Roger Guay via use-livecode < use-livecode@lists.runrev.com> wrote: > > Hi all, > > Please, what’s the easiest way to return the total number of a given > repeated number in a list of numbers? IOW, how many times is 2 repeated in > a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. > > > Thanks, > > Roger > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > -- On the first day, God created the heavens and the Earth On the second day, God created the oceans. On the third day, God put the animals on hold for a few hours, and did a little diving. And God said, "This is good." ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
Probably not the shortest approach, but I’d probably do either this… function countItemRepsInList pList, pItem replace comma with cr in pList filter pList with pItem return (the number of lines in pList) end countItemRepsInList or this function countItemRepsInList pList, pItem put 0 into tCount repeat for each item tItem in pList if (tItem = pItem) then add 1 to tCount end repeat return tCount end countItemRepsInList Terry From: use-livecode on behalf of Roger Guay via use-livecode Date: Friday, 24 May 2024 at 12:09 PM To: How to use LiveCode Cc: Roger Guay Subject: Return Total of a Given Repeated Number in a List Hi all, Please, what’s the easiest way to return the total number of a given repeated number in a list of numbers? IOW, how many times is 2 repeated in a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. Thanks, Roger ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
Very clever, Mike. I never thought to use itemDelimiter this way. I’ll have to play with this. Thanks very much, Roger > On May 23, 2024, at 7:37 PM, Mike Kerner via use-livecode > wrote: > > just spitballing: > let's call our containers "tSearchingFor" and "tSearchString" > > *set* the itemDelimiter to comma & tSearchString & comma > > *put* the number of items in tSearchingFor - 1 into tNum > > *if* tSearchString begins with tSearchingFor & comma *then* *add* 1 to tNum > > *if* tSearchString ends with comma & tSearchingFor *then* *add* 1 to tNum > > On Thu, May 23, 2024 at 10:08 PM Roger Guay via use-livecode < > use-livecode@lists.runrev.com> wrote: > >> >> Hi all, >> >> Please, what’s the easiest way to return the total number of a given >> repeated number in a list of numbers? IOW, how many times is 2 repeated in >> a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. >> >> >> Thanks, >> >> Roger >> ___ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your >> subscription preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode >> > > > -- > On the first day, God created the heavens and the Earth > On the second day, God created the oceans. > On the third day, God put the animals on hold for a few hours, > and did a little diving. > And God said, "This is good." > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
Another way to do it is this: function countOccurrences pString repeat for each item tItem in pString add 1 to tFrequencyArray[tItem] end repeat return tFrequencyArray end countOccurrences To get the number of 2’s, just extract tFrequencyArray[2] etc. The advantage is that you get a frequency list (array) of ALL the items in one go. The bonus advantage is that you also get a list of unique values, by getting the keys of tFrequencyArray. So it also serves as a duplicate-clearing function, which is sometimes handy. /Andreas > 24 maj 2024 kl. 07:08 skrev Roger Guay via use-livecode > : > > Very clever, Mike. I never thought to use itemDelimiter this way. I’ll have > to play with this. > > Thanks very much, > > Roger > >> On May 23, 2024, at 7:37 PM, Mike Kerner via use-livecode >> wrote: >> >> just spitballing: >> let's call our containers "tSearchingFor" and "tSearchString" >> >> *set* the itemDelimiter to comma & tSearchString & comma >> >> *put* the number of items in tSearchingFor - 1 into tNum >> >> *if* tSearchString begins with tSearchingFor & comma *then* *add* 1 to tNum >> >> *if* tSearchString ends with comma & tSearchingFor *then* *add* 1 to tNum >> >> On Thu, May 23, 2024 at 10:08 PM Roger Guay via use-livecode < >> use-livecode@lists.runrev.com> wrote: >> >>> >>> Hi all, >>> >>> Please, what’s the easiest way to return the total number of a given >>> repeated number in a list of numbers? IOW, how many times is 2 repeated in >>> a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. >>> >>> >>> Thanks, >>> >>> Roger >>> ___ >>> use-livecode mailing list >>> use-livecode@lists.runrev.com >>> Please visit this url to subscribe, unsubscribe and manage your >>> subscription preferences: >>> http://lists.runrev.com/mailman/listinfo/use-livecode >>> >> >> >> -- >> On the first day, God created the heavens and the Earth >> On the second day, God created the oceans. >> On the third day, God put the animals on hold for a few hours, >> and did a little diving. >> And God said, "This is good." >> ___ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your subscription >> preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
i LOVE all of these solutions. chunking is so great. in every language i use, there are two things i always implement: * chunking * quicken date shortcuts On Fri, May 24, 2024 at 2:56 AM Andreas Bergendal via use-livecode < use-livecode@lists.runrev.com> wrote: > Another way to do it is this: > > function countOccurrences pString >repeat for each item tItem in pString > add 1 to tFrequencyArray[tItem] >end repeat > >return tFrequencyArray > end countOccurrences > > To get the number of 2’s, just extract tFrequencyArray[2] etc. > The advantage is that you get a frequency list (array) of ALL the items in > one go. > > The bonus advantage is that you also get a list of unique values, by > getting the keys of tFrequencyArray. > So it also serves as a duplicate-clearing function, which is sometimes > handy. > > /Andreas > > > > 24 maj 2024 kl. 07:08 skrev Roger Guay via use-livecode < > use-livecode@lists.runrev.com>: > > > > Very clever, Mike. I never thought to use itemDelimiter this way. I’ll > have to play with this. > > > > Thanks very much, > > > > Roger > > > >> On May 23, 2024, at 7:37 PM, Mike Kerner via use-livecode < > use-livecode@lists.runrev.com> wrote: > >> > >> just spitballing: > >> let's call our containers "tSearchingFor" and "tSearchString" > >> > >> *set* the itemDelimiter to comma & tSearchString & comma > >> > >> *put* the number of items in tSearchingFor - 1 into tNum > >> > >> *if* tSearchString begins with tSearchingFor & comma *then* *add* 1 to > tNum > >> > >> *if* tSearchString ends with comma & tSearchingFor *then* *add* 1 to > tNum > >> > >> On Thu, May 23, 2024 at 10:08 PM Roger Guay via use-livecode < > >> use-livecode@lists.runrev.com> wrote: > >> > >>> > >>> Hi all, > >>> > >>> Please, what’s the easiest way to return the total number of a given > >>> repeated number in a list of numbers? IOW, how many times is 2 > repeated in > >>> a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. > >>> > >>> > >>> Thanks, > >>> > >>> Roger > >>> ___ > >>> use-livecode mailing list > >>> use-livecode@lists.runrev.com > >>> Please visit this url to subscribe, unsubscribe and manage your > >>> subscription preferences: > >>> http://lists.runrev.com/mailman/listinfo/use-livecode > >>> > >> > >> > >> -- > >> On the first day, God created the heavens and the Earth > >> On the second day, God created the oceans. > >> On the third day, God put the animals on hold for a few hours, > >> and did a little diving. > >> And God said, "This is good." > >> ___ > >> use-livecode mailing list > >> use-livecode@lists.runrev.com > >> Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > >> http://lists.runrev.com/mailman/listinfo/use-livecode > > > > > > ___ > > use-livecode mailing list > > use-livecode@lists.runrev.com > > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > > http://lists.runrev.com/mailman/listinfo/use-livecode > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > -- On the first day, God created the heavens and the Earth On the second day, God created the oceans. On the third day, God put the animals on hold for a few hours, and did a little diving. And God said, "This is good." ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
On 24/05/2024 13:35, Mike Kerner via use-livecode wrote: i LOVE all of these solutions. chunking is so great. in every language i use, there are two things i always implement: * chunking Yes. * quicken date shortcuts Alex. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
Filter items of tList with 2;put the number of items of tList Bob S > On May 23, 2024, at 7:07 PM, Roger Guay via use-livecode > wrote: > > > Hi all, > > Please, what’s the easiest way to return the total number of a given repeated > number in a list of numbers? IOW, how many times is 2 repeated in a list > containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. > > > Thanks, > > Roger > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
Actually: put tList into tTest — so you don’t lose the original contents of tList filter items of tTest with 2 put the number of items of tTest Bob S > On May 24, 2024, at 8:23 AM, Bob Sneidar via use-livecode > wrote: > > Filter items of tList with 2;put the number of items of tList > > Bob S > > >> On May 23, 2024, at 7:07 PM, Roger Guay via use-livecode >> wrote: >> >> >> Hi all, >> >> Please, what’s the easiest way to return the total number of a given >> repeated number in a list of numbers? IOW, how many times is 2 repeated in a >> list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. >> >> >> Thanks, >> >> Roger ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
The single most important feature of LiveCode is this list. Thank you, Bob, Alex, Mike and Andreas Roger > On May 24, 2024, at 8:26 AM, Bob Sneidar via use-livecode > wrote: > > Actually: > > put tList into tTest — so you don’t lose the original contents of tList > filter items of tTest with 2 > put the number of items of tTest > > Bob S > > >> On May 24, 2024, at 8:23 AM, Bob Sneidar via use-livecode >> wrote: >> >> Filter items of tList with 2;put the number of items of tList >> >> Bob S >> >> >>> On May 23, 2024, at 7:07 PM, Roger Guay via use-livecode >>> wrote: >>> >>> >>> Hi all, >>> >>> Please, what’s the easiest way to return the total number of a given >>> repeated number in a list of numbers? IOW, how many times is 2 repeated in >>> a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. >>> >>> >>> Thanks, >>> >>> Roger > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
(to alex's question) > * quicken date shortcuts quicken has/had these very nifty ways of handling date inputs, to make entry faster. if you enter a numeral, like 26, it means that date of this month. similarly, month/date e.g. 5/25 is 5/25 of this year. "T" is today "+" to increment the date field one day. if the date field is empty, it means tomorrow "-" "M" is the first day of this month, and "H" is the last "Y"ea"R" "W"ee"K" On Fri, May 24, 2024 at 5:06 PM Roger Guay via use-livecode < use-livecode@lists.runrev.com> wrote: > The single most important feature of LiveCode is this list. Thank you, > Bob, Alex, Mike and Andreas > > Roger > > > On May 24, 2024, at 8:26 AM, Bob Sneidar via use-livecode < > use-livecode@lists.runrev.com> wrote: > > > > Actually: > > > > put tList into tTest — so you don’t lose the original contents of tList > > filter items of tTest with 2 > > put the number of items of tTest > > > > Bob S > > > > > >> On May 24, 2024, at 8:23 AM, Bob Sneidar via use-livecode < > use-livecode@lists.runrev.com> wrote: > >> > >> Filter items of tList with 2;put the number of items of tList > >> > >> Bob S > >> > >> > >>> On May 23, 2024, at 7:07 PM, Roger Guay via use-livecode < > use-livecode@lists.runrev.com> wrote: > >>> > >>> > >>> Hi all, > >>> > >>> Please, what’s the easiest way to return the total number of a given > repeated number in a list of numbers? IOW, how many times is 2 repeated in > a list containing 1,2,3,2,4,2,5,2,8 etc. Appreciate your help. > >>> > >>> > >>> Thanks, > >>> > >>> Roger > > > > ___ > > use-livecode mailing list > > use-livecode@lists.runrev.com > > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > > http://lists.runrev.com/mailman/listinfo/use-livecode > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > -- On the first day, God created the heavens and the Earth On the second day, God created the oceans. On the third day, God put the animals on hold for a few hours, and did a little diving. And God said, "This is good." ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Return Total of a Given Repeated Number in a List
On 25/05/2024 16:13, Mike Kerner via use-livecode wrote: (to alex's question) * quicken date shortcuts quicken has/had these very nifty ways of handling date inputs, to make entry faster. if you enter a numeral, like 26, it means that date of this month. similarly, month/date e.g. 5/25 is 5/25 of this year. "T" is today "+" to increment the date field one day. if the date field is empty, it means tomorrow "-" "M" is the first day of this month, and "H" is the last "Y"ea"R" "W"ee"K" O - those are cool :-) I have a project to keep me busy tomorrow :-) Thanks, Alex. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode