write the algorithm to draw a sphere (Circle) , the function should have paramters
1. diameter (how many line)
2. character (use which character to draw)
eg, draw_sphere(10, '8') will produce:
88888
8888888888888
8888888888888888888
888888888888888888888
88888888888888888888888
88888888888888888888888
888888888888888888888
8888888888888888888
8888888888888
88888
the above is a sphere of 10 lines, which is drawn using the character "8"
could anyone help on this? im newbie in php, thanks in advance…
EDIT: I tried but vBulletin messes with the tabbing from post to render. Hopefully you can guess what it is intended to look like Mittineague
Well, there’s two variables for each line: the whitespace and the 8.
How can you figure out how much whitespace there should be and how many characters to draw?
Start out with what you should know: it should be as wide as it is tall. The width and the height are the same as the diameter. The length of a chord is the product of a function: http://www.mathopenref.com/chord.html and the whitespace is related to the diameter and the chord length.
But you should be able to do this. This is a a problem that high-school sophomores solve.
I’ve been learning php for years… and even now I wouldn’t put myself forward for a php job despite a several people in the field suggesting my understanding of it is better than some of the pro’s.
You can’t just jump in as someone who knows very little and grab a job… can you? - If so where do I sign?
And how often in the real world are we faced with a problem such as drawing a sphere full of the digit “8”?
The original poster was asking this same question on other boards. The one where I found an explanation, if it is correct, is not as easy as some of you seem to think it is.
When I first got interested in computer programming, I talked to one of the programmers at the company I worked for. The most important tool a programmer can have, he said, is documentation. Nobody knows the answer to every problem. But someone with a brain and access to documentation can arrive at an answer (eventually). I’ll bet they don’t test for that.
Well, I spend a big chunk of my time trying to figure out how to programatically generate one thing from another, so I will go with the answer “almost every single day”.