Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Length 5 Snippet - One of the Logic GatesLogic Gates

This is the AND gate, from one of the 16 Logic Gates answer by Martin Ender♦16 Logic Gates answer by Martin Ender♦. In his answer, the explanation was left for readers as practise. Well, maybe it's time for the solution:

These 2 are simplified (thus not a very good version) of a cat program. For a real working one, please see herehere.

In some code golf challenges, it is acceptable to have null bytes printed before the desired output. However this is not the case for the simple cat challenge attached above :P Also, this does not handle null bytes \0 well. If you are curious how to do the cat with 6 bytes which handles \0 and prints nothing else and stops, check it outcheck it out! (The 6 bytes solution is shown after the 7 bytes)

Length 5 Snippet - One of the Logic Gates

This is the AND gate, from one of the 16 Logic Gates answer by Martin Ender♦. In his answer, the explanation was left for readers as practise. Well, maybe it's time for the solution:

These 2 are simplified (thus not a very good version) of a cat program. For a real working one, please see here.

In some code golf challenges, it is acceptable to have null bytes printed before the desired output. However this is not the case for the simple cat challenge attached above :P Also, this does not handle null bytes \0 well. If you are curious how to do the cat with 6 bytes which handles \0 and prints nothing else and stops, check it out! (The 6 bytes solution is shown after the 7 bytes)

Length 5 Snippet - One of the Logic Gates

This is the AND gate, from one of the 16 Logic Gates answer by Martin Ender♦. In his answer, the explanation was left for readers as practise. Well, maybe it's time for the solution:

These 2 are simplified (thus not a very good version) of a cat program. For a real working one, please see here.

In some code golf challenges, it is acceptable to have null bytes printed before the desired output. However this is not the case for the simple cat challenge attached above :P Also, this does not handle null bytes \0 well. If you are curious how to do the cat with 6 bytes which handles \0 and prints nothing else and stops, check it out! (The 6 bytes solution is shown after the 7 bytes)

Post Made Community Wiki by Dennis
Length 5 snippet from the logic gates!
Source Link
Sunny Pun
  • 861
  • 7
  • 8

Length 5 Snippet - One of the Logic Gates

?<!@<

This is the AND gate, from one of the 16 Logic Gates answer by Martin Ender♦. In his answer, the explanation was left for readers as practise. Well, maybe it's time for the solution:

and1

First ? reads the first input.

If it is 0, then the IP got reflected to NE direction at < and directly wraps "to the left" (as it is <=0) and got printed at !. Whatever it reads at ?, it wraps and stops at @.

and2

If it is 1, the IP takes the right branch for the "conditional" and hit the "inclined mirror" side of < and got reflected back and hit the "hub" side of < which sends it to W direction to read another input. It then wraps and hit the "horizontal mirror" side of < and gets itself to an implicit-if at the corner. 6 instructions made within this blue path.

The different usages of < are all demostrated in this example.

If the second input is 0, then the IP goes along the red path above, which prints a 0 and reads the "third" input and stops.

If it is a 1 instead, yay we finally got 2 1s for the AND gate! The IP goes along the green path and prints out the 1 and terminates!

Length 3 and Length 4 Snippets - Cats

Length 5 Snippet - One of the Logic Gates

?<!@<

This is the AND gate, from one of the 16 Logic Gates answer by Martin Ender♦. In his answer, the explanation was left for readers as practise. Well, maybe it's time for the solution:

and1

First ? reads the first input.

If it is 0, then the IP got reflected to NE direction at < and directly wraps "to the left" (as it is <=0) and got printed at !. Whatever it reads at ?, it wraps and stops at @.

and2

If it is 1, the IP takes the right branch for the "conditional" and hit the "inclined mirror" side of < and got reflected back and hit the "hub" side of < which sends it to W direction to read another input. It then wraps and hit the "horizontal mirror" side of < and gets itself to an implicit-if at the corner. 6 instructions made within this blue path.

The different usages of < are all demostrated in this example.

If the second input is 0, then the IP goes along the red path above, which prints a 0 and reads the "third" input and stops.

If it is a 1 instead, yay we finally got 2 1s for the AND gate! The IP goes along the green path and prints out the 1 and terminates!

Length 3 and Length 4 Snippets - Cats

Added the cats as length 3 and 4 snippets
Source Link
Sunny Pun
  • 861
  • 7
  • 8

Images created with Timwi's tools with link provided in the Factoid! The heaheaders Length n Snippet are Try It Online! links :)

Length 3 and Length 4 Snippets - Cats

These 2 are simplified (thus not a very good version) of a cat program. For a real working one, please see here.

,;~

This reads and prints and also outputs a lot of trailing mysterious symbols. What's happening?

, reads a byte and ; prints it no matter what , gets (If there is no input, , will return a -1 and ; will print it modulo 256 which is 255).

Here is a trick which is useful in creating Hexagons: Using ~ (negation) to control the direction the IP goes before it reaches an if (no matter it is an implicit one or an explicit one like < and > and some other conditionals).

If you find this hard to understand, then it's worth mentioning that this is not a linear loop. As an exercise imagine the above are put into a 2-hexagon and you'll see why we need ~ to do make a loop with the implicit if :P The code basically runs in the same manner as in the length 2 snippet below!

Thus, when there is a byte, the memory will be positive and ~ makes it negative so it goes back to the top to read another byte. Yet it won't stop...

So let's see the length 4 version of the cat.

<,@;

When you try this, it looks good. Finally we have one program which stops!

cat4

It starts on the top left with an initial value of 0. A trick here which is (again) quite common - deflect the initial IP with <. This is particularly useful when the main loop should end when the calculated value is <=0.

Here it comes to the blue path. ; prints the null byte (as it is initially 0) and , reads a byte. An implicit-if decides if it should go to the green one (doing nothing and wraps back to the main blue loop for printing this byte) or it should go to the red terminal @.

In some code golf challenges, it is acceptable to have null bytes printed before the desired output. However this is not the case for the simple cat challenge attached above :P Also, this does not handle null bytes \0 well. If you are curious how to do the cat with 6 bytes which handles \0 and prints nothing else and stops, check it out! (The 6 bytes solution is shown after the 7 bytes)

Images created with Timwi's tools with link provided in the Factoid! The hea Length n Snippet are Try It Online! links :)

Images created with Timwi's tools with link provided in the Factoid! The headers Length n Snippet are Try It Online! links :)

Length 3 and Length 4 Snippets - Cats

These 2 are simplified (thus not a very good version) of a cat program. For a real working one, please see here.

,;~

This reads and prints and also outputs a lot of trailing mysterious symbols. What's happening?

, reads a byte and ; prints it no matter what , gets (If there is no input, , will return a -1 and ; will print it modulo 256 which is 255).

Here is a trick which is useful in creating Hexagons: Using ~ (negation) to control the direction the IP goes before it reaches an if (no matter it is an implicit one or an explicit one like < and > and some other conditionals).

If you find this hard to understand, then it's worth mentioning that this is not a linear loop. As an exercise imagine the above are put into a 2-hexagon and you'll see why we need ~ to do make a loop with the implicit if :P The code basically runs in the same manner as in the length 2 snippet below!

Thus, when there is a byte, the memory will be positive and ~ makes it negative so it goes back to the top to read another byte. Yet it won't stop...

So let's see the length 4 version of the cat.

<,@;

When you try this, it looks good. Finally we have one program which stops!

cat4

It starts on the top left with an initial value of 0. A trick here which is (again) quite common - deflect the initial IP with <. This is particularly useful when the main loop should end when the calculated value is <=0.

Here it comes to the blue path. ; prints the null byte (as it is initially 0) and , reads a byte. An implicit-if decides if it should go to the green one (doing nothing and wraps back to the main blue loop for printing this byte) or it should go to the red terminal @.

In some code golf challenges, it is acceptable to have null bytes printed before the desired output. However this is not the case for the simple cat challenge attached above :P Also, this does not handle null bytes \0 well. If you are curious how to do the cat with 6 bytes which handles \0 and prints nothing else and stops, check it out! (The 6 bytes solution is shown after the 7 bytes)

added 1388 characters in body
Source Link
Sunny Pun
  • 861
  • 7
  • 8
Loading
Length 1 snippnet. Thanks for the vote!
Source Link
Sunny Pun
  • 861
  • 7
  • 8
Loading
Source Link
Sunny Pun
  • 861
  • 7
  • 8
Loading