Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local circle = [[
- 0000000
- 00000000000000000
- 000000000000000000000
- 0000000000000000000000000
- 000000000000000000000000000
- 000000000000000000000000000
- 00000000000000000000000000000
- 00000000000000000000000000000
- 00000000000000000000000000000
- 000000000000000000000000000
- 000000000000000000000000000
- 0000000000000000000000000
- 000000000000000000000
- 00000000000000000
- 0000000
- ]]
- local diameter, circumfrence = 0, 0
- local circletbl = {}
- local x, y = 1, 1
- for char in string.gmatch(circle, ".") do
- if not circletbl[x] then circletbl[x] = {} end
- if char == "\n" then
- x = 1
- y = y + 2 -- Because each '0' is 2 units tall
- else
- circletbl[x][y] = (char == "0")
- circletbl[x][y+1] = (char == "0") -- Because each '0' is 2 units tall
- x = x + 1
- end
- end
- local x = #circletbl[1] / 2
- for y = 1, #circletbl do
- if circletbl[x][y] then
- diameter = diameter + 1
- end
- end
- print("Diameter of the circle is "..diameter)
- for x, tbl in pairs(circletbl) do
- for y, val in pairs(tbl) do
- if val then
- if circletbl[x][y+1] == false or circletbl[x][y-1] == false or circletbl[x+1][y] == false or circletbl[x-1][y] == false then
- circumfrence = circumfrence + 1
- end
- end
- end
- end
- print("Circumfrence of the circle is "..circumfrence)
- print("Pi is about equal to ".. circumfrence / diameter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement