Message Boards Message Boards

0
|
4712 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Make a list of integers with the following pattern?

Posted 5 years ago

I want to make a code that How to assign in order.
?In detail,I want to make a list of four numbers. The first two numbers in the list are 2 and 5, and the remaining two numbers are all integers from 1 to 6. I want to output all patterns. My code like this.?

 a = Table[i, {i, 1, 6}] 
  b = Table[i, {i, 1, 6}]
  list[2, 5], a, b]

My code does not work.
I want the answer to be output like this:

{2,5,1,1},{2,5,1,2},{2,5,1,3}........{2,5,6,6}
POSTED BY: Keito Tanemura
4 Replies

Wow! The code is very simple. Thank you for me.

POSTED BY: Keito Tanemura

Keito,

Claudio's solution works well and gives you detailed control over the form of the output. There is a built in command for doing combinations like this that is worth knowing about (although Claudio's approach is more general):

Tuples[{{2}, {5}, Range[6], Range[6]}] (* give all combinations taking one item from each list *)

gives

{{2,5,1,1},{2,5,1,2},{2,5,1,3},{2,5,1,4},{2,5,1,5},{2,5,1,6},{2,5,2,1},{2,5,2,2},{2,5,2,3},{2,5,2,4},{2,5,2,5},{2,5,2,6},{2,5,3,1},{2,5,3,2},{2,5,3,3},{2,5,3,4},{2,5,3,5},{2,5,3,6},{2,5,4,1},{2,5,4,2},{2,5,4,3},{2,5,4,4},{2,5,4,5},{2,5,4,6},{2,5,5,1},{2,5,5,2},{2,5,5,3},{2,5,5,4},{2,5,5,5},{2,5,5,6},{2,5,6,1},{2,5,6,2},{2,5,6,3},{2,5,6,4},{2,5,6,5},{2,5,6,6}}

Or you could separately prepend the {2,5} and generate just the combinations of the last two items with:

Tuples[Range[6],2] (* give all combinations of 2 items from the list *)

Regards,

Neil

POSTED BY: Neil Singer

Oh!!!Yes.Thank you very much!!!

POSTED BY: Keito Tanemura

Hello Keito, the result you expect is something like this?

Map[Flatten@Join[{{2, 5}, #}] &, 
 Sort@Join[Thread[{Range@6, Range@6}], Subsets[Range@6, {2}]]]

im1

If the order of sequential terms is important then all possible pattern combinations look something like this:

Flatten[Table[{2, 5, x, y}, {x, 1, 6}, {y, 1, 6}], 1]

im2

POSTED BY: Claudio Chaib
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