[EIWL] list line plot of the first digits of the first 100 squares ?

At

exercise 6.10 is “Make a list line plot of the first digits of the first 100 squares.”

I found a solution

ListLinePlot[Table[First[Part[First[IntegerDigits[{Range[100]^2}]], n]], {n, 100}]]

but surely there has to be a better way. Can someone provide a nicer way of accomplishing the task. I certainly can’t! :frowning:

Maybe a bit shorter:

ListLinePlot[IntegerDigits[Range[100]^2][[;; , -1]]]

Edit: I misread “the last” digit…

For the First digit:

ListLinePlot[IntegerDigits[Range[100]^2][[;; , 1]]]

Thank-you Christian. Definitely better. Or at least it will be if I can figure out what the [[;; , -1]] is all about.

This may also be what you need

ListLinePlot[First /@ IntegerDigits /@ (Range[100]^2)]

Paul.

Hello Peter, the ;; is a short form for “All” but is a very simple way to manipulate array without explicit index. have a look at the Mathematica help about Span it is very clearly explained. BTW in that particular case, Paul’s proposal is even cleaner because there are no reference to table indexes at all.( /@ being the prefix form for “Map”..see also Map help)

Thank-you both Paul and Christian. I shall investigate, and hopefully learn. :slight_smile:

Since IntegerDigits has attribute Listable, there’s no need to Map IntegerDigits onto Range[100]^2. Thus simply;

 ListLinePlot[First /@ IntegerDigits[Range[100]^2]]

This may also be used : ListLinePlot[Table[First[IntegerDigits[n^2]], {n, 100}]]