HyperCard Mailing List

Re: [HC] Permutations of calculations using four digits
(Msg 1 of 33)
DunbarX@[redacted].com <DunbarX@[redacted].com>
Friday, 13-May-2011 21:38 GMT
Tony.


use-livecode@[redacted].runrevcom


Craig
Re: [HC] Permutations of calculations using four digits
(Msg 2 of 33)
D <dannygelder@[redacted].com>
Saturday, 14-May-2011 06:00 GMT
Do I understand the problem as a concatenation of

random(0,1,2,3,4,5,6,7,8,9)
random(+,-,*,/)
random(1,2,3,4,5,6,7,8,9)
random(+,-,*,/)
random(2,3,4,5,6,7,8,9)
random(+,-,*,/)
random(3,4,5,6,7,8,9)

With the constraint that the result must be a positive integer? What else did I miss? This won't be too hard if you can define the problem first.
Re: [HC] Permutations of calculations using four digits
(Msg 3 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Saturday, 14-May-2011 08:52 GMT

On 14 May 2011, at 07:00, D wrote:

> Do I understand the problem as a concatenation of
>
> random(0,1,2,3,4,5,6,7,8,9)
> random(+,-,*,/)
> random(1,2,3,4,5,6,7,8,9)
> random(+,-,*,/)
> random(2,3,4,5,6,7,8,9)
> random(+,-,*,/)
> random(3,4,5,6,7,8,9)
>
> With the constraint that the result must be a positive integer? What else did I miss? This won't be too hard if you can define the problem first.
>

It's more like…

Number A - item (sequence) of (0,1,2,3,4,5,6,7,8,9)

Operator x - item (sequence) of (+,-,*,/,^,√,&)
Number B - item (sequence) of (0,1,2,3,4,5,6,7,8,9)

Operator y - item (sequence) of (+,-,*,/,^,√,&)
Number C - item (sequence) of (0,1,2,3,4,5,6,7,8,9)

Operator z - item (sequence) of (+,-,*,/,^,√,&)
Number D - item (sequence) of (0,1,2,3,4,5,6,7,8,9)

… with each 'sequence' being a repeat loop.

With random I 'might' never get to see (5/3)*(4+2)

Those are the bipartisan operators - and I have to allow for the fact that while some A z B = B z A, not all of them do.
Then there is the 'solo' concatenation ! operator - - A!, B!, C!, D! and (A • B)! etc. and ((A • B) • C)! etc.

I also need to allow for the fact that ((A • B) • C) may not be the same as (C • (A • B))

It's a swamp of nested repeats. And I hit a handler-length limitation.

Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 4 of 33)
D <dannygelder@[redacted].com>
Saturday, 14-May-2011 18:52 GMT

Handler length limitation?
Re: [HC] Permutations of calculations using four digits
(Msg 5 of 33)
Rebecca Bettencourt <beckiergb@[redacted].com>
Saturday, 14-May-2011 19:08 GMT
I don't remember there ever being a limit on handler length (besides
the 32K limit on total script size). There's no such limit mentioned
in the HyperCard Script Language Guide. If there is such a limit, that
would be interesting to know. There is a limit of 30 nested repeat
loops; maybe that's what you're running into. In any case, shouldn't
splitting the handler into multiple handlers get around this limit?

-- Rebecca Bettencourt


On Sat, May 14, 2011 at 11:52 AM, D <dannygelder@[redacted].com wrote:
>
>
>
> Handler length limitation?
>
>


Re: [HC] Permutations of calculations using four digits
(Msg 6 of 33)
Colin Holgate <coiin@[redacted].net>
Saturday, 14-May-2011 19:42 GMT
Fields and scripts were limited to 30000 characters. Not sure why it was safely under the 32768 theoretical limit. The card, background, stack, and stacksinuse scripts could obviously add up to a lot more than 30k.


On May 14, 2011, at 3:08 PM, Rebecca Bettencourt wrote:

> I don't remember there ever being a limit on handler length (besides
> the 32K limit on total script size).
Re: [HC] Permutations of calculations using four digits
(Msg 7 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Saturday, 14-May-2011 19:59 GMT

On 14 May 2011, at 19:52, D wrote:

> Handler length limitation?


I had to split a script in two (actually went to "in four" for safety) when I was stopped by an error message which quoted "handler length". I didn;t note the exact wording, but I presume it was the 30,000 characters in the Maximum Script Size HyperTalk limit.

Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 8 of 33)
Michael Mays <michael@[redacted].org>
Sunday, 15-May-2011 14:16 GMT
Tony,

How about
1&2+3/4 ?
12 or 13?

What are your rules for the factorial? Isn't it just 'short hand' for multiple multiplications and additions. N! is (N-1) multiplications and additions (adding a number to the negative of another number)? Also 0! and 1! are mathematically defined operations resulting in 1.

When you are just considering * / - + and you are truncating or rounding your results to an integer your results are in the range 0 to 3,024 inclusive. HyperCard uses 'real number multiplication' and the real numbers return by HyperCard happen to have exact integer representations over that range. But with exponentiation and the factorial the mantissa of the real number result may not be large enough to represent the 'integer' result and your answer will be approximated.

Speed of calculation is important only if the time to calculate your complete set is determined by how long you can run the calculation. For your game you would just keep the results in a file/card (maybe also with their associated calculations) and do a look up instead of the calculation.

Michael

On May 13, 2011, at 3:50 AM, Tony McCoy O'Grady wrote:
> On 12 May 2011, at 21:39, Deivy Petrescu wrote:
> Do you consider 1,2,3,4 forming 12 as a concatenation?
> Only it the 1 is arrived at in the calculation ((8-4)-3)&2 = 12
Re: [HC] Permutations of calculations using four digits
(Msg 9 of 33)
Colin Holgate <coiin@[redacted].net>
Sunday, 15-May-2011 15:19 GMT
I was emailing Bill Atkinson about something else, so I asked about why it was a limit of 30,000 and not 32,768. His reasons included ones I suspected, the main two being that 30,000 is a friendlier number for lay people to understand, and also it allowed for a little slop to help the length checking calculation be reliable. If the limit was really 32,767, and the calculation was slightly out, that would lead to having negative lengths.


On May 14, 2011, at 3:59 PM, Tony McCoy O'Grady wrote:

> I presume it was the 30,000 characters in the Maximum Script Size HyperTalk limit.



[Non-text portions of this message have been removed]
Re: [HC] Permutations of calculations using four digits
(Msg 10 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Monday, 16-May-2011 09:07 GMT
On 15 May 2011, at 15:16, Michael Mays wrote:

> How about
> 1&2+3/4 ?
> 12 or 13?

Neither

3/4 will always be calculated (by HyperCard and everyone else) before addition. So the result of 1&2+3/4 will be 12.75 - and as a non-integer will notbe a valid solution to my query - what positive integers can be created from the given digits.


> What are your rules for the factorial? Isn't it just 'short hand' for multiple multiplications and additions. N! is (N-1) multiplications and additions (adding a number to the negative of another number)? Also 0! and 1! aremathematically defined operations resulting in 1.

I think you might be confusing/conflating 'factorial' with 'summation'
Factorials are repeated multiplications down to 1 so that 5! = 5 x 4
x 3 x 2 (x 1) = 120


> When you are just considering * / - + and you are truncating or roundingyour results to an integer your results are in the range 0 to 3,024 inclusive.

As I indicated above, I am neither truncating nor rounding. I am only interested in having positive integers reported to me

> Speed of calculation is important only if the time to calculate your complete set is determined by how long you can run the calculation. For your game you would just keep the results in a file/card (maybe also with their associated calculations) and do a look up instead of the calculation.

As I said at the end of the original post

"This problem is not 'important' to me but it is intriguing me - it is a curiosity along the way as I create a game based on the use of the digits andoperators to create as many numbers as the player can. If I get a good working result from this I might be able to include a 'cheat' in the game if the player is stuck - but that would be just whistles and bells on the basicidea."

If I get an exhaustive list then I would like to include the list in the back-office of the game and draw on it if a player cannot get a solution to how to form a particular integer, then I could offer either a hint or a cheat.


Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 11 of 33)
Michael Mays <michael@[redacted].org>
Monday, 16-May-2011 16:53 GMT
No. I was describing the operations not the actual process of calculating it. The factorial is a short cut representing a specific product of sequences (capital Pi (∏) notation).

N-1
∏ (N-i)
i=0

when you write out the sequence it looks like:
(N-0)*(N-1)*(N-2)* ... *(N-(N-1))
which is N subtractions (additions) and N-1 multiplications

Also, if you are including the factorial how are you handling it? Does it always have to be the last operation?

Michael

On May 16, 2011, at 4:07 AM, Tony McCoy O'Grady wrote:

> I think you might be confusing/conflating 'factorial' with 'summation'
> Factorials are repeated multiplications down to 1 … so that 5! = 5 x 4 x 3 x 2 (x 1) = 120


[Non-text portions of this message have been removed]
Re: [HC] Permutations of calculations using four digits
(Msg 12 of 33)
Rebecca Bettencourt <beckiergb@[redacted].com>
Monday, 16-May-2011 17:46 GMT
On Sun, May 15, 2011 at 8:19 AM, Colin Holgate <coiin@[redacted].net wrote:
> I was emailing Bill Atkinson about something else, so I asked about
> why it was a limit of 30,000 and not 32,768. His reasons included
> ones I suspected, the main two being that 30,000 is a friendlier
> number for lay people to understand, and also it allowed for a little
> slop to help the length checking calculation be reliable. If the limit
> was really 32,767, and the calculation was slightly out, that would
> lead to having negative lengths.

I always thought it was because HyperTalk code is compiled to machine
code when it is first run, and sometimes the compiled code is slightly
longer than the source code, so the 30,000 limit allows for that.

I remember reading something about when the PowerPC version of
HyperCard came out, some people ran into a maximum script length limit
at less than the expected 30,000 characters because compiled PowerPC
code is longer than compiled 68K code.

HyperCard itself actually imposes a 29,999 character limit (an attempt
to make it an even 30,000 results in a "can't set that property" or
"failed to save script" error). Theoretically, though, there is no
reason a script can't be as long as 32767 characters as long as the
compiled version isn't any longer; you'd just have to hack it in.

-- Rebecca Bettencourt
Re: [HC] Permutations of calculations using four digits
(Msg 13 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Monday, 16-May-2011 18:11 GMT

On 16 May 2011, at 17:53, Michael Mays wrote:

>
> Also, if you are including the factorial how are you handling it? Does it always have to be the last operation?

It's the first thing I assess, as it's the only thing which HC can't do from the symbol, and so it doesn't have an 'order of precedence' to work to.

The root function is handled next as it means converting the A√B operation into a B^(1/A) operation.

Where possible I use brackets to force the order of precedence, and think I have a scheme which covers most eventualities.

As yet I haven't coded for the inclusion of the concatenation symbol - just the others took several days to run through. It was my decision to include the concatenation that prompted me to seek speed advice.

Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 14 of 33)
Michael Mays <michael@[redacted].org>
Monday, 16-May-2011 20:51 GMT
So for a set such as 3,5,7,9 on number could be
3! + 4 + 5 + 7 ?
Is
3! + 4! + 5! + 7!
and
(3 + 4 )! + (5 + 7 )!
valid?

Michael



On May 16, 2011, at 1:11 PM, Tony McCoy O'Grady wrote:

>
> On 16 May 2011, at 17:53, Michael Mays wrote:
>
>>
>> Also, if you are including the factorial how are you handling it? Does it always have to be the last operation?
>
> It's the first thing I assess, as it's the only thing which HC can't do from the symbol, and so it doesn't have an 'order of precedence' to work to.
>
Re: [HC] Permutations of calculations using four digits
(Msg 15 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Tuesday, 17-May-2011 08:12 GMT

On 16 May 2011, at 21:51, Michael Mays wrote:

> So for a set such as 3,5,7,9 on number could be
> 3! + 4 + 5 + 7 ?
> Is
> 3! + 4! + 5! + 7!
> and
> (3 + 4 )! + (5 + 7 )!
> valid?


Yes - as are

(5! * 7!) / (3! * 4!)
and
(4!-3!)^(7-5)
etc

In brief, anything which combines any of the operators with the digits, in any order of operation or digits, which produces a positive integer is a 'result'.

Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 16 of 33)
Uli Kusterer <Witness.of.TeachText@[redacted].net>
Tuesday, 17-May-2011 08:48 GMT
On 13.05.2011, at 18:38, Tony McCoy O'Grady wrote:
>> You have to do a lot of mental juggling to try to compose a system that will exhaustively get all the possibilities. I am already dizzy.
>
> it doesn't need to be utterly exhaustive - all integers of less than 5 digits would be good.

If it's just generating all the combinations, all you do is one nested loop per digit:

repeat with w = 0 to 9
repeat with x = 0 to 9
repeat with y = 0 to 9
repeat with z = 0 to 9
put w & x & y & z & comma after myVariable
end repeat
end repeat
end repeat
end repeat

myVariable is now a comma-delimited list of all the numbers from 0 through 9999 (well, 0000 etc. with leading zeroes, but that is the same number).

You can use the same approach if you want to combine a bunch of other things in all possible variations. Just put the possible values for each slot in a list, then use e.g. w as the index into the array for the first slot (and instead of 0 to 9 go to from 1 to number of items).

Also, variables are not only faster than fields in HyperCard, they also don't have a 32k limit AFAIR. You can now loop over myVariable and create a card for each.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
Re: [HC] Permutations of calculations using four digits
(Msg 17 of 33)
Uli Kusterer <Witness.of.TeachText@[redacted].net>
Tuesday, 17-May-2011 09:29 GMT
On 14.05.2011, at 21:59, Tony McCoy O'Grady wrote:
> I had to split a script in two (actually went to "in four" for safety) when I was stopped by an error message which quoted "handler length". I didn;t note the exact wording, but I presume it was the 30,000 characters in the Maximum Script Size HyperTalk limit.

AddColor did that, too. They actually had an extra field (or was it even a resource? Can't remember) that they replaced a button's script with, to send it some more messages. Madness.

Cheers,
-- Uli Kusterer
http://stacksmith.com
Re: [HC] Permutations of calculations using four digits
(Msg 18 of 33)
Uli Kusterer <Witness.of.TeachText@[redacted].net>
Tuesday, 17-May-2011 09:37 GMT
On 16.05.2011, at 19:46, Rebecca Bettencourt wrote:
> On Sun, May 15, 2011 at 8:19 AM, Colin Holgate <coiin@[redacted].net wrote:
>> I was emailing Bill Atkinson about something else, so I asked about
>> why it was a limit of 30,000 and not 32,768. His reasons included
>> ones I suspected, the main two being that 30,000 is a friendlier
>> number for lay people to understand, and also it allowed for a little
>> slop to help the length checking calculation be reliable. If the limit
>> was really 32,767, and the calculation was slightly out, that would
>> lead to having negative lengths.
>
> I always thought it was because HyperTalk code is compiled to machine
> code when it is first run, and sometimes the compiled code is slightly
> longer than the source code, so the 30,000 limit allows for that.

AFAIK the compiler was introduced with HyperCard 2.0, which Atkinson no longer worked on.

> I remember reading something about when the PowerPC version of
> HyperCard came out, some people ran into a maximum script length limit
> at less than the expected 30,000 characters because compiled PowerPC
> code is longer than compiled 68K code.

Would love to read more about that, if you can find anything.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://groups.yahoo.com/group/mac-gui-dev/
Re: [HC] Permutations of calculations using four digits
(Msg 19 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Tuesday, 17-May-2011 10:35 GMT

On 17 May 2011, at 09:48, Uli Kusterer wrote:

> repeat with w = 0 to 9
> repeat with x = 0 to 9
> repeat with y = 0 to 9
> repeat with z = 0 to 9
> put w & x & y & z & comma after myVariable
> end repeat
> end repeat
> end repeat
> end repeat
>
> myVariable is now a comma-delimited list of all the numbers from 0 through 9999 (well, 0000 etc. with leading zeroes, but that is the same number).
>
> You can use the same approach if you want to combine a bunch of other things in all possible variations. Just put the possible values for each slot in a list, then use e.g. w as the index into the array for the first slot (and instead of 0 to 9 go to from 1 to number of items).
>
> Also, variables are not only faster than fields in HyperCard, they also don't have a 32k limit AFAIR. You can now loop over myVariable and create a card for each.


This is pretty much what I'm doing at the moment, with the addition of

Three 1-9 loops for each of the operators - +,-,*,*-,/,/-,^,√,& to go in between each digit, and four 1 - 2 loops to generate the factorials, and further repeat loops to generate the factorials of (w • x) etc.

As I said elsewhere, it's a swamp of repeat loops - un-nesting as many as possible is the aim, I think.

I'm making headway and will post the final script eventually.


Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 20 of 33)
Michael Mays <michael@[redacted].org>
Tuesday, 17-May-2011 15:38 GMT
I think Tony wanted the number of combinations with repetition not all the permutations with repetition.

Suppose you have 2 colored balls and you want to know the number of permutations with repetition:
RR
RY
YR
YY
The number of combinations with repetition are:
RR
RY (equivalent to the combination YR)
YY

Michael


On May 17, 2011, at 3:48 AM, Uli Kusterer wrote:

> On 13.05.2011, at 18:38, Tony McCoy O'Grady wrote:
>>> You have to do a lot of mental juggling to try to compose a system that will exhaustively get all the possibilities. I am already dizzy.
>>
>> it doesn't need to be utterly exhaustive - all integers of less than 5 digits would be good.
>
> If it's just generating all the combinations, all you do is one nested loop per digit:
>
> repeat with w = 0 to 9
> repeat with x = 0 to 9
> repeat with y = 0 to 9
> repeat with z = 0 to 9
> put w & x & y & z & comma after myVariable
> end repeat
> end repeat
> end repeat
> end repeat
>
> myVariable is now a comma-delimited list of all the numbers from 0 through 9999 (well, 0000 etc. with leading zeroes, but that is the same number).
>
> You can use the same approach if you want to combine a bunch of other things in all possible variations. Just put the possible values for each slot in a list, then use e.g. w as the index into the array for the first slot (and instead of 0 to 9 go to from 1 to number of items).
>
> Also, variables are not only faster than fields in HyperCard, they also don't have a 32k limit AFAIR. You can now loop over myVariable and create a card for each.
>
> Cheers,
> -- Uli Kusterer
> "The Witnesses of TeachText are everywhere..."
>
>
>
>
>
>
Re: [HC] Permutations of calculations using four digits
(Msg 21 of 33)
DunbarX@[redacted].com <DunbarX@[redacted].com>
Tuesday, 17-May-2011 15:43 GMT
Tony correctly calculated this early on, the number being 715.


Craig Newman
Re: [HC] Permutations of calculations using four digits
(Msg 22 of 33)
David Karger <karger@[redacted].edu>
Tuesday, 17-May-2011 16:10 GMT
if you want to avoid nested loops you can make use of a permutation
numbering:
https://secure.wikimedia.org/wikipedia/en/wiki/Factorial_number_system

On 5/17/2011 11:43 AM, DunbarX@[redacted].comwrote:
>
> Tony correctly calculated this early on, the number being 715.
>
> Craig Newman
>
> -----Original Message-----
> From: Michael Mays <michael@[redacted].org<mailto:michael%40ihug.org>>
> To: HyperCard-Mailing-List <mailto:HyperCard%40yahoogroups.com>
> Sent: Tue, May 17, 2011 11:38 am
> Subject: Re: [HC] Permutations of calculations using four digits
>
> I think Tony wanted the number of combinations with repetition not all
> the permutations with repetition.
>
> Suppose you have 2 colored balls and you want to know the number of
> permutations with repetition:
> RR
> RY
> YR
> YY
> The number of combinations with repetition are:
> RR
> RY (equivalent to the combination YR)
> YY
>
> Michael
>
> On May 17, 2011, at 3:48 AM, Uli Kusterer wrote:
>
> > On 13.05.2011, at 18:38, Tony McCoy O'Grady wrote:
> >>> You have to do a lot of mental juggling to try to compose a system
> that will exhaustively get all the possibilities. I am already dizzy.
> >>
> >> it doesn't need to be utterly exhaustive - all integers of less
> than 5 digits would be good.
> >
> > If it's just generating all the combinations, all you do is one
> nested loop per digit:
> >
> > repeat with w = 0 to 9
> > repeat with x = 0 to 9
> > repeat with y = 0 to 9
> > repeat with z = 0 to 9
> > put w & x & y & z & comma after myVariable
> > end repeat
> > end repeat
> > end repeat
> > end repeat
> >
> > myVariable is now a comma-delimited list of all the numbers from 0
> through 9999 (well, 0000 etc. with leading zeroes, but that is the
> same number).
> >
> > You can use the same approach if you want to combine a bunch of
> other things in all possible variations. Just put the possible values
> for each slot in a list, then use e.g. w as the index into the array
> for the first slot (and instead of 0 to 9 go to from 1 to number of
> items).
> >
> > Also, variables are not only faster than fields in HyperCard, they
> also don't have a 32k limit AFAIR. You can now loop over myVariable
> and create a card for each.
> >
> > Cheers,
> > -- Uli Kusterer
> > "The Witnesses of TeachText are everywhere..."
> >
> >
> >
> >
> >
> >
Re: [HC] Permutations of calculations using four digits
(Msg 23 of 33)
Michael Mays <michael@[redacted].org>
Tuesday, 17-May-2011 16:21 GMT
Yes but Uli's calculation was 10,000. Nested loops are good for permutations. Combinations are not so simply enumerated.
Michael

On May 17, 2011, at 10:43 AM, DunbarX@[redacted].comwrote:

> Tony correctly calculated this early on, the number being 715.
>
>
> Craig Newman
>
>
>
>
>
> -----Original Message-----
> From: Michael Mays <michael@[redacted].org
> To: HyperCard-Mailing-List
> Sent: Tue, May 17, 2011 11:38 am
> Subject: Re: [HC] Permutations of calculations using four digits
>
>
>
>
>
> I think Tony wanted the number of combinations with repetition not all the permutations with repetition.
>
> Suppose you have 2 colored balls and you want to know the number of permutations with repetition:
> RR
> RY
> YR
> YY
> The number of combinations with repetition are:
> RR
> RY (equivalent to the combination YR)
> YY
>
> Michael
>
> On May 17, 2011, at 3:48 AM, Uli Kusterer wrote:
>
>> On 13.05.2011, at 18:38, Tony McCoy O'Grady wrote:
>>>> You have to do a lot of mental juggling to try to compose a system that will exhaustively get all the possibilities. I am already dizzy.
>>>
>>> it doesn't need to be utterly exhaustive - all integers of less than 5 digits would be good.
>>
>> If it's just generating all the combinations, all you do is one nested loop per digit:
>>
>> repeat with w = 0 to 9
>> repeat with x = 0 to 9
>> repeat with y = 0 to 9
>> repeat with z = 0 to 9
>> put w & x & y & z & comma after myVariable
>> end repeat
>> end repeat
>> end repeat
>> end repeat
>>
>> myVariable is now a comma-delimited list of all the numbers from 0 through 9999 (well, 0000 etc. with leading zeroes, but that is the same number).
>>
>> You can use the same approach if you want to combine a bunch of other things in all possible variations. Just put the possible values for each slot in a list, then use e.g. w as the index into the array for the first slot (and instead of 0 to 9 go to from 1 to number of items).
>>
>> Also, variables are not only faster than fields in HyperCard, they also don't have a 32k limit AFAIR. You can now loop over myVariable and create a card for each.
>>
>> Cheers,
>> -- Uli Kusterer
>> "The Witnesses of TeachText are everywhere..."
>>
>>
>>
>>
>>
>>
Re: [HC] Permutations of calculations using four digits
(Msg 24 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Tuesday, 17-May-2011 18:35 GMT

On 17 May 2011, at 16:43, DunbarX@[redacted].comwrote:

> Tony correctly calculated this early on, the number being 715.
>

Indeed.
Once I have done the permutations for all operators on the digits 1,2,3,4
I do not need to revisit them. so after the card for 1,2,3,9, the next card I do is 1.2,4,4 - skipping 1,2,4,3


Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 25 of 33)
Michael Mays <michael@[redacted].org>
Wednesday, 18-May-2011 01:47 GMT
And if you do all the permutations of 6 binary operators including the 5 different orderings for each permutation due to parenthesis on each of those 715 _COMBINATIONS_ you will need to do 772,200 calculations.
Michael


On May 17, 2011, at 1:35 PM, Tony McCoy O'Grady wrote:

>
> On 17 May 2011, at 16:43, DunbarX@[redacted].comwrote:
>
>> Tony correctly calculated this early on, the number being 715.
>>
>
> Indeed.
> Once I have done the permutations for all operators on the digits 1,2,3,4
> I do not need to revisit them. so after the card for 1,2,3,9, the next card I do is 1.2,4,4 - skipping 1,2,4,3
>
>
> Tony McCoy O'Grady
Re: [HC] Permutations of calculations using four digits
(Msg 26 of 33)
DunbarX@[redacted].com <DunbarX@[redacted].com>
Wednesday, 18-May-2011 01:51 GMT
That should take at least a half minute...


Craig Newman
Re: [HC] Permutations of calculations using four digits
(Msg 27 of 33)
Michael Mays <michael@[redacted].org>
Wednesday, 18-May-2011 14:10 GMT
A year is at least half a minute ;)

Long gone are the days I could go and get a cup of coffee while HyperCard was in the process of tabbing to the next field. [exaggeration]

Michael

On May 17, 2011, at 8:51 PM, DunbarX@[redacted].comwrote:

> That should take at least a half minute...
>
>
> Craig Newman
>
>
>
>
>
> -----Original Message-----
> From: Michael Mays <michael@[redacted].org
> To: HyperCard-Mailing-List
> Sent: Tue, May 17, 2011 9:47 pm
> Subject: Re: [HC] Permutations of calculations using four digits
>
>
>
>
>
> And if you do all the permutations of 6 binary operators including the 5 different orderings for each permutation due to parenthesis on each of those 715 _COMBINATIONS_ you will need to do 772,200 calculations.
> Michael
>
> On May 17, 2011, at 1:35 PM, Tony McCoy O'Grady wrote:
>
>>
>> On 17 May 2011, at 16:43, DunbarX@[redacted].comwrote:
>>
>>> Tony correctly calculated this early on, the number being 715.
>>>
>>
>> Indeed.
>> Once I have done the permutations for all operators on the digits 1,2,3,4
>> I do not need to revisit them. so after the card for 1,2,3,9, the next card I do is 1.2,4,4 - skipping 1,2,4,3
>>
>>
>> Tony McCoy O'Grady
>
>
>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
Re: [HC] Permutations of calculations using four digits
(Msg 28 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Sunday, 12-Jun-2011 18:23 GMT
Hi oh wise ones,

I have a stack of 715 cards of one background.
The first four bg fields hold a single digit from 0 to 9.
Card 1 carries 0,0,0,0 in these fields and all the (ordered) combinations of digits are covered in the cards up to card 715 which holds 9,9,9,9

I can have any number of other fields on the background.

What I am trying to achieve is to use all four digits on any given card once each, with any combination of maths operators to create an exhaustive list of the different positive integers which can be created from the four given digits. The digits can be used alone or in combinations such that 4 and 8 can be 48 without the use of an operator. Brackets are available to force the assessment of an expression to comply with the usual BOMDAS order, as anything in brackets, even nested brackets, is handled firstly.

The operators other than *,/,+ and - which I use are
a) the factorial symbol (!) [which may me used if a number if greater than 2];
b) the root operator (√) which can only be used in conjunction with a leading number [which must be constructed from one of the 4 available digits] to give square roots, cube roots, etc
c) the exponent symbol (^); and
d) the concatenation symbol (&) which can be used to append an available number to an already calculated number, such that ((2*8)-4)&3 = 123

The multiply and divide operators can have a minus sign follow them to give 6/-3 for example. There is not limit to the operators which can be used. and in the case of 1,2,3,4 there are 12 numbers which can be created without using any operators.

At present I am taking the operators in the order Factorials, Roots, BOMDAS and then Concatenation

The code I have created to do this is incredibly slow, even though it traps for any NAN or INF errors and ignores negative or non-integer results.

Can anyone offer me some pointers to an efficient and speedy execution of what must surely be able to be speedily executed?

Once I have a solution for A.B.C.D = X then I don't need the code to report a new expression which yields the same result. (Although I might, in the future, be interested in how many ways the given digits can be manipulated to create a certain number.

This problem is not 'important' to me but it is intriguing me - it is a curiosity along the way as I create a game based on the use of the digits and operators to create as many numbers as the player can. If I get a good working result from this I might be able to include a 'cheat' in the game if the player is stuck - but that would be just whistles and bells on the basic idea.

I look forward to interesting suggestions.

Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 29 of 33)
Deivy Petrescu <hypercard@[redacted].com>
Sunday, 12-Jun-2011 18:23 GMT

On May 12, 2011, at 16:11 , Tony McCoy O'Grady wrote:

> Hi oh wise ones,
>
> I have a stack of 715 cards of one background.
> The first four bg fields hold a single digit from 0 to 9.
> Card 1 carries 0,0,0,0 in these fields and all the (ordered) combinations of digits are covered in the cards up to card 715 which holds 9,9,9,9
>
> I can have any number of other fields on the background.
>
> What I am trying to achieve is to use all four digits on any given card once each, with any combination of maths operators to create an exhaustive list of the different

> positive integers

Just stressing you said **positive integers**

> which can be created from the four given digits. The digits can be used alone or in combinations such that 4 and 8 can be 48 without the use of an operator. Brackets are available to force the assessment of an expression to comply with the usual BOMDAS order, as anything in brackets, even nested brackets, is handled firstly.
>
> The operators other than *,/,+ and - which I use are
> a) the factorial symbol (!) [which may me used if a number if greater than 2];
> b) the root operator (√) which can only be used in conjunction with a leading number [which must be constructed from one of the 4 available digits] to give square roots, cube roots, etc

When you use the root operator are you using a number of the list of 4 numbers or not? That is if you use square root are you using a 2? A cube root uses the 3?
But one must be careful not to get the result as an irrational, as per positive integers, right?

> c) the exponent symbol (^); and
> d) the concatenation symbol (&) which can be used to append an available number to an already calculated number, such that ((2*8)-4)&3 = 123
>
> The multiply and divide operators can have a minus sign follow them to give 6/-3 for example.

Why would you use a - sign if the result you want is positive?


> There is not limit to the operators which can be used. and in the case of 1,2,3,4 there are 12 numbers which can be created without using any operators.

I can count 4 numbers without any operation.
Unless your concatenation is only to add to an "expression" as your example above.
Do you consider 1,2,3,4 forming 12 as a concatenation?
If not, then 1,2,3,4 form 4+12+24+24 different numbers ( all possible permutation of 1,2,3 and 4 digits)

>
> At present I am taking the operators in the order Factorials, Roots, BOMDAS and then Concatenation
>
> The code I have created to do this is incredibly slow, even though it traps for any NAN or INF errors and ignores negative or non-integer results.
>
> Can anyone offer me some pointers to an efficient and speedy execution of what must surely be able to be speedily executed?
>
> Once I have a solution for A.B.C.D = X then I don't need the code to report a new expression which yields the same result. (Although I might, in the future, be interested in how many ways the given digits can be manipulated to create a certain number.
>
> This problem is not 'important' to me but it is intriguing me - it is a curiosity along the way as I create a game based on the use of the digits and operators to create as many numbers as the player can. If I get a good working result from this I might be able to include a 'cheat' in the game if the player is stuck - but that would be just whistles and bells on the basic idea.
>
> I look forward to interesting suggestions.
>
> Tony McCoy O'Grady
> -=-=-=-=-=-=-=-=-=-=-=-=-=
> If I had stopped to listen once or twice
> If I had closed my mouth and opened my eyes
> If I had cooled my head and warmed my heart
> I'd not be on this road tonight
>
Re: [HC] Permutations of calculations using four digits
(Msg 30 of 33)
DunbarX@[redacted].com <DunbarX@[redacted].com>
Sunday, 12-Jun-2011 18:23 GMT
Tony.


This will drive you mad. At least post it as well to the LC list. Might as well annoy them too.


You have to do a lot of mental juggling to try to compose a system that will exhaustively get all the possibilities. I am already dizzy.


Craig Newman
Re: [HC] Permutations of calculations using four digits
(Msg 31 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Sunday, 12-Jun-2011 18:24 GMT

On 12 May 2011, at 21:39, Deivy Petrescu wrote:

>> positive integers
>
> Just stressing you said **positive integers**

Yes. Because I imagine that accepting negatives would not 'improve' the problem, as any string could be converted to a negative, and vice-versa

> When you use the root operator are you using a number of the list of 4 numbers or not? That is if you use square root are you using a 2? A cube root uses the 3?
> But one must be careful not to get the result as an irrational, as per positive integers, right?

Right. That is why I trap for NAN

>
>> c) the exponent symbol (^); and
>> d) the concatenation symbol (&) which can be used to append an available number to an already calculated number, such that ((2*8)-4)&3 = 123
>>
>> The multiply and divide operators can have a minus sign follow them to give 6/-3 for example.
>
> Why would you use a - sign if the result you want is positive?

Because the end result could be positive, depending on the order the person enters the digits. (4-8)*(6/-3) = 8

>
>
>> There is not limit to the operators which can be used. and in the case of 1,2,3,4 there are 12 numbers which can be created without using any operators.
>
> I can count 4 numbers without any operation.
> Unless your concatenation is only to add to an "expression" as your example above.

Sorry, I should have said 24.

1234 - 1243 - 1324 - 1342- 1423 - 1432
2134 - 2143 - 2314 - 2341 - 2413 - 2431
3124 - 3142 - 3214 - 3241 - 3412 - 3421
4123 - 4132 - 4213 - 4231 - 4312 - 4321


> Do you consider 1,2,3,4 forming 12 as a concatenation?

Only it the 1 is arrived at in the calculation ((8-4)-3)&2 = 12


> I like the problem.


I've been with it for weeks and it grows tiresome, :-)

Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 32 of 33)
Tony McCoy O'Grady <maxiogee@[redacted].ie>
Sunday, 12-Jun-2011 18:24 GMT

On 13 May 2011, at 00:16, DunbarX@[redacted].comwrote:

> Tony.
>
>
> This will drive you mad.

Common assumption by friends and family is that I already am.
My doctors mention depression/dual diagnosis.

So there'll be no change there then!


> At least post it as well to the LC list. Might as well annoy them too.

I knew they had a forum, didn't know there was also a list.... where do I enrol?



> You have to do a lot of mental juggling to try to compose a system that will exhaustively get all the possibilities. I am already dizzy.

it doesn't need to be utterly exhaustive - all integers of less than 5 digits would be good.

HyperCard burped because of its 32,000 char limit - which I hadn't anticipated.


Tony McCoy O'Grady
-=-=-=-=-=-=-=-=-=-=-=-=-=
If I had stopped to listen once or twice
If I had closed my mouth and opened my eyes
If I had cooled my head and warmed my heart
I'd not be on this road tonight
Re: [HC] Permutations of calculations using four digits
(Msg 33 of 33)
J. Landman Gay <jacque@[redacted].com>
Sunday, 12-Jun-2011 18:24 GMT
On 5/13/11 11:38 AM, Tony McCoy O'Grady wrote:

>> At least post it as well to the LC list. Might as well annoy them too.
>
> I knew they had a forum, didn't know there was also a list.... where do I enrol?

<http://lists.runrev.com/mailman/listinfo/use-livecode/>;

There are far more pro developers on the list than in the forums, and
many of them don't participate in the forums at all. The list is highly
recommended.

--
Jacqueline Landman Gay | jacque@[redacted].comHyperActive Software | http://www.hyperactivesw.com
HyperCard® and HyperTalk™ remain trademarks of Apple, Inc.; other trademarked products and terms mentioned in this archive are the property of their respective trademark holders. Individual messages remain the intellectual property of their respective authors.