-
-
Notifications
You must be signed in to change notification settings - Fork 360
Bubble sort lua #412
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
Bubble sort lua #412
Conversation
Stole numbers from C code /:
Pretty sure I got it right, should probably run the book to check
Forgot lua could do this derp.
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.
Nice, I addressed a few minor things
contents/bubble_sort/bubble_sort.md
Outdated
@@ -22,6 +22,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with | |||
[import:4-9, lang:"python"](code/python/bubblesort.py) | |||
{% sample lang="m" %} | |||
[import:1-13, lang:"matlab"](code/matlab/bubblesort.m) | |||
{% sample lang="lua" %} | |||
[import:1-19, lang="lua"](code/lua/bubble_sort.lua) |
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.
Here import only the function, and later import the whole file
@@ -0,0 +1,17 @@ | |||
|
|||
function bubble_sort(arr) | |||
for i = 1,#arr do |
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.
This only need to be 1,#arr-1
since for n elements you only need to do n-1 passes.
|
||
bubble_sort(arr) | ||
|
||
print(("Sorted array: {%s}"):format(table.concat(arr,", "))) |
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.
I think you need a newline after the last line
@@ -0,0 +1,17 @@ | |||
|
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.
don't open with an empty line
Fixed bubble_sort.md and small changes to code
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 looks fine now, but when I run your code here the array doesn't get sorted. I don't know why.
contents/bubble_sort/bubble_sort.md
Outdated
@@ -77,6 +79,8 @@ Trust me, there are plenty of more complicated algorithms that do precisely the | |||
[import, lang:"python"](code/python/bubblesort.py) | |||
{% sample lang="m" %} | |||
[import, lang:"matlab"](code/matlab/bubblesort.m) | |||
{% sample lang="lua" %} | |||
[import:1-17, lang="lua"](code/lua/bubble_sort.lua) |
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.
You can simply write [import, lang=...]
is you want to import the whole file.
Not necessary when importing entire file
Probably should have tested before pushing
Issue was with swap code in the wrong order, checked it and it ran fine this time |
"Probably should have tested before pushing" hahaha, yup :) |
* Added Bubble Sort in Lua * Added test case Stole numbers from C code /: * Moved files cus derp * Added Lua entry to md file Pretty sure I got it right, should probably run the book to check * Use tuple style swap Forgot lua could do this derp. * Addressing problems Fixed bubble_sort.md and small changes to code * Removed unnecessary line specification Not necessary when importing entire file * Swap code broken Probably should have tested before pushing
Lua is pretty empty so I will probably start filling it up for hacktoberfest