MathGroup Archive 2002

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

Search the Archive

RE: How to Properly Use Partition?


Maybe this will work for you:

groupDigits[n_String, k_Integer] := Partition[
    PadLeft[Characters[n],
      k Ceiling[StringLength[n]/k],
      "0"],
    k]

Bobby Treat

-----Original Message-----
From: flip [mailto:flip_alpha at safebunch.com] 
To: mathgroup at smc.vnet.net
Subject: [mg36732] [mg36725] How to Properly Use Partition?

b = 2; r = 4;
n = "10101111"
p = Reverse[Characters[n]]
{"1", "1", "1", "1", "0", "1", "0", "1"}
z = Reverse[Partition[p, r]]
{{"0", "1", "0", "1"}, {"1", "1", "1", "1"}}  (* this is okay *)
b = 2; r = 3;
z = Reverse[Partition[p, r]]
{{"1", "0", "1"}, {"1", "1", "1"}}  (* this is wrong, want output to be
{{0,1,0},{1,0,1},{1,1,1}}*)

What I want is a function that takes a string as input, parses each
character, partitions that to whatever length I want and Prepends zeros
to
the input as needed to create an appropriate length array.

What is the correct syntax for Partition (or is there a better way?).

Thanks, Flip

Remove _alpha to email.







  • Prev by Date: Re: DAEs with Mathematica
  • Next by Date: How to Properly Use Partition?
  • Previous by thread: Re: How to Properly Use Partition?
  • Next by thread: How to Properly Use Partition?