Skip to content
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

Add Approximate counting in Java #898

Merged
merged 11 commits into from
Dec 2, 2021

Conversation

PaddyKe
Copy link
Contributor

@PaddyKe PaddyKe commented Oct 23, 2021

No description provided.

Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

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

Thanks for your first batch of PRs.
This looks like overall clean code, but I have a few problems with it, the vast majority of which are typos.
It's pretty merge-able right now, so I'll let you correct the problems 😄

Comment on lines 57 to 68
* It terminates the program on failure
*/
static void testApproximateCount(int nTrails, int nItems, double a, double threshold) {
double avg = DoubleStream.generate(() -> approximateCount(nItems, a))
.limit(nTrails)
.average()
.getAsDouble();

if (Math.abs((avg - nItems) / nItems) < threshold) {
System.out.println("passed");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it terminate the program on failure? You don't seem to check anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure. I don't think this function should terminate the program on failure.
As I understand this function, it should only print whether the calculation was successful or not. However, I can add the else part to the if expression to print "failed" if the test has failed.

@Amaras Amaras added hacktoberfest-accepted Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: java Java programming language labels Oct 23, 2021
@henrikac
Copy link
Contributor

henrikac commented Oct 26, 2021

Shouldn't it terminate the program on failure?

This seems to vary from implementation to implementation. Julia's implementation returns true or false, Python's implementation prints passed if condition is true, C++ returns "pass" or "fail" depending on the result of the condition. C's implementation aborts program execution.

Edit: I have created an issue for this - #907

Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

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

Pending #907, this is ready to merge.

I won't update right now until we have that sorted and standardized, so we are not too confused about merging it immediately

@Amaras
Copy link
Member

Amaras commented Nov 3, 2021

We'll merge this when #913 is merged, @PaddyKe you can probably use the blueprint provided by the PR so we can merge it rapidly

Copy link
Contributor

@stormofice stormofice left a comment

Choose a reason for hiding this comment

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

These changes should make the implementation's output comply with the standardized version.

@leios
Copy link
Member

leios commented Dec 2, 2021

#913 is merged and I commited @stormofice 'ssuggestion, so I will merge this

@leios leios merged commit a3276be into algorithm-archivists:main Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: java Java programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants