w-alanna / Darts

Monte Carlo darts simulation
0 stars 0 forks source link

Steps for darts program? #3

Open bpbond opened 1 year ago

bpbond commented 1 year ago

@w-alanna @melatg0 This is an "issue" -- we can use it to discuss our plans for the darts program, assign tasks, and document problems.

Question for you both. Thinking back to the darts/pi walkthrough we did on the whiteboard...what are the high-level steps for our program?

For example, I think step number 1 will probably be to define constants.

@w-alanna already did one line of this:

# Number of darts to throw; the more we throw, the more accurate our estimate
darts <- 1000

What are the next steps for our darts-simulating program?

bpbond commented 1 year ago

image

w-alanna commented 1 year ago

I think the next steps are making a matrix with 3 columns: x-coord, y-coord, and bounds, and 1000 rows. We then randomly assign each x-coord and y-coord a value between 0 and 1. Then we calculate the distance from the center (0.5, 0.5) to see if the distance is equal or less than 0.5. If greater, then bounds is false, else it is equal. We then count the number of columns that have true and make the ratio and use the ratio to solve for pi.

melatg0 commented 1 year ago

I also have a similar idea as Alanna.

  1. Create n x n matrix where n is a odd integer
  2. Use randomizer function to randomly select elements in the matrix (all elements are set to 0 prior) and set them to 1 if they are 'hit' by the dart.
  3. Repeat above X number of times
  4. Count number of elements n/2 units away from center (calculate using distance formula; iterating through all elements = 1 to see if they are within bound)
  5. Estimate pi using the method Ben had discussed earlier.
bpbond commented 1 year ago

OK, agreed, thank you both!

Let's set some goals and assignments - this is about practicing R programming but also Git/GitHub.

  1. 4

  2. 5

  3. 6

bpbond commented 1 year ago

☝️ Go to one of the issues and claim it by assigning yourself:

Screenshot 2023-11-08 at 2 19 53 PM

Then (i) create a new branch, (ii) code and test your solution, and (iii) open a pull request!