RE: How to Properly Use Partition?
- To: mathgroup at smc.vnet.net
- Subject: [mg36732] RE: [mg36725] How to Properly Use Partition?
- From: "DrBob" <drbob at bigfoot.com>
- Date: Sat, 21 Sep 2002 02:21:57 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
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.