Skip to content

Added brainfuck code and explanation for Euclidean Algorithm #463

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Ariana1729
Copy link
Contributor

Just so that multiple algos and langs dont get merged, there's another PR

@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 6, 2018
@Ariana1729
Copy link
Contributor Author

ok umm not quite sure how to fix the conflicts tbh ill try again maybe like tmr?

@leios
Copy link
Member

leios commented Oct 6, 2018

I'll fix the conflicts once the code is reviewed. These are easy ones to fix on my end. I am still trying to wrap my head around BF, though. I want to do these reviews soon!

@leios
Copy link
Member

leios commented Oct 11, 2018

I think @Trashtalk217 did a decent BF review last time. Can he also do this review?

Copy link
Contributor

@Trashtalk217 Trashtalk217 left a comment

Choose a reason for hiding this comment

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

Since this review is going to take a while, I'm not done, I just wanted to give you something so there is no complete radio silence.

book.json Outdated
},
{
"lang": "bf",
"name": "brainfuck"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we already have brainfuck in book.jason, put that can easily be fixed by resolving the conflict later.

book.json Outdated
},
{
"lang": "bf",
"name": "Brainfuck"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we already have brainfuck in book.jason, but a conflict like this can easily be resolved.

book.json Outdated
},
{
"lang": "bf",
"name": "Brainfuck"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we already have brainfuck in book.jason, but a conflict like this can easily be resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore this, Its double

@@ -0,0 +1,2 @@
,>,>>>+[[-]<<<<[->>>+<<<]>[->>>+<<<]>>[-<+<<+>>>]>[-<+<<+>>>]<<[->->[-]+<[>-]>[->>]<<<]>[>]<[<<[-]>>[-<<+>>>+<]]<[<<[-]>>[-<<+>>>>+<<]]>>>[-]+>[-]<<[>-]>[<<<<.>>>>->>]<<]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd first like to note it's really hard commenting on a onliner but I'll do my best: the second [-] is unnecessary, I've never seen it called.

@@ -0,0 +1,2 @@
,>,>>>+[[-]<<<<[->>>+<<<]>[->>>+<<<]>>[-<+<<+>>>]>[-<+<<+>>>]<<[->->[-]+<[>-]>[->>]<<<]>[>]<[<<[-]>>[-<<+>>>+<]]<[<<[-]>>[-<<+>>>>+<<]]>>>[-]+>[-]<<[>-]>[<<<<.>>>>->>]<<]
Copy link
Contributor

@Trashtalk217 Trashtalk217 Oct 30, 2018

Choose a reason for hiding this comment

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

I'm just going to leave a nice indented version down below, so I can accuratly point some things out.

,>,

>>>+

[
	[-]
	<<<<
	[->>>+<<<]
	>
	[->>>+<<<]
	>>
	[-<+<<+>>>]
	>
	[-<+<<+>>>]
	<<
	[
		->->
		**[-]**
		+<
		[>-]
		>
		[->>]
		<<<
	]
	>
	[>]
	<
	[
		<<
		[-]
		>>
		[-<<+>>>+<]
	]
	<
	[
		<<
		[-]
		>>
		[-<<+>>>>+<<]
	]
	>>>
	**[-]**
	+
        **>[-]<**
        <
	[>-]
	>
	[<<<<.>>>>->>]
	<<
]	

The parts I surrounded with ** I found to be unneeded. And I have been able to leave them away without much issue.

@@ -0,0 +1 @@
>,>,[<[>->+<[>]>[<+>-]<<[<]>-]>[-<+>]>[-<+<+>>]<]<.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm generally happy with this code, it did take some checking to find out that the [>->+<[>]>[<+>-]<<[<]>-] part, you got from here was in the public domain, but I eventually found this, so it's fine.

@Ariana1729
Copy link
Contributor Author

oh yes hi, updated the code&updated this branch

@@ -209,6 +213,114 @@ and modulo method:
[import, lang="LOLCODE"](code/lolcode/euclid.lol)
{% sample lang="bash" %}
[import, lang="bash"](code/bash/euclid.bash)
{% sample lang="bf" %}
#### Subtraction varient
##### Code
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy with the code at this point. The code is as slim as it can be without having to redo the fundemantals. This leaves me with one final question, and that one is of style: What is your justification for writing your code as a one-liner and then a explanation in the md-file? We already have a brainfuck bubble sort and it is quiet different -> here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

iirc there was a discussion in the discord chat about if to combine the explanation and code, and we agreed on removing all comments in the code to make it more 'brainfuck', i see if i can find that chat

Copy link
Contributor Author

@Ariana1729 Ariana1729 Nov 1, 2018

Choose a reason for hiding this comment

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

#407 (comment)
So basically there was a discussion, also on discord iirc? and was like agreed to have the brainfuck code to have comments striped

Copy link
Member

Choose a reason for hiding this comment

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

I used the "source code" then commented version with my whitespace submission. I think it's best this way. Brainfuck is a joke language and the joke is more effective without comments, but then after you see the source code you want to know more and that's when the comments are nice.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just find the format we already have for the bubble sort bf more easy to read and review and it also keeps documentation and code in the same place, which I prefer. And when this PR is added we'll lose some concistency between chapters. Still, having a style guide for brainfuck code seams a bit ridiculous and if this is the way some other people already agreed on, I'm fine with that. In that case I will start reviewing the explanation part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait so do we want like
Brainfuck is a joke language and the joke is more effective without comments & reformat prev code
or like same as previous pr

Copy link
Contributor

Choose a reason for hiding this comment

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

@jiegillet prefers the first and I prefer the latter. I've asked Leios what he thinks of it, he'll look at it later.

Copy link
Member

Choose a reason for hiding this comment

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

I understand that the in-text code should be more BF-like; however, a commented version is also necessary (if possible). Both this chapter and bubble sort provide an adequate solution; however, I would argue that the bubble sort seems much easier to read when the two chapters are put side-by-side.

I think this ultimately boils down to a number of factors:

  1. a single line of BF code does not actually fit on the page when rendering online
  2. the explanation provided for this chapter is a bit hard to follow. Somehow the commented Bubble sort implementation is easier, even though it has less detail.

With other esoteric languages (like whitespace), the code was displayed as it would be seen in actually whitespace code, and then a heavily commented / modified version was put underneath. I think this is also a fine solution, but if we do that we need to make sure that the BF code actually fits into the AAA codebox.

I think the best solution is just to provide a heavily commented BF code sample with the explanation in-built. If that's not possible, the explanation at the end of the chapter is still useful, but should be rewritten (which I can help with). Sorry for all the extra work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I just rmbed why the commented code wasnt in the file
All the .,[]+- was screwing up the code

@leios leios changed the title Added brainfuck code and explanation Added brainfuck code and explanation for Euclidean Algorithm Nov 10, 2018
was kinda busy with like music and school so was afk the whole of nov:/
Not quite sure how well this explanation is but at least its slightly better
@Ariana1729
Copy link
Contributor Author

was kinda busy with like music and school so was afk the whole of nov:/
Not quite sure how well this explanation is but at least its slightly better

**Here, we subtract 1 from cell 2 from 3 until one of them hits 0, the other cell would be |a-b|**
```
<<
[->- subtracts a from b, assuming a>b
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't a>b actually affect the code execution here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that’s one of the reasons why I didn’t comment in the actual bf code, cuz .,<> are all affecting execution

@leios leios added the lang: brainfuck Brainfuck programming language label Aug 28, 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.) lang: brainfuck Brainfuck programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants