Re: working with lists
- To: mathgroup at smc.vnet.net
- Subject: [mg113211] Re: working with lists
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 19 Oct 2010 05:54:15 -0400 (EDT)
- Reply-to: hanlonr at cox.net
Your sample output does not appear to agree with your description of the desired operation. The following implements the description.
f[x_?VectorQ] := Module[
{n = 0},
If[Mod[#, 3] == 0,
n = 1; 2 #, # - n] & /@ x]
f[{1, 2, 3, 5, 7}]
{1, 2, 6, 4, 6}
Bob Hanlon
---- Sam Takoy <sam.takoy at yahoo.com> wrote:
=============
Hi,
I'm not very good at working with lists. May I ask for someone to work
out an example which has several elements of what I need to do.
What's the best way to write a function f[list] that goes through each
element of the lest, doubles each element divisible by three and reduces
each of the following elements by 1. That is
f[{ 1 2 3 5 7}] is { 1 2 6 4 12 }
Many thanks in advance,
Sam