# Changing or "Marking" some elements in a list

I want to "Mark" some elements in a list if they obey certain conditions. I honestly do not know if there is a way to mark elements, so I have decided to create another list where those numbers which obey the criteria will be represented in "1" (And those which do not will be represented in "0").

The condition is Divisable[2*#-1,3]

Here is the code, which is not working for a reason.

a = 12
blist = 2*Range[a/2] - 2
enter code here
ilist = Table[0, Length[blist]]
Map[If[Divisable[2*# - 1, 3],ReplacePart[ilist, Position[blist, #] -> 1]] &, blist]
ilist


The list blist ({0,2,4,6,8,10}) has two elements that meet the criteria, and therefore the final output of ilist should be the following:

{0,1,0,0,1,0}


However, Mathematica outputs the following:

{0,0,0,0,0,0}


If you could tell me what is wrong with my code and how to properly "Mark" certain elements in a list, I'd be very grateful. Any help is appreciated.

• Try Boole[Divisible[2 # - 1, 3]] & /@ blist. Commented Jul 27, 2017 at 10:23
• Thanks, it works well!
– user51325
Commented Jul 27, 2017 at 10:26
• Not as neat as JM's comment, but using your own approach: If[Divisible[2*# - 1, 3], 1, 0] & /@ {0, 2, 4, 6, 8, 10} Commented Jul 27, 2017 at 10:34
• Works just as fine!
– user51325
Commented Jul 27, 2017 at 10:35
• ilist = Boole[Divisible[2 blist - 1, 3]] Commented Jul 27, 2017 at 11:12

 blist = 2*Range[12/2] - 2;

-Mod[2 blist - 1, 3] // UnitStep


{0, 1, 0, 0, 1, 0}

• Thank you very much!
– user51325
Commented Jul 27, 2017 at 10:49
• You're welcome. You could define blist with Range[1, 2 a, 4] - 2 and then just -Mod[blist, 3] // UnitStep
– eldo
Commented Jul 27, 2017 at 11:02
blist = {0, 2, 4, 6, 8, 10};
1 - Unitize @ Mod[2 blist - 1, 3]


{0, 1, 0, 0, 1, 0}