Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14524 > unrolled thread

skipping some i, j , ... values in Table

Started byAndre Hautot <ahautot@ulg.ac.be>
First post2013-05-18 06:38 +0000
Last post2013-05-19 09:46 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  skipping some i, j , ... values in Table Andre Hautot <ahautot@ulg.ac.be> - 2013-05-18 06:38 +0000
    Re: skipping some i, j , ... values in Table spamslayer19@gmail.com - 2013-05-19 09:46 +0000
    Re: skipping some i, j , ... values in Table spamslayer19@gmail.com - 2013-05-19 09:46 +0000

#14524 — skipping some i, j , ... values in Table

FromAndre Hautot <ahautot@ulg.ac.be>
Date2013-05-18 06:38 +0000
Subjectskipping some i, j , ... values in Table
Message-ID<kn77l0$8is$1@smc.vnet.net>
Hi,
Suppose I need a list, Flatten[Table[something[i,j],{i,10},{j,10}]], 
where some combinations of indices i and j are voluntarily missing under 
a known condition (for example, stupid I know, when i+j is a prime).
How can I do that ?
Thanks in advance,
ahautot

[toc] | [next] | [standalone]


#14534

Fromspamslayer19@gmail.com
Date2013-05-19 09:46 +0000
Message-ID<kna724$fvi$1@smc.vnet.net>
In reply to#14524
Others will chime in with more elegant solutions, but I believe this does what you wanted:

f @@@ Select[
  Flatten[Table[{i, j}, {i, 1, 10}, {j, 1, 10}], 
   1], ! PrimeQ@(Plus @@ #) &]

That gives a list of f[i,j] where i+j aren't prime.

On Saturday, May 18, 2013 1:38:24 AM UTC-5, Andre Hautot wrote:
> Hi,
> 
> Suppose I need a list, Flatten[Table[something[i,j],{i,10},{j,10}]], 
> 
> where some combinations of indices i and j are voluntarily missing under 
> 
> a known condition (for example, stupid I know, when i+j is a prime).
> 
> How can I do that ?
> 
> Thanks in advance,
> 
> ahautot

[toc] | [prev] | [next] | [standalone]


#14535

Fromspamslayer19@gmail.com
Date2013-05-19 09:46 +0000
Message-ID<kna72f$fvr$1@smc.vnet.net>
In reply to#14524
Here's another solution, slightly faster for large numbers:

Rest@Flatten@
  Reap@Do[If[! PrimeQ@(i + j), Sow@f[i, j]], {i, 1, 10}, {j, 1, 10}]

On Saturday, May 18, 2013 1:38:24 AM UTC-5, Andre Hautot wrote:
> Hi,
> 
> Suppose I need a list, Flatten[Table[something[i,j],{i,10},{j,10}]], 
> 
> where some combinations of indices i and j are voluntarily missing under 
> 
> a known condition (for example, stupid I know, when i+j is a prime).
> 
> How can I do that ?
> 
> Thanks in advance,
> 
> ahautot

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web