Re: Need pure function to opeate on integer lists
- To: mathgroup at smc.vnet.net
- Subject: [mg68121] Re: Need pure function to opeate on integer lists
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 24 Jul 2006 05:52:28 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <ea1nf3$pja$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Terry wrote: > Suppose I have a list of integers, such as > > listA = {1,2,5,6,7,12,13,15,16,17,18,22,23,24} > > how do I construct a pure function that will difference successive > integer elements to produce > > {1-24,2-1,5-2,6-5,7-6,12-7,13-12,15-13,16-15,17-16,18-17,22-18,23-22,24-23} I have used Bob Hanlon's method described in http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/027e49fcbf045552/9dd947b480658fba?lnk=arm&hl=en#9dd947b480658fba MapThread[HoldForm[#1 + #2] & , {listA, -RotateRight[listA]}] returns {1 - 24, 2 - 1, 5 - 2, 6 - 5, 7 - 6, 12 - 7, 13 - 12, 15 - 13, 16 - 15, 17 - 16, 18 - 17, 22 - 18, 23 - 22, 24 - 23} as required. HTH, Jean-Marc