Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: List:{1}, {2,3},{4,5,6}....
Replies: 2   Last Post: Jan 14, 2013 12:01 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bob Hanlon

Posts: 895
Registered: 10/29/11
Re: List:{1}, {2,3},{4,5,6}....
Posted: Jan 11, 2013 10:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

m = 5;

t1 = Timing[
list1 = Table[
i + 1, {n, 1, m}, {i, n (n - 1)/2, n (n - 1)/2 + n - 1}];][[1]]

0.000083

t2 = Timing[
list2 = Table[Range[n (n - 1)/2 + 1, n (n + 1)/2], {n, m}];][[1]]

0.000054

t1/t2

1.5

list1 == list2

True

m = 1000;

t3 = Timing[
list3 = Table[
i + 1, {n, 1, m}, {i, n (n - 1)/2, n (n - 1)/2 + n - 1}];][[1]]

0.368475

t4 = Timing[
list4 = Table[Range[n (n - 1)/2 + 1, n (n + 1)/2], {n, m}];][[1]]

0.010008

t3/t4

36.82

list3 == list4

True


Bob Hanlon


On Thu, Jan 10, 2013 at 9:39 PM, hknetman <hknetman@hotmail.com> wrote:
> I use the command
> list = Table[i + 1, {n, 1, 5}, {i, n (n - 1)/2, n (n - 1)/2 + n - 1}]
> to get the following result:
> {{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}}
>
> Is there any better method?
>
> Thanks a lot.
>





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.