bigpi
. Each digit is used as an index
into an array called hist
that keeps track of the number of times a given digit occurs in bigpi
.
Another array called digit
is used to seed the horizontal axis of the histogram, as it is loaded
with the numbers from 0 to 9, which are the possible digits in π.
digit[i] =
so digit
will hold the numbers from 0 to 9. Fix the hist[i]=
line
so that all counts start at zero. Lastly, fix the hist[d] =
line so that it is increased by
one inside of the if
statement.
hist={}
digit={}
for i=0,9 do
digit[i] = ???
hist[i] = ???
end
for i=1,string.len(bigpi) do
d = string.sub(bigpi,i,i)
if (d ~= ".") then
d=tonumber(d)
hist[d] = ???
end
end
drawchart(digit,hist,"bar")
digit[i] =
line so that the ith element of array digit
contains
the ith possible digit of π running from 0 to 9?
hist[i]
line to initially set all histogram counts equal to zero?
if
statement, the variable d
contains the current digit of π found
in bigpi
(i.e. a number from 0 to 9), what how will you fix the hist[d] =
line so that hist[d]
is increased by one relative to its currently held count? Hint: It's related to what's in this lesson.