-1
$\begingroup$

I have a table (from this question) as follows:

NestList[{#[[1]] - 2 #[[2]] + 2 #[[3]], 2 #[[1]] - #[[2]] + 2 #[[3]], 
2 #[[1]] - 2 #[[2]] + 3 #[[3]]} &, {3, 4, 5}, 15]// TableForm

I want the same table, but with all instances where the second column is divisible by 8 to be highlighted as Style[numberDivisibleBy8,Bold]. It doesn't work to add an If function to the # expressions. So, how do I do it?

$\endgroup$
  • 1
    $\begingroup$ Please see mathematica.stackexchange.com/questions/194053/… $\endgroup$ – MelaGo May 7 at 23:56
  • $\begingroup$ Hi @MelaGo. I looked again (it was my own question, after all!) , but I really don't see how to transfer that to the current table. I tried, and just ended up with a garbled mess. I realise these are Newbie issues, but I just don't (yet) get it. I'll work on my understanding, but I was hoping for a solution for right now. $\endgroup$ – Richard Burke-Ward May 8 at 0:19
0
$\begingroup$
t = NestList[{#[[1]] - 2 #[[2]] + 2 #[[3]], 
     2 #[[1]] - #[[2]] + 2 #[[3]], 
     2 #[[1]] - 2 #[[2]] + 3 #[[3]]} &, {3, 4, 5}, 15];

t2 = Table[Style[#, {Bold, Plain}[[IntegerQ[row[[2]]/8] /. {True -> 1, False -> 2}]]] & /@row, {row, t}]

or

t2 = Table[Style[#, If[IntegerQ[row[[2]]/8], Bold, Plain]] & /@ row, {row, t}]
TableForm[t2]

enter image description here

$\endgroup$
0
$\begingroup$
 NestList[{#[[1]] - 2 #[[2]] + 2 #[[3]], 2 #[[1]] - #[[2]] + 2 #[[3]], 
          2 #[[1]] - 2 #[[2]] + 3 #[[3]]} &, {3, 4, 5}, 15] // 
    MapAt[If[Divisible[#, 8], Style[#, Red, Bold], #] &, #, {All, 2}] & // TableForm

enter image description here

$\endgroup$
  • $\begingroup$ Both great answers, but I had to go with the one I was closest to understanding. Much appreciated, both of you. $\endgroup$ – Richard Burke-Ward May 8 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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