Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a18e7cc
Adding flood fill in Coconut
Amaras Aug 5, 2020
7d2739b
Correcting copy-paste fails
Amaras Aug 5, 2020
5da3ae8
Flood Fill in C (#741)
Gathros Aug 6, 2020
d21dacd
Huffman Encoding Scratch Implementation (#682)
dovisutu Sep 10, 2020
aa08db0
Update monte_carlo.py (#751)
DougBR Sep 10, 2020
a4dbc2a
Fixed infinite loop issue in "euclidean_example.py" (#749)
valdaarhun Sep 11, 2020
9dcc06f
fix both error of issue 739 (#756)
Oct 12, 2020
627aed9
Add Flood Fill in Python (#753)
lazyprop Oct 12, 2020
fee7e83
Remove color function from flood fill because it is redundant (#766)
leios Oct 15, 2020
85f8e9a
Added Bogosort in Coconut (#735)
Amaras Oct 15, 2020
18944ea
Added Bubblesort in Coconut (#736)
Amaras Oct 15, 2020
f1aa057
Add Scheme alongside Racket in EditorConfig (#779)
berquist Nov 4, 2020
7bc0e22
Added CSS for printing (#777)
0xJonas Nov 5, 2020
91d5625
Added Cooley-Tukey in Lisp
0xJonas Nov 11, 2020
5a6ebd0
Make Euclid's algorithm in Nim more idiomatic (#784)
berquist Nov 11, 2020
153317d
Make Verlet integration in Nim more idiomatic (#782)
berquist Nov 11, 2020
0ca5ac6
Make Bogosort in Nim more idiomatic (#783)
berquist Nov 11, 2020
7ada7da
Formatting and refactoring
0xJonas Dec 27, 2020
c72caaf
Update contents/cooley_tukey/code/clisp/fft.lisp
0xJonas Dec 28, 2020
70822e9
Update contents/cooley_tukey/code/clisp/fft.lisp
0xJonas Dec 28, 2020
9d0a5bb
Update contents/cooley_tukey/code/clisp/fft.lisp
0xJonas Dec 28, 2020
2793edf
Update contents/cooley_tukey/code/clisp/fft.lisp
0xJonas Dec 28, 2020
8426216
Update contents/cooley_tukey/code/clisp/fft.lisp
0xJonas Dec 28, 2020
e92bcb7
Update contents/cooley_tukey/code/clisp/fft.lisp
0xJonas Dec 28, 2020
e631b57
Updated line number
0xJonas Dec 28, 2020
02dd353
Merge pull request #786 from 0xJonas/cooley-tukey-lisp
Trashtalk217 Jan 1, 2021
f9a6eda
Add Computus in Nim (#780)
berquist Jan 2, 2021
b49f034
Domain Coloring in Python using Matplotlib (#788)
0xJonas Jan 4, 2021
9d7349a
adding gif to show people how to change languages (#797)
leios Jan 25, 2021
5be74ec
Adding flood fill in Coconut
Amaras Aug 5, 2020
1949a10
Correcting copy-paste fails
Amaras Aug 5, 2020
a5c0f6b
Addressed part of Trashtalk's review
Amaras Feb 4, 2021
db00314
Merge remote-tracking branch 'origin/flood_fill_coconut' into flood_f…
Amaras Feb 4, 2021
f312994
Got closer to Julia's code logic + reworked the line numbers
Amaras Feb 4, 2021
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
Prev Previous commit
Next Next commit
Addressed part of Trashtalk's review
  • Loading branch information
Amaras committed Feb 4, 2021
commit a5c0f6b264bd92f571ccb7a8dccaca81e05f1987
29 changes: 15 additions & 14 deletions contents/flood_fill/code/coconut/flood_fill.coco
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,53 @@ def colour(canvas, location is Point, old_value, new_value):


def find_neighbours(canvas, location is Point, old_value, new_value):
possible_neighbours = (Point(0, 1), Point(1, 0), Point(0, -1), Point(-1, 0)) |> map$(location.__add__)
possible_neighbours = ((Point(0, 1), Point(1, 0), Point(0, -1), Point(-1, 0))
|> map$(location.__add__))

for neighbour in possible_neighbours:
if inbounds(canvas.shape, neighbour) and canvas[neighbour] == old_value:
yield neighbour
yield from possible_neighbours |> filter$(x -> (inbounds(canvas.shape, x) and canvas[x] == old_value))


def stack_fill(canvas, location is Point, old_value, new_value):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll agree with you that it's better to do stack work with imperative code. Don't try to squeeze functional code into this.

if new_value == old_value:
if new_value == old_value or not inbounds(canvas.shape, location):
return

stack = [location]

while stack:
current_location = stack.pop()
colour(canvas, current_location, old_value, new_value)
canvas[current_location] = new_value
for neighbour in find_neighbours(canvas, current_location, old_value,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use stack.extend to add all new neighbours at once

Copy link
Member Author

Choose a reason for hiding this comment

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

For this one, I think it's a good idea

new_value):
stack.append(neighbour)


def queue_fill(canvas, location is Point, old_value, new_value):
if new_value == old_value:
if new_value == old_value or not inbounds(canvas.shape, location):
return

queue = deque()
queue.append(location)

colour(canvas, location, old_value, new_value)
canvas[location] = new_value

while queue:
current_location = queue.popleft()
for neighbour in find_neighbours(canvas, current_location, old_value,
Copy link
Contributor

Choose a reason for hiding this comment

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

same thing as above, you could do map for colour and queue.extend to add.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure I see how to do that right away. I probably need to work on it a bit more, but that seems out of my capabilities for now.

new_value):
queue.append(neighbour)
colour(canvas, neighbour, old_value, new_value)
canvas[neighbour] = new_value


def recursive_fill(canvas, location is Point, old_value, new_value):
if new_value == old_value:
if new_value == old_value or not inbounds(canvas.shape, location):
return
colour(canvas, location, old_value, new_value)

for neighbour in find_neighbours(canvas, location, old_value, new_value):
recursive_fill(canvas, neighbour, old_value, new_value)

canvas[location] = new_value
# consume is important here, because otherwise, the recursive function is not called again
consume(
find_neighbours(canvas, location, old_value, new_value)
|> map$(recursive_fill$(canvas, ?, old_value, new_value))
)

if __name__ == '__main__':
# Testing setup
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe try to make the tests similair to the Julia tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean "similar to the Julia tests"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Disregard the thing I said. I meant to say that you should probably use the same test as in the Julia implementation, namely:

grid = zeros(5,5) grid[3,:] .= 1 

But I just realize that you are already doing so. It's just that Julia indexes it's arrays starting at 1. Got confused there.

Expand Down