Draft

Befunge-98: Fibonacci sequence

Description:

History

Befunge is an essoteric programming language (like BF) initially created in 1993 by Chris Pressey. In 1998, Chriss Pressely released what is now the most recent Befunge specification which was significantly more expansive than Befunge-93. Befunge-98 is a 2 dimensional programming language, where the pointer initially is in the top left moving right every tick, but can be turned based on various commands.

Basic Operation

Programs are controlled by the code in the code-space which perform operations on the pointer, code-space, and the stack. when the pointer reaches an edge, it wraps around. Both the stack and the code space can have any signed integer between -2,147,483,647 and 2,147,483,647 which is also the limit on the x and y coordinates possible in the code space. For a detail explaination of the nuances, see the Befunge specification.

The Task at Hand

Create a Befunge program (yes, Befunge, not JavaScript) that outputs the nth Fibonacci number based on an integer input in less than 30x30 characters. The input should be recieved with & and the output should be given with ,

example: input=7 output=13

example: input=9 output=34

the input will not exceed 250 and as such, the output won't need to exceed 52 digits.

If you would like to use a Befunge enviorment to debug, I have one available at efhiii.github.io/games/befunge/.

Command List

All of the commands are listed both in the Wiki and Specification (linked at the top), but here's a list here:

0-f representing the hex numbers 0-15,

+ - * / % for math operations which pop the top 2 elements of the stack and push the answer,

! which performs a not operation on the top element of the stack,

" which toggles in to/out of a string mode that pushes the char code of every character the pointer hits (until the next "),

@ which ends a program with exit code 0,

^v<> which make the pointer start moving up, down, left, and right respectively,

# which makes the pointer skip the next instruction,

$ which pops the top instruction,

& and ~ which pushes an input integer and input character char code respectively,

' which pushes the char code of the next character instead of operating on it,

, and . which outputs the character with a poped number char code and the poped number respectively,

[ and ] which turn left and right 90 degrees respectively,

\ which swaps the top 2 elements on the stack,

` which pushes 1 if the top element is less than the next, else 0,

: which copies the top element of the stack to the top of the stack,

; which has the pointer jump over everything between this and the next ;,

? which has the pointer go in a random direction,

_ and | which are east/south if zero, else west/north,

g which gets the char code of the character at x,y popped from the stack in the code space,

p which puts the char code of the character at popped after popping x,y from the stack at x,y in the code space,

j which jumps a popped number of spaces in the direction of the pointer,

k which does the next operation a popped number of times (if 0, skips the next operation),

n which clears the stack,

q which quits with a popped exit code,

r which reflects,

s which sets the next space to the popped char code,

t which duplicates the pointer with a copy of the stack and sends it in the opposite direction,

w which sends the pointer left, straight or right if the popped value is >, =, or < the value popped after it respectively,

x which sets the absolute pointer vector from the popped 2 values; x,y,

z which delays the pointer's movement,

and { & } which set/reset the orgin with a new stack, moving a popped number of elements between the current stack, and the transfered one.

More By Author:

Check out these other kata created by EFHIII

Stats:

CreatedNov 29, 2018
Warriors Trained57
Total Skips2
Total Code Submissions8
Total Times Completed3
JavaScript Completions3
Total Stars1
% of votes with a positive feedback rating75% of 2
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments2
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • EFHIII Avatar
Ad