-
-
Notifications
You must be signed in to change notification settings - Fork 360
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bcd6a56
Added Processing language + BogoSort
52e4c29
change
3cee797
changed lang to pde in book.json
782cbc1
adding processing visualization and small merges.
leios 7bfb564
Merge pull request #2 from leios/johhnry_updates
johhnry 301f188
Merge branch 'master' into bogo_sort_processing
leios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
int[] test_array = new int[5]; | ||
|
||
void setup() { | ||
size(400,400); | ||
stroke(255); | ||
fill(0); | ||
|
||
randomArray(test_array,0,100); | ||
} | ||
|
||
void draw(){ | ||
background(255); | ||
|
||
int w = width/test_array.length , minimum = min(test_array) , maximum = max(test_array); | ||
for(int i=0;i<test_array.length;i++){ | ||
rect(w*i,height,w,-map(test_array[i],minimum,maximum,5,height-5)); | ||
} | ||
|
||
if (isSorted(test_array)){ | ||
noLoop(); | ||
println("Finished in "+ millis()/1000 +" seconds."); | ||
}else{ | ||
randomize(test_array); | ||
} | ||
} | ||
|
||
|
||
void randomArray(int[] array , int min , int max){ | ||
for(int i=0;i<array.length;i++){ | ||
array[i] = (int) random(min,max); | ||
} | ||
} | ||
|
||
void swap(int[] array, int i, int j) { | ||
int temp = array[i]; | ||
array[i] = array[j]; | ||
array[j] = temp; | ||
} | ||
|
||
|
||
void randomize(int[] array) { | ||
johhnry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (int i = array.length-1; i>=1 ; i--) { | ||
int j = (int) random(0, i); | ||
swap(array,i,j); | ||
} | ||
} | ||
|
||
Boolean isSorted(int[] array){ | ||
for(int i=0;i<array.length-1;i++){ | ||
if (array[i]>array[i+1]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
void bogoSort(int[] array){ | ||
while (! isSorted(array)){ | ||
randomize(array); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.