Skip to content

Euclidian Algorithm Piet Implementation #448

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

Conversation

ThijsRay
Copy link
Contributor

@ThijsRay ThijsRay commented Oct 4, 2018

Euclidian algorithm in Piet

I would argue that text books can be better understood if they contain pictures. Piet is an excellent programming language that achieves this goal.

This pull request aims to implement the Euclidian Algorithm in Piet.

To run Piet programs, I would advice npiet. The -t and -tps parameters are especially useful because they show exactly what path the program is taking.

Euclidian algorithm with the modulo operator

Actual version: Euclidian algorithm with the module operator (small)
Enlarged version for better visibility: Euclidian algorithm with the module operator
This version is quite small because it takes only a few commands to do the euclidian algorithm with the modulo operator. Possibly the smallest implementation of the euclidian algorithm in Piet yet.

Euclidian algorithm with subtraction

Actual version: Euclidian algorithm with subtraction (small)
Enlarged version for better visibility: Euclidian algorithm with subtraction
This version is a lot bigger than the previous one, because of a few reasons:

  • Taking an absolute value in Piet takes a lot of commands.
  • The stack has to be modified a lot to make the algorithm work.
  • There are a lot of branches.

I added some extra colourful pixels to fill up the empty space I was left with.

Reviewing these pixels

The pixels are based on the implementation that can be found in euclidian_algorithm.piet. This can be manually verified with npiet -t [program].

@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 4, 2018
@leios
Copy link
Member

leios commented Oct 4, 2018

This looks really cool. I'll try to learn it and do a review when I can and when it's completed.

@ThijsRay ThijsRay changed the title WIP: Euclidian Algorithm Piet Implementation Euclidian Algorithm Piet Implementation Oct 5, 2018
@ThijsRay ThijsRay force-pushed the euclidian_algorithm_in_piet branch 2 times, most recently from e1e5034 to ffb37ac Compare October 8, 2018 09:22
@Liikt Liikt self-assigned this Oct 8, 2018
Copy link

@Liikt Liikt left a comment

Choose a reason for hiding this comment

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

Everything looks good so far. Three questions though:

  1. Is there a specific reason you started with a different color?
  2. How did you manage to limit the Color Blocks of the As in the sub euclid to onl 4? did you change the color slightly?
  3. Have you gone crazy? :D

@ThijsRay
Copy link
Contributor Author

@Liikt

  1. There is no reason for that. I just chose a random starting colour.
  2. I changed the colour slightly. The colour blocks that count are of the colour #00ffff. The colour of the A's is #00fffe.
  3. Not yet!

@ThijsRay ThijsRay force-pushed the euclidian_algorithm_in_piet branch from ffb37ac to 539cd58 Compare October 16, 2018 19:16
Copy link

@Liikt Liikt left a comment

Choose a reason for hiding this comment

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

Aight. This is crazy enough and it works

@Liikt Liikt merged commit 0435b24 into algorithm-archivists:master Dec 23, 2018
theinventor13 added a commit to theinventor13/algorithm-archive that referenced this pull request Dec 24, 2018
…lidian_algorithm_in_piet"

This reverts commit 0435b24, reversing
changes made to fb4f592.
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.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants