Skip to content

added monte carlo method c# #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

sanstorik
Copy link

Simple monte carlo method implementation in c#

@june128 june128 self-assigned this Jul 9, 2018
@june128 june128 added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jul 9, 2018
}


private static double MonteCarloMethod(int samples)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to a separate file called MonteCarlo with the class MonteCarlo and rename the method into Run(), since that's the way all other C# implementations work (look here for reference https://www.algorithm-archive.org/chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.html).

@june128
Copy link
Member

june128 commented Jul 9, 2018

Two other things:

  • You can add yourself to the CONTRIBUTORS.md as a "reward" for your work and you can also put a comment at the top of the files mentioning that you wrote this code (example: Jarvis March C# (first line))
  • You need to import the code in the .md file. At the bottom of this page you can see how it's done and the Monte Carlo .md also has already a few imports in it for reference.

var randomY = random.NextDouble() * radius;

if (IsInCircle(randomX, randomY))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is just a single line, you don't need the curly braces. I would remove them, what do you think?



private static bool IsInCircle(double x, double y)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can use => sine you just have a single line in the method. So the method would roughly look like this

private static bool IsInCircle(double x, double y) => x * x + y * y < radius * radius;

It's also just a suggestion and I would like to hear your input.

@june128
Copy link
Member

june128 commented Jul 9, 2018

Ok, I reviewed and commented quite a few things now. But I also want to welcome you to the AAA community! If you have any questions, suggestion or concerns feel free to publish them here or on our Discord (depending on situation): https://discord.gg/pb976sY

@june128
Copy link
Member

june128 commented Jul 9, 2018

Ohh and another final request: Please change the name of the directory you put the code in from C# to csharp.

@sanstorik
Copy link
Author

Hi. Thanks for the review. I have moved code to MonteCarlo.cs, changed dir name to csharp, updated .md files and used method expression.

@@ -0,0 +1,18 @@
using System;

// submitted by vitalii shvetsov (@sanstorik)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this at the very top?

@@ -123,6 +126,8 @@ Feel free to submit your version via pull request, and thanks for reading!
{% sample lang="swift" %}
### Swift
[import, lang:"swift"](code/swift/monte_carlo.swift)
### CSharp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to put {% sample lang="csharp" %} above this line, so that we see the code when selecting C#.

@@ -59,8 +59,11 @@ each point is tested to see whether it's in the circle or not:
[import:13-15, lang:"java"](code/java/MonteCarlo.java)
{% sample lang="swift" %}
[import:21-25, lang:"swift"](code/swift/monte_carlo.swift)
{% sample lang="csharp" %}
[import:37-39, lang:"csharp"](code/csharp/MonteCarlo.cs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code import should only be line 38, since you made the method smaller.

@june128
Copy link
Member

june128 commented Jul 10, 2018

Thanks for correcting these little issues. I found 3 more things, I would like to have changed, but then the PR should be ready to merge.

@june128
Copy link
Member

june128 commented Jul 17, 2018

@sanstorik How is the situation?

@june128
Copy link
Member

june128 commented Jul 28, 2018

@sanstorik I'll close this PR now and do the C# Monte Carlo implementation myself. If you're coming back, before I open my PR, feel free to tag me here and reopen this PR.

@june128 june128 closed this Jul 28, 2018
@june128 june128 mentioned this pull request Jul 28, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants