MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: making a list using table but with different increment after a certain number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81506] Re: making a list using table but with different increment after a certain number
  • From: "Nasser Abbasi" <nma at 12000.org>
  • Date: Wed, 26 Sep 2007 06:40:23 -0400 (EDT)
  • References: <fd7sae$cgl$1@smc.vnet.net>

"sean_incali" <sean_incali at yahoo.com> wrote in message 
news:fd7sae$cgl$1 at smc.vnet.net...
>I can make a list using
>
> Table[a, {a, 0, 100, 10}]
>
> gives
>
> {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
>
>
> But let's say I wanted to make a list that increment in 1 up to 10,
> then increment in 10 onwards.
>
> So that after "tabling" I would get...
>
> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90,
> 100}
>
> How do I accomplish this?
>

I tried using only the Table command, but the problem is that Table must run 
for the number of iterations it is set to run, and one can't easily 'skip 
over'. May be there is a way.

But how about coding it yourself, with a simple If statement? something 
like:

m = {};
Table[If[i > 10, If[Mod[i, 10] == 0, AppendTo[m, i]], AppendTo[m, i]],
   {i, 0, 100, 1}];

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}

(you can speed this up by preallocating an array for m, and insert items 
into the array instead of appending as the above) but then you'd have to 
calculate the size of the array before hand)

if you do not like the above, how about:

m = Range[0, 10];
Flatten[AppendTo[m, Range[20, 100, 10]]]

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}

(I know you want a 'true functional' solution using Table command only).

Nasser 



  • Prev by Date: XML parsing using patterns
  • Next by Date: Re: how to get random numbers from a distribution
  • Previous by thread: Re: making a list using table but with different increment after a certain number
  • Next by thread: DynamicModule - a few questions