Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.8K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Part error using Position[ ]

Posted 2 years ago

enter image description here

I am getting error in this. I think the loop is not running or maybe I am doing some syntax error. Could anyone help to rectify this? I want to loop over i here i.e. different values of i

POSTED BY: Indranil Maiti
2 Replies
Posted 2 years ago

Thanks for your time and kind reply.

POSTED BY: Indranil Maiti
Posted 2 years ago

Meta comment: When posting questions here, you should provide code in copy-paste-able form (instead of pictures). It's tedious to type it all out and make sure it's correct just to be able to reproduce the problem.

Have you read the documentation for Position? Nothing in there suggests that Position is a looping construct, so there is no reason to expect this to work by just adding {i,1,7} to the end of the expression.

Here is one way to achieve what I think you're trying to achieve. It's easier to break the problem up into small pieces, so let's start by creating the patterns you want to search for:

searchPatterns = Insert[#, _Integer, {{3}, {3}, {-1}, {-1}}] & /@ combinations1

{{1,0,_Integer,_Integer,0,1,_Integer,_Integer},{0,1,_Integer,_Integer,1,0,_Integer,_Integer},{1,0,_Integer,_Integer,0,0,_Integer,_Integer},{0,1,_Integer,_Integer,0,0,_Integer,_Integer},{0,0,_Integer,_Integer,0,1,_Integer,_Integer},{0,0,_Integer,_Integer,1,0,_Integer,_Integer},{0,0,_Integer,_Integer,0,0,_Integer,_Integer}}

Now we'll map Position over these patterns:

Position[level11, #] & /@ searchPatterns

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

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard