DuncanA

713 Reputation

8 Badges

18 years, 264 days

MaplePrimes Activity


These are replies submitted by DuncanA

Here is a version that handles ties according to the Wikipedia description of the card game.

Card_Game,War.mw

---

Duncan

Here is a version that handles ties according to the Wikipedia description of the card game.

Card_Game,War.mw

---

Duncan

@goli 

Based on Robert Israel's post, the Array T can be sorted by its third column as follows:

A := sort(Array(1..16, i->T[i]), (a,b) -> (a[3]>=b[3]));
Array(ArrayDims(T),(i,j)->A[i][j]);

@goli 

Based on Robert Israel's post, the Array T can be sorted by its third column as follows:

A := sort(Array(1..16, i->T[i]), (a,b) -> (a[3]>=b[3]));
Array(ArrayDims(T),(i,j)->A[i][j]);

@goli 

One way of doing this is to store the data in an Array then write the array to a file.

T := Array(1..16, 1..3):
idx := 1:
for m from 1 by 1 to 4 do
  for n from 1 by 1 to 4 do
    alpha := m+n;
    T[idx, 1] := m;
    T[idx, 2] := n;
    T[idx, 3] := alpha;
    idx := idx + 1
  od;
od;

writedata("test.dat", convert(T, array), integer);


@goli 

One way of doing this is to store the data in an Array then write the array to a file.

T := Array(1..16, 1..3):
idx := 1:
for m from 1 by 1 to 4 do
  for n from 1 by 1 to 4 do
    alpha := m+n;
    T[idx, 1] := m;
    T[idx, 2] := n;
    T[idx, 3] := alpha;
    idx := idx + 1
  od;
od;

writedata("test.dat", convert(T, array), integer);


@goli The easiest way to do what you ask is to call print within the inner loop

for m from 1 by 1 to 4 do
  for n from 1 by 1 to 4 do
    alpha := m+n;
    print(m,n,alpha);
  od;
od;

With printlevel := 1; (the default) the output from the alpha := m+n; statement won't appear.

@goli The easiest way to do what you ask is to call print within the inner loop

for m from 1 by 1 to 4 do
  for n from 1 by 1 to 4 do
    alpha := m+n;
    print(m,n,alpha);
  od;
od;

With printlevel := 1; (the default) the output from the alpha := m+n; statement won't appear.

Use three variables on left hand side of assignment

a, b, c := test(alpha, beta);

 

---

Duncan

Use three variables on left hand side of assignment

a, b, c := test(alpha, beta);

 

---

Duncan

I experience the same problem, but only with the Standard Worksheet in Document Mode, and only when I press Shift+Enter to add newlines in the declaration of the for loop. If the for loop is all on one line without Shift+Enter then the error doesn't manifest itself. I'm using Maple 12.

---

Duncan

@sasomao Sorry, I didn't realise that it happened randomly. I was thinking that you were running the same script on different machines and that it failed on one machine, but not on another. This made me think that perhaps a problem with an external library was to blame.

@sasomao Sorry, I didn't realise that it happened randomly. I was thinking that you were running the same script on different machines and that it failed on one machine, but not on another. This made me think that perhaps a problem with an external library was to blame.

@alex_01 Here are two worksheets that perform the tasks in parallel. Both use Threads not Tasks. I'm using Maple 12 which doesn't support Tasks.

Counting_7s_with_Thr.mw

Importing_Quotes_wit.mw

@alex_01 Here are two worksheets that perform the tasks in parallel. Both use Threads not Tasks. I'm using Maple 12 which doesn't support Tasks.

Counting_7s_with_Thr.mw

Importing_Quotes_wit.mw

1 2 3 4 Page 3 of 4