Message Boards Message Boards

0
|
4207 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

[?] Write all outputs in a set?

Posted 6 years ago

Hello all, I try to put all outputs in a set. Unfortunately I cannot it. Here is the program:

p = 7;
Do[
 Do[
  If[t^2 + t*k + k^2 == p, {a = t, b = k}]
  , {t, 1, p}]
 , {k, 1, p}]
tt = a + b - 1;
Do[If[Mod[a + b*s, p] == 0, r = s], {s, 0, p - 1}]

Do[Do[If[Mod[x + y*r, p] == 0 && 
    Min[Abs[x] + Abs[y]] < Abs[tt] + Abs[tt], Print[x]],
  {x, -tt, tt}],
 {y, -tt, tt}]

the outputs seems as -1,0,1. I want to obtain the outputs as {-1,0,1}. How can I do that? Thanks in advanced

POSTED BY: murat guzeltepe
(Do[Do[If[
      Mod[x + y*r, p] == 0 && 
       Min[Abs[x] + Abs[y]] < Abs[tt] + Abs[tt], Sow[x]], {x, -tt, 
      tt}], {y, -tt, tt}] // Reap)[[2, 1]]
POSTED BY: l van Veen
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract