Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: apply rule to Partition
Replies: 6   Last Post: Sep 21, 2013 4:34 AM

 Messages: [ Previous | Next ]
 Bob Hanlon Posts: 906 Registered: 10/29/11
Re: apply rule to Partition
Posted: Sep 21, 2013 4:24 AM

Partition[Range[10], m /. m -> 2]

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

With[{n = 10, m = 2}, Partition[Range[n], m]]

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

Module[{n = 10, m = 2}, Partition[Range[n], m]]

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

Block[{n = 10, m = 2}, Partition[Range[n], m]]

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

Hold[Partition[Range[n], m]] /. {n -> 10, m -> 2} // ReleaseHold

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

Bob Hanlon

On Fri, Sep 20, 2013 at 7:06 AM, Joug Raw <jougraw@gmail.com> wrote:

>
> I want to use rule to simplify my code. A piece of my code use Partition
> and I tried something like:
>
> Partition[Range[10], m] /. m -> 2
>
> It give me error message. My real code is in fact more complicated and this
> way failed to give me an output. How could I make it work?
> Thanks.
>
>
>

Date Subject Author
9/21/13 Tomas Garza Hernandez
9/21/13 Itai Seggev