2
$\begingroup$
MemberQ[IntegerDigits [#], 3] & /@ Range[100]

Grid[ArrayReshape[Range[100], {10, 10}], Frame -> All]

I want to get a 10 by 10 grid, that highlights all the numbers that have the digit 3. I have done the basic two lines, I am just wondering how to put them togher so that I get something like this

enter image description here

$\endgroup$
6
$\begingroup$
Grid[Partition[Item[#, Background -> If[FreeQ[IntegerDigits@#, 3], White, Yellow]] & /@ 
  Range @ 100, 10], ItemSize -> 2, Dividers -> All]

enter image description here

$\endgroup$
3
$\begingroup$

Here's one way to do it, something more efficient probably exists though:

bgs = Rule @@@ 
   Transpose[{Tuples[Range[10], 2], 
     If[MemberQ[IntegerDigits[#], 3], Yellow, White] & /@ Range[100]}];
Grid[ArrayReshape[Range[100], {10, 10}], Frame -> All, 
 Background -> {None, None, bgs}]

grid with "3"s hilighted

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.