2
$\begingroup$

I have a list of values a:

{1,4,11,14}

I want to print out values that satisfy b(1+a) = 0 mod 15 where b are the values from 0 to 14. The output I am wanting is something like:

a = 1 , b = 0
a = 4 , b = 0,3,6,9,12
a = 11 , b = 0,5,10
a = 14 , b = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

I am a beginner with Mathematica any help is appreciated

$\endgroup$
  • $\begingroup$ A HINT. When you are starting something new to you it usually seems helpful to start with a simpler project, get that to work, make it a little more complicated and repeat this until you have solved the whole problem. There are a dozen ways of doing anything in Mathematica. I'll give you a hint to get you started. Read the help page for "Do" and see in that there is one variation Do[expr, {i, {i1, i2, ...}}]. If you change that i to a, replace {i1, i2, ...} with your list of numbers and replace expr with something like Print["a=",a] then see if you can get that to work. Then work up from there $\endgroup$ – Bill Feb 21 '15 at 20:22
  • $\begingroup$ Please "Making loop based off what I can say in words" is unhelpful. What do "words" have to do with anything here? What does "based off" really mean? Nobody who has your exact question would ever type a query that will find your answers based on your title. $\endgroup$ – David G. Stork Feb 21 '15 at 23:02
2
$\begingroup$

This answer is concerned about formatting the output is the style shown in the question. I start by generating the list of b values using the method given by Mr.Wizard.

aVals = {1, 4, 11, 14};
bVals = Range[0, 14];
validate[a_] := {a, Pick[bVals, Mod[bVals (1 + a), 15], 0]}
valid = validate /@ aVals
{{1, {0}}, {4, {0, 3, 6, 9, 12}}, {11, {0, 5, 10}}, 
 {14, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}}}

Next I define a helper function for displayin a list in sequence-like format.

sequenceForm[nums_] := Row[Most@Flatten[{#, ", "} & /@ nums]]

Finally, I put the results contained in the list valid into a Grid with the proper formatting applied.

Grid[{Row[{"a = ", #[[1]], ","}], 
      Row[{"b = ", sequenceForm[#[[2]]]}]} & /@ valid,
  Alignment -> Left]

grid

$\endgroup$
6
$\begingroup$

I propose:

a = {1, 4, 11, 14};

b = Range[0, 14];

{#, Pick[b, Mod[b (1 + #), 15], 0]} & /@ a
{
 {1, {0}},
 {4, {0, 3, 6, 9, 12}},
 {11, {0, 5, 10}},
 {14, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}}
}

Anything more is formatting, which I shall leave to you.

$\endgroup$
  • $\begingroup$ my proposal was: g[u_] := u -> Range[0, 14, 15/GCD[15, u + 1]]; g/@lst but +1 of course $\endgroup$ – ubpdqn Feb 22 '15 at 11:08
1
$\begingroup$
l = {1, 4, 11, 14};
({#, b /.  Solve[Mod[b (1 + #), 15] == 0 && 0 <= b <= 14, b, Integers]} & /@  l) // Grid

Mathematica graphics

$\endgroup$
1
$\begingroup$

Just another way:

lst = {1, 4, 10, 14}
f[u_] := u ->Reap[If[Mod[(u + 1) #, 15] == 0, Sow[#]] & /@ Range[0, 14]][[-1, 1]]
f /@ lst

yields:

(*{1 -> {0}, 4 -> {0, 3, 6, 9, 12}, 11 -> {0, 5, 10}, 
 14 -> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}}*)

or perhaps:

g[u_] := u -> Range[0, 14, 15/GCD[15, u + 1]]
g/@lst
$\endgroup$
  • $\begingroup$ I like that last one. :-) $\endgroup$ – Mr.Wizard Feb 23 '15 at 3:01
0
$\begingroup$

Here's one way: build a list that contains the indices you want (called zeros) and then parse the list to get the form you want the output in:

zeros = Mod[Range[0, 14] (1 + #), 15] & /@ {1, 4, 11, 14}; 
Table[Transpose[Select[Position[zeros, 0], #[[1]] == i &]][[2]] - 1, {i, Length[zeros]}]

{{0}, {0, 3, 6, 9, 12}, {0, 5, 10}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.