Skip to content

Bubble Sort Scratch Implementation #610

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

Merged
merged 9 commits into from
Jul 17, 2019

Conversation

dovisutu
Copy link
Contributor

@dovisutu dovisutu commented Jun 12, 2019

In the building, I met a strange problem:
It can't pass. It said

Template render error: (C:\Users\w\Downloads\algorithm-archive\contents\bubble_sort\bubble_sort.md) [Line 1605, Column 35]
parseSignature: expected comma after expression

what? Line 1605?
Also, I tried to paste the code of tree traversal here(with ../tree_traversal), but still fail.

@jiegillet
Copy link
Member

Bubble sort usually sorts from smallest to largest, you should invert your logic.

In the error you showed there is a space in the path contents\bubble_s ort\bubble_sort.md is that a copy/paste error or did you include a space in the folder name?

@dovisutu
Copy link
Contributor Author

That's an error when copying, because I directly copied from the console. No space in the folder.

@dovisutu
Copy link
Contributor Author

Ok, I'll invert the logic(ascending)

@dovisutu dovisutu changed the title Bubble Sort Scratch Implementation[WIP] Bubble Sort Scratch Implementation Jun 13, 2019
@leios
Copy link
Member

leios commented Jun 13, 2019

The scratch implementation that has been submitted is a png image that seems to have been saved as an svg. I don't mind png images in the algorithm archive, so feel free to use a png instead of svg. Could you also increase the quality of the image used?

@dovisutu
Copy link
Contributor Author

wait, I just find the way to generate in scratch 2...crap.

@dovisutu dovisutu force-pushed the bubble_sort_in_scratch branch from f4f4ed7 to 9532eb8 Compare June 13, 2019 10:48
@dovisutu
Copy link
Contributor Author

dovisutu commented Jun 13, 2019

OK, although I put a .svg generated from the tool @jiegillet used
EDIT: the .svg looks good on site, but when I download it down it becomes black... Strange...
using .png now.
by the way, if anybody's interesting, here's the text I used to generate the graph at here

define BubbleSort
set [it1 v] to (1)
set [it2 v] to (1)
repeat (length of [List v])
repeat ((length of [List v]) - (1))
If <(item ((it2)+(1)) of [List v]) <(item (it2) of [List v])> then
set [tmp v] to (item (it2) of [List v])
replace item (it2) of [List v] with (item ((it2)+(1)) of [List v]
replace item ((it2)+(1)) of [List v] with (tmp)
end
change [it2 v] by (1)
end
set [it2 v] to (1)
change [it1 v] by (1)
end

@dovisutu dovisutu force-pushed the bubble_sort_in_scratch branch 2 times, most recently from afa84b5 to 3bb1aad Compare June 13, 2019 13:52
@dovisutu dovisutu force-pushed the bubble_sort_in_scratch branch from 3bb1aad to f8aaa63 Compare June 13, 2019 14:03
@leios
Copy link
Member

leios commented Jun 13, 2019

All the scratch right now is in scratch2, but it is possible to output scratch3 with this: https://s3blocks.github.io/generator/ (use the export svg button). I would guess scratch3 would be better for this. You can get to this site by clicking the "scratchblocks" link in the upper left of the link you posted.

Would you also be able to commit the scratchblocks code used to generate this so we can generate it again in the future if there is a change to scratch (scratch4).

@jiegillet Is it possible to find the scratchblocks code you used for the scratch2 implementations?

@jiegillet
Copy link
Member

Do you mean the code in text form? I'm afraid I dropped the ball and lost it, I should know better than to get rid of source code :(

@leios
Copy link
Member

leios commented Jun 14, 2019

It's equally my fault for not asking for it at the time. I suppose we should use scratch3 for this one?

@jiegillet
Copy link
Member

I think I deleted it even before sending the PR, nothing you could have done. I now think the code in text form should also be committed along with the svg (but should not be included in the .md file).

Yes, we should use Scratch 3 from now on! Maybe I'll update my Scratch svgs in the future!

@dovisutu
Copy link
Contributor Author

well, how to include the scratchblock? just .txt?

@leios
Copy link
Member

leios commented Jun 14, 2019

Yeah, please add a text document next to the svg image

@dovisutu
Copy link
Contributor Author

dovisutu commented Jun 14, 2019

Crap. I tried to generate in scratch 3, the picture does show on site, but when I click "Export SVG", nothing happened. "Export PNG" makes a file that I can't open. When I directly save the picture, it becomes all black.
But it works when I save as PNG. Phew.
If anyone want the better .svg file, sorry, but I just can't make it here.

@leios
Copy link
Member

leios commented Jun 14, 2019

I put a PR to your branch with the svg. It worked fine on my end.

@dovisutu
Copy link
Contributor Author

dovisutu commented Jun 14, 2019

@leios sorry, but I found that I accidently added one more define BubbleSort line, and you're using that. Crap.
The scratchblock is right on my comment above now, since I edited it.
AKA this

define BubbleSort
set [it1 v] to (1)
set [it2 v] to (1)
repeat (length of [List v])
repeat ((length of [List v]) - (1))
If <(item ((it2)+(1)) of [List v]) <(item (it2) of [List v])> then
set [tmp v] to (item (it2) of [List v])
replace item (it2) of [List v] with (item ((it2)+(1)) of [List v]
replace item ((it2)+(1)) of [List v] with (tmp)
end
change [it2 v] by (1)
end
set [it2 v] to (1)
change [it1 v] by (1)
end

@leios
Copy link
Member

leios commented Jun 14, 2019

I am not really sure why the svg option is not working for you

@dovisutu dovisutu force-pushed the bubble_sort_in_scratch branch from 09aba21 to 39a04e5 Compare June 15, 2019 07:05
@dovisutu
Copy link
Contributor Author

Phew. By some strange way, I finally get the correct svg picture.

@c252
Copy link
Member

c252 commented Jun 15, 2019

This isn't totally necessary, but it could be nice to change the variable names to match the other implementations it -> i it2 -> j list -> a

@c252 c252 added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jun 15, 2019
 - Indent
 - add Scratch textCode into .editorconfig
@dovisutu
Copy link
Contributor Author

This isn't totally necessary, but it could be nice to change the variable names to match the other implementations it -> i it2 -> j list -> a

Thanks, but as mentioned before, I can't generate .svg here (may be caused by Edge), so I can't make change.
Although you can generate it and add it to here via PR.

@dovisutu
Copy link
Contributor Author

hmm... I think I know how to make correct svg here.
Previously it was black, because this is missing:

<style><![CDATA[ .sb-label {
      font-family: "Helvetica Neue", Helvetica, sans-serif;
      font-weight: normal;
      fill: #fff;
      font-size: 11px;
      word-spacing: 0px;
      opacity: 1;
    }

    .sb-obsolete { fill: #ED4242; }
    .sb-motion { fill: #4C97FF; }
    .sb-looks { fill: #9966FF; }
    .sb-sound { fill: #CF63CF; }
    .sb-pen { fill: #0fBD8C;  }
    .sb-events { fill: #FFBF00; }
    .sb-control { fill: #FFAB19; }
    .sb-sensing { fill: #5CB1D6; }
    .sb-operators { fill: #59C059; }
    .sb-variables { fill: #FF8C1A; }
    .sb-list { fill: #FF661A }
    .sb-custom { fill: #FF6680; }
    .sb-custom-arg { fill: #FF6680; }
    .sb-oldextension { fill: #4b4a60; }
    .sb-extension { fill: #0fbd8c; }
    .sb-grey { fill: #969696; }
    .sb-bevel {
      filter2: url(#bevelFilter);
      stroke: #000;
      stroke-opacity: 0.15;
      stroke-alignment: inner;
    }
    .sb-input-round-dropdown,
    .sb-input-boolean {
      filter: url(#inputDarkFilter);
    }
    .sb-input {
      filter2: url(#inputBevelFilter);
      stroke: #000;
      stroke-opacity: 0.15;
      stroke-alignment: inner;
    }
    .sb-input-number,
    .sb-input-string,
    .sb-input-number-dropdown {
      fill: #fff;
    }
    .sb-literal-number,
    .sb-literal-string,
    .sb-literal-number-dropdown,
    .sb-literal-dropdown {
      font-weight: normal;
      font-size: 11px;
      word-spacing: 0;
    }
    .sb-literal-number,
    .sb-literal-string,
    .sb-literal-number-dropdown {
      fill: #444;
    }

    .sb-darker {
      filter2: url(#inputDarkFilter);
      stroke: #000;
      stroke-opacity: 0.1;
      stroke-alignment: inner;
    }
    .sb-desaturate {
      filter: url(#desaturateFilter);
    }
    .sb-outline {
      stroke: #000;
      stroke-opacity: 0.1;
      stroke-width: 1;
      fill: #FF4D6A;
    }

    .sb-define-hat-cap {
      stroke: #632d99;
      stroke-width: 1;
      fill: #8e2ec2;
    }

    .sb-comment {
      fill: #E4DB8C;
      stroke: #000;
      stroke-opacity: 0.2;
      stroke-width: 1;
    }
    .sb-comment-line {
      fill: #000;
      opacity: 0.2;
    }
    .sb-comment-label {
      font-family: "Helvetica Neue", Helvetica, sans-serif;
      font-weight: normal;
      fill: #000;
      font-size: 11px;
      word-spacing: 0px;
      opacity: 1;
    }

    .sb-diff {
      fill: none;
      stroke: #000;
    }
    .sb-diff-ins {
      stroke-width: 2px;
    }
    .sb-diff-del {
      stroke-width: 3px;
    }
  ]]></style>

so if I add it in the end of <def> label, the image looks fine.
I think I finally can do the change requested by @c252 .

@leios
Copy link
Member

leios commented Jul 17, 2019

I am relatively happy with the code and am almost ready to merge it. The only problem I have is that the BubbleSort function cannot take the list a as an input variable. This is a limitation with scratch, right?

If so, there is nothing we can do and I'm willing to merge now.

@dovisutu
Copy link
Contributor Author

Yeah, we can't take lists as a variable.

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.

This is as close as we can come to the other implementations in scratch, so I approve.

@leios leios merged commit 40cf050 into algorithm-archivists:master Jul 17, 2019
@dovisutu dovisutu deleted the bubble_sort_in_scratch branch July 17, 2019 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants