2
$\begingroup$

Looking to input a $p$ for the first line:

p=6; 

Build a list of primes from the 3rd to $p-1$:

plist=Table[Prime[n],{n,3,p-1}]; 

Then build a list as follows:

bmod=Outer[Mod,{3*Prime[p]},plist] 

Here's the code so far with the output:

p=6; plist=Table[Prime[n],{n,3,p-1}]; bmod=Outer[Mod,{3*Prime[p]},plist] {{4,4,6}} 

Now I'd like to multiply each element of the list by $2$, but keep them mod their original prime, so instead of:

{{8,8,12}} 

I get:

{{3,1,1}} 

Then, I'd like to add this list to the original, still keeping the modular bounds:

{{3,1,1}} + {{4,4,6}} = {{2,5,7}} 

And then repeat this process several times, always adding to the previous line:

{{4,4,6}} {{2,5,7}} {{0,6,8}} {{3,0,9}} etc. 

Assuming you've followed my so far, how would I do that?

$\endgroup$
2
  • 1
    $\begingroup$ Your explanation doesn't seem to match your numbers. Why is the 6 not doubled to 12 in the first step? How does the 2 in {2,5,1} go to 0? 2*2 + 4 is not 0 mod 5. $\endgroup$ Commented Apr 15, 2016 at 1:55
  • $\begingroup$ @wxffles Should be fixed now. Feel free to give it a once-over. I can be quite mistake prone. $\endgroup$ Commented Apr 15, 2016 at 3:27

1 Answer 1

2
$\begingroup$

Starting with

p = 6; plist = Table[Prime[n], {n, 3, p - 1}] bmod = Outer[Mod, {3*Prime[p]}, plist] // Flatten (* {5, 7, 11} *) (* {4, 4, 6} *) 

the first result is obtained by

Thread[Mod[2 bmod, plist]] (* {3, 1, 1} *) 

To obtain the next results, use

NestList[Thread[Mod[# + bmod, plist]] &, %, 5] (* {{3, 1, 1}, {2, 5, 7}, {1, 2, 2}, {0, 6, 8}, {4, 3, 3}, {3, 0, 9}} *) 

which adds bmod to the previous result, modulo the corresponding prime in plist.

Addendum

To test whether any of the results immediately above contain 2 or 4, as requested in a comment, use

MemberQ[#, (2 | 4)] & /@ % (* {False, True, True, False, True, False} *) 
$\endgroup$
6
  • $\begingroup$ You're right. My bad. I'll edit, and give this a shot shortly. Thanks! $\endgroup$ Commented Apr 15, 2016 at 3:23
  • $\begingroup$ Does what I want! Thanks! $\endgroup$ Commented Apr 15, 2016 at 3:51
  • $\begingroup$ Hey, you've already been immensely helpful, but would you mind one more thing? I need to apply "$MemberQ$" to each individual list in that final line to test if either 2 or 4 are elements of the list. Looking for an output of "False, True, True, False, True, False" but I'm just getting the single output of "True". Thanks for helping out a newb! =) $\endgroup$ Commented Apr 15, 2016 at 4:10
  • $\begingroup$ @Elem-Teach-w-Bach-n-Math-Ed I must not understand your last comment. There are three elements in every sublist. In any case, you probably should apply Map to the list to apply whatever criterion you wish to each sublist. I can take a look tomorrow morning, if you like. $\endgroup$ Commented Apr 15, 2016 at 4:14
  • $\begingroup$ Great, I'll look into Map and give it a try. I'll let you know if I'm still having trouble. Thanks! $\endgroup$ Commented Apr 15, 2016 at 4:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.