trainfck

From Esolang
Jump to navigation Jump to search
trainfck
Paradigm(s) imperative
Designed by User:Mujk
Appeared in 2023
Memory system Cell-based
Dimensions two-dimensional
Computational class Turing complete
Major implementations trainfck
Influenced by brainfuck
File extension(s) .trainf

Trainfck is a minimalistic esoteric programming language with trains.

description

Trainfck is an esoteric programming language inspired by brainfuck and railways. Trains depart from stations (+) and travel in all directions. There is no limitation on stations and therefore also not on trains.

     |  
     ⬆️  
     🚆  
     |  
-⬅️🚆-+-🚆➡️-  
     |  
     🚆  
     ⬇️  
     |  

If there is no way to go the train turns. When two or more trains collide, they crash. The program ends when all trains have crashed. Memory is managed in byte cells, as in brainfuck. All trains use the same byte cells. Because trainfck uses all the brainfuck operators, the language is turning complete.

cells:

 ------------
 |11|0|17|3|4|
 ------------
       ⬆️

The pointer points on the third cell. This byte can be increased or decreased now. The cell pointer and the cell value is controlled by the direction where a train passes a station, all other operators are on the rails. Empty cells have always the value 0.

operators

  • + : station

train directions:

  1. up -> cell byte + 1
  2. down -> cell byte - 1
  3. right -> cell pointer goes to next cell
  4. left -> cell pointer goes to last cell
  • - | : rails, the train can only move on rails and operators, or they will turn around
  • ^ > < v  : changes direction at the next possible option (o)
  • ? : ignores the next action if the current cell equals the last cell
  • . prints out the current cell
  • , takes input as value for the current cell
  • o change direction

examples

cat

 o-o  
 > <
 o^+,vo
   >  <
   o.-o

add one (old longer version)

    o-    
    >   
 ov,+vo
 |  | <
 |  o^o
 >  > 
 o-.ovo
      |

add one (new shorter version)

   .
   |
   |
 --+-- 
   ,