Skip to content

Added Processing language + BogoSort implementation #436

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 6 commits into from
Closed

Added Processing language + BogoSort implementation #436

wants to merge 6 commits into from

Conversation

johhnry
Copy link

@johhnry johhnry commented Oct 3, 2018

Added a new language, Processing.
Processing is a Java based programming language used for computer graphics, data visualisation, animation...
Checkout https://processing.org/.

Added the Processing version of the Bogo Sort algorithm with sorting visualisation.

@Gathros Gathros added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Hacktoberfest The label for all Hacktoberfest related things! labels Oct 3, 2018
Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

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

Not used to the processing language. I asked a few questions, also the randomize() function seems a bit odd, but maybe I am just misreading it.

book.json Outdated
@@ -139,6 +139,10 @@
{
"lang": "f90",
"name": "Fortran90"
},
{
"lang": "processing",
Copy link
Member

Choose a reason for hiding this comment

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

I think lang should be the file extension, which is pde in this case.

Copy link
Author

Choose a reason for hiding this comment

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

Yes you are right, do I need to change that in the Pull request?

Copy link
Contributor

Choose a reason for hiding this comment

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

@johhnry Yep. Just push your changes to the branch you made this PR from.

random_array(test_array,0,100);
}

void draw(){
Copy link
Member

Choose a reason for hiding this comment

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

Dumb question about processing. Does everything require a visual output?

Copy link
Author

Choose a reason for hiding this comment

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

It's not a requirement but Processing language was created for that kind of task.
I found it nice to visualize the sorting process.

return true;
}

void bogo_Sort(int[] array){
Copy link
Member

Choose a reason for hiding this comment

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

It seems like we are mixing camel case and snake case here. We should probably choose one.

Copy link
Author

Choose a reason for hiding this comment

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

Is it possible to change the code of a pull request?

Copy link
Contributor

@Yordrar Yordrar Oct 4, 2018

Choose a reason for hiding this comment

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

Just commit to the branch you have in your forked repo and the PR automatically updates. Read carefully the contributing tutorial!

@Butt4cak3
Copy link
Contributor

I'm not sure if we need this. The algorithms themselves are almost just plain Java and everything this adds on top is the visualization code which doesn't really help to teach the algorithms.

@c252
Copy link
Member

c252 commented Oct 6, 2018

this is a small thing, but you have merge conflicts in book.json and bogo_sort.md

You can also use frame.setVisible(false); in processing if you decide you don't want to have the drawing window and just print to the console.

@johhnry
Copy link
Author

johhnry commented Oct 7, 2018

@Butt4cak3
If you think it's not relevant to add visualisation to the algorithm, we don't need to merge the pull request.
I just think that it adds something to the algorithm, otherwise I could just implement Bogo sort in Java as Processing is Java-based.

@jiegillet
Copy link
Member

I wrote some visualization before, it was in Elm in the Euler method chapter. We discussed a bunch, and I ended up displaying the parts relevant to the algorithm, then the full code after, along with a link to my GitHub.io with the interactive visualization.
Is something like that doable for you?
My opinion is that visualizations are great to learn.

@leios
Copy link
Member

leios commented Oct 7, 2018

I don't think processing can run in gitbook, though?

@johhnry
Copy link
Author

johhnry commented Oct 7, 2018

@leios
Processing can't run in gitbook but there's p5.js (https://p5js.org/) in JavaScript.

@jiegillet
Copy link
Member

I don't think we should go down the road of adding that to the AAA, but if you have a personal page, you should definitely set it up there and add a link

@Butt4cak3
Copy link
Contributor

Now we're getting back to the old discussion about interactive visualizations in the AAA, which we have turned down in the past (see HOVL).

@johhnry
Copy link
Author

johhnry commented Oct 7, 2018

@Butt4cak3
What was the conclusion?

@johhnry
Copy link
Author

johhnry commented Oct 7, 2018

I just saw that there's an animation in this page : https://www.algorithm-archive.org/contents/monte_carlo_integration/monte_carlo_integration.html

It could be nice to add the same thing for other algorithms (visualization) by using gif.

@Butt4cak3
Copy link
Contributor

@Butt4cak3
What was the conclusion?

Well... We turned it down. No interactive visualization in the AAA.

@johhnry
Copy link
Author

johhnry commented Oct 8, 2018

Sorry if I am asking a lot of questions but why book.json and contents/bogo_sort/bogo_sort.md are they in conflict? How do we resolve that?

Thanks for giving your time

@leios
Copy link
Member

leios commented Oct 8, 2018

Hey @johhnry. We have an elm visualization for the forward euler method; however, that remains the only interactive visualization in the AAA so far. Even then, there was a heated debate as to whether it should be added in. Processing cannot be a dynamic visualization on the algorithm-archive.org (P5.js can, though?).

Is the processing implementation of the algorithm (without the boilerplate visualization) different than Java?

My understanding is that they are literally the same, except that the processing code is dropped into a Java class when the code is compiled. I am conflicted here. On the one hand, it looks like Processing is much easier to read and write than Java; however, if the implementation is literally the same, then no one will really be able to tell the difference in the AAA.

This is a good discussion to have, so even if we decide to turn this PR down, it was really helpful. I would like to hear opinions from both sides.

@jiegillet
Copy link
Member

Another idea is having @johhnry work with @leios on a quality animation, like a gif, and have it displayed in a chapter, like we have in Monte Carlo or Split-Op. We can leave a note at the end saying that the visualization was done in Processing and show the code. I think that would be wonderful and very useful to people.

@leios
Copy link
Member

leios commented Oct 8, 2018

Yeah, I agree with that @jiegillet. The only problem here is that for consistency, if we use one visualization method for Bogo Sort, we should use the same one for all the other sorts (and there are a lot of them). It's fine, so long as @johhnry is willing to help as more sorting chapters get added.

@jiegillet
Copy link
Member

I don't think consistency is a priority, if only one chapter has a visualization, it's better than nothing. If more do, all the better.

@johhnry
Copy link
Author

johhnry commented Oct 9, 2018

It's fine, so long as @johhnry is willing to help as more sorting chapters get added.

I would love to!
I think it will add more interactivity to the algorithm archive gitbook.

@johhnry
Copy link
Author

johhnry commented Oct 9, 2018

Really simple example for Bubble sort algorithm :

tmp_181009-160246

@leios
Copy link
Member

leios commented Oct 9, 2018

So what was the verdict on this PR? Do we close it and create a separate issue to discuss the visualization of sorting algorithms? Or do we keep it up and rework it for a general-case visualization with code available?

@jiegillet
Copy link
Member

@johhnry very nice!
I think you should add more colors to differentiate the pairs being compared and switched.

@leios
Copy link
Member

leios commented Oct 10, 2018

I think it would be understandable enough to highlight the two bars we are comparing. Once we have the visualization done, I'll send you a PR on this PR for you to merge so we can merge.

@johhnry
Copy link
Author

johhnry commented Oct 10, 2018

Here is my second try :

tmp_181010-101858

@jiegillet
Copy link
Member

Looks good! I would work on the timings a bit more. The swap is too slow and the non-swap are too fast :)

@leios
Copy link
Member

leios commented Oct 11, 2018

I like the visualization. If you fix the timings, it will be great!

That said, isn't that visualization for Bubble sort? This is a Bogo Sort PR. I can just change the name to Bubble Sort, though.

@johhnry
Copy link
Author

johhnry commented Oct 11, 2018

Looks good! I would work on the timings a bit more. The swap is too slow and the non-swap are too fast :)

Yes you are totally right

@leios
I also want to make the visualization for Bogo sort so we can rename the PR to "sorting visualization" ?

@johhnry
Copy link
Author

johhnry commented Oct 11, 2018

Bogo Sort visualization (maybe on more elements) :

tmp_181012-005717

Bubble Sort :

tmp_181012-011059

@jiegillet
Copy link
Member

Love it!
I would add a few more elements to the bogoSort array. Should it end on a sorted array and turn green maybe? That would show that the algorithm can finish, but I admit that an endless loops of shuffling is way funnier (but in this case, you have to make the first and last frame identical so that it's a smooth loop)

Bubble sort is good but it stops before the array is sorted, that's frustrating, maybe you can remove one or 2 elements. Also most AAA algorithm don't have the optimization of not going through the whole array when then end is already sorted, so maybe you shouldn't either. I'm not sure...

@leios
Copy link
Member

leios commented Oct 12, 2018

Agreed, these are good. It would be nice if both of them finished on sorted arrays and waited for a second or something.

@johhnry johhnry closed this Oct 14, 2018
@johhnry johhnry reopened this Oct 14, 2018
@johhnry
Copy link
Author

johhnry commented Oct 17, 2018

Bogo Sort :
animation_1

@leios
Copy link
Member

leios commented Oct 21, 2018

Alright, I am happy with this visualization. Let me send a PR to your PR about this.

@johhnry
Copy link
Author

johhnry commented Nov 29, 2018

What's up guys ?
@leios Did you send me a PR?

@leios
Copy link
Member

leios commented Dec 15, 2018

I have not. I've just been swamped lately.

@leios
Copy link
Member

leios commented Dec 24, 2018

@leios
Copy link
Member

leios commented Jan 10, 2019

Hey @johhnry thanks a lot! Do you have a video of this animation as well? We have recently changed things to videos, if possible. If you don't have a video, no problem!

@johhnry
Copy link
Author

johhnry commented Jan 10, 2019

Sure, how do I send it ? on Github?

@Amaras
Copy link
Member

Amaras commented Aug 22, 2021

Since the repository has been deleted, I don't think it's merge-able any more, sadly.
Also, we don't have sorting chapters any more, so this is now a dead PR.
I'm closing it, though it's a shame it has not been given the attention it deserved.

@Amaras Amaras closed this Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest The label for all Hacktoberfest related things! 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.

9 participants