Skip to main content
Fixed mixed up direction
Source Link
Isti115
  • 101
  • 4

Again this is an infinite loop. The program starts by travelling left-to right, which does the input then output. The program will continue to flow in the same direction whenever it can. At the light green codel the only exit is to start moving back the other way. When travelling back leftright-to-rightleft it attempts to perform subtract and add commands, but the stack is empty so these become no-ops.

Again this is an infinite loop. The program starts by travelling left-to right, which does the input then output. The program will continue to flow in the same direction whenever it can. At the light green codel the only exit is to start moving back the other way. When travelling back left-to-right it attempts to perform subtract and add commands, but the stack is empty so these become no-ops.

Again this is an infinite loop. The program starts by travelling left-to right, which does the input then output. The program will continue to flow in the same direction whenever it can. At the light green codel the only exit is to start moving back the other way. When travelling back right-to-left it attempts to perform subtract and add commands, but the stack is empty so these become no-ops.

Post Made Community Wiki by Dennis
added 1528 characters in body
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8

54 Codels

54 Codels

Prints "hi!" to stdout

Not a particularly long message, but printing in piet takes a surprising amount of room. Printing is done by using unicode values, and integers are pushed onto the stack by using the size of the region that is being exited. Since we have a very limited number of codels for this challenge, we use some math to get up to the printable range we want.

The program starts with a push of 5 from the cyan region on the left. From here, it flows right along the top with 6 duplicate operations to prime the stack with a bunch of 5s. Next is push 1, subtract to put a 4 on top of the stack, then 2 multiply operations to put 455=100 on top of the stack. Then a duplicate for 2 100s.

Now the program bounces off of the black and starts working leftwards along the bottom. Push operations of 3 and 2 and then a roll to bury the 2 100s under a 5. Next is push 1, subtract, and add to get 100+5-1=104 on top of the stack, which is unicode "h". Next 2 operations are push 1 and pointer to get around the corner and start moving right along the middle, and then output to print "h".

Next is add 100+5=105 on top of the stack, and output to print "i". The stack now contains two 5s. Push 1, add, multiply gives (1+5)*5=30. Finally push 3 and add for 33, and output for the trailing "!". The program then goes right through the remaining white space to end in the green on the right.

54 Codels

54 Codels

Prints "hi!" to stdout

Not a particularly long message, but printing in piet takes a surprising amount of room. Printing is done by using unicode values, and integers are pushed onto the stack by using the size of the region that is being exited. Since we have a very limited number of codels for this challenge, we use some math to get up to the printable range we want.

The program starts with a push of 5 from the cyan region on the left. From here, it flows right along the top with 6 duplicate operations to prime the stack with a bunch of 5s. Next is push 1, subtract to put a 4 on top of the stack, then 2 multiply operations to put 455=100 on top of the stack. Then a duplicate for 2 100s.

Now the program bounces off of the black and starts working leftwards along the bottom. Push operations of 3 and 2 and then a roll to bury the 2 100s under a 5. Next is push 1, subtract, and add to get 100+5-1=104 on top of the stack, which is unicode "h". Next 2 operations are push 1 and pointer to get around the corner and start moving right along the middle, and then output to print "h".

Next is add 100+5=105 on top of the stack, and output to print "i". The stack now contains two 5s. Push 1, add, multiply gives (1+5)*5=30. Finally push 3 and add for 33, and output for the trailing "!". The program then goes right through the remaining white space to end in the green on the right.

30 codel program
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8

30 Codels

30 Codels

Fibonacci generator. Prints out terms of the Fibonacci sequence to stdout and doesn't stop.

This is the first introduction of the roll operator, as well as the first time that a region size bigger than 1 is used with the push operator to get a specific value onto the stack.

As always starts in the top-left moving right. The first 2 operations push a 1 onto the stack and then output it since the Fibonacci sequence starts with two 1s, but the main program loop will only print 1 once. Then it pushes 2 more 1s onto the stack to end up in the dark magenta in the top-right to start the main program loop.

Moving down the right side we duplicate and output to print off the next term of the sequence, then duplicate again to get a copy of the current sequence value. Moving left across the bottom executes 2 push operations. Since the light red region in the bottom-right is 3 codels in size, the first push will push a 3 onto the stack instead of a 1.

Moving up into the light blue is a roll operation. This pops the top 2 values off of the stack and performs a number of rolls equal to the first value popped, to a depth equal to the second value popped. In this case, it will perform 1 roll to a depth of 3. A roll to depth n takes the top value of the stack (our duplicated current value) and buries it n places deep. Our stack is only 3 deep right now so it will bury the top value at the bottom.

Moving up once more performs an add operation adding together the current sequence value with the previous sequence value. Our stack now has the next (new current) sequence value on top, and the last value below it. The program now moves right across the white into the dark magenta to start the loop again.

The yellow pattern in the middle is never used.

30 Codels

30 Codels

Fibonacci generator. Prints out terms of the Fibonacci sequence to stdout and doesn't stop.

This is the first introduction of the roll operator, as well as the first time that a region size bigger than 1 is used with the push operator to get a specific value onto the stack.

As always starts in the top-left moving right. The first 2 operations push a 1 onto the stack and then output it since the Fibonacci sequence starts with two 1s, but the main program loop will only print 1 once. Then it pushes 2 more 1s onto the stack to end up in the dark magenta in the top-right to start the main program loop.

Moving down the right side we duplicate and output to print off the next term of the sequence, then duplicate again to get a copy of the current sequence value. Moving left across the bottom executes 2 push operations. Since the light red region in the bottom-right is 3 codels in size, the first push will push a 3 onto the stack instead of a 1.

Moving up into the light blue is a roll operation. This pops the top 2 values off of the stack and performs a number of rolls equal to the first value popped, to a depth equal to the second value popped. In this case, it will perform 1 roll to a depth of 3. A roll to depth n takes the top value of the stack (our duplicated current value) and buries it n places deep. Our stack is only 3 deep right now so it will bury the top value at the bottom.

Moving up once more performs an add operation adding together the current sequence value with the previous sequence value. Our stack now has the next (new current) sequence value on top, and the last value below it. The program now moves right across the white into the dark magenta to start the loop again.

The yellow pattern in the middle is never used.

Add backticks to make operation names more distinct
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
edited body
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Add 25 codel answer
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
added 148 characters in body
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Add 20 codel program, clarify earlier programs
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
12 and 15 codel programs
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
7-9 Codel answers
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Add 6 codel program
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
5 codels
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Add 4 codel program
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
added 354 characters in body
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Add 2 codel program
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Add 1 codel answer
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading
Source Link
Spencer
  • 1.7k
  • 1
  • 10
  • 8
Loading