Mapfuck

From Esolang
(Redirected from MapFuck)
Jump to navigation Jump to search

Mapfuck is an esolang created by QTpye (talk), it is a derivative of brainfuck where the commands are remapped to different chars every time a command is read, this causes cascading changes where if a single char is changed all chars in the following program have to be rewritten to correct for this remapping (also see Mapfuck 2: Turring Boogaloo and RC4 Mapfuck)

commands

Char Instruction Number
> Move the pointer to the right 1
< Move the pointer to the left 2
+ Increment the memory cell at the pointer 3
- Decrement the memory cell at the pointer 4
. Output the character signified by the cell at the pointer 5
, Input a character and store it in the cell at the pointer 6
[ Jump past the matching ] if the cell at the pointer is 0 7
] Jump back to the matching [ if the cell at the pointer is nonzero 8

mappings

last char: > < + - . , [ ]
FROM (char for inst #) TO (char for inst #)
1 2 8 1 2 8 8 1 2
2 3 1 3 4 7 2 7 1
3 4 2 5 6 6 6 2 4
4 5 3 7 8 5 4 5 3
5 6 4 2 1 4 5 3 6
6 7 5 4 3 3 3 8 5
7 8 6 6 5 2 7 4 8
8 1 7 8 7 1 1 6 7

processing of code

processing of code is done by repeating 2 steps

step 1: assemble an instruction map. this shows which character does what

step 2: read in a single charactor and do the instruction from the instruction map

these 2 steps are done once for every instruction. starting with the first character in the code


so if we want to make code to run the instruction set 3333 or increase the value at the pointer 4 times (see first table) then we do as follows


instruction #1

does an instruction map exist yet? NO, we assume the default instruction map of

instruction char number
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8


change map based on previous character in code (no previous character as we are on first character, so no change)


then we read in a character and do its corresponding instruction set

or in this case we ask what char do we need for instruction 3

instruction char number
1 1
2 2
3 3 <- instruction 3 is called with char 3 a +
4 4
5 5
6 6
7 7
8 8


so the first char we need is for the code is +, the same as a normal brainfuck program

now we must repeat for the next instruction


Instruction #2

does an instruction map exist yet? YES, it is the instruction map from before


instruction char number
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8


change map based on previous character in code! the previous character we just saw was a +. so we look at the + column in the mappings table

this gives us the following change table


CHANGE TABLE
last char: +
FROM (char for inst #) TO (char for inst #)
1 1
2 3
3 5
4 7
5 2
6 4
7 6
8 8


we use this table to change the instruction map as follows

look at the row for instruction 2

instruction char number
1 1
2 2 <----
3 3
4 4
5 5
6 6
7 7
8 8


in the change table above, in the second row, it says to change the char for instruction 2 (fig 1 below) to the char for instruction 3 (fig 2 below)


char for instruction 2

Fig 1
instruction char number
1 1
2 -->2<--
3 3
4 4
5 5
6 6
7 7
8 8



char for instruction 3

Fig 2
instruction char number
1 1
2 2
3 -->3<--
4 4
5 5
6 6
7 7
8 8


so we make a new table with a 3 (the character in fig 2) in the second position (the position of the character in fig 1)

New Instruction Map
instruction char number
1
2 3
3
4
5
6
7
8


we continue filling out the New Instruction Map in this way until it is full

please feel free to draw a copy of this table on a piece of paper and fill it out the rest of the way to gain a better understating of the mapping procedure (understanding this part makes all the difference)


here is the completed New Instruction Table, open once you have finished practicing the conversion

New Instruction Map
instruction char number
1 1
2 3
3 5
4 7
5 2
6 4
7 6
8 8

we now have the new instruction map so the next instruction we want is instruction 3 (2nd instruction of 3333) which is char number 5 or .

so the code we have so far is +. this is the instruction set 33 or increase the value at the pointer by 2, yay were half way there (and living on a prayer)


instruction #3

does an instruction map exist yet? YES, it is the instruction map from before


New Instruction Map
instruction char number
1 1
2 3
3 5
4 7
5 2
6 4
7 6
8 8


change map based on previous character in code! the previous character we just saw was a .. so we look at the . column in the mappings table

this gives us the following change table


CHANGE TABLE
last char: .
FROM (char for inst #) TO (char for inst #)
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1

changing are instruction map according to what we just learned above we get a resulting instruction map as follows

Instruction Map
instruction char number
1 8
2 6
3 4
4 2
5 7
6 5
7 3
8 1

were looking for the char for instructions 3, in this case its char 4 or -

so the next char for are code is - so out code becomes +.-


instruction 4:

does an instruction map exist yet? YES, it is the instruction map from before

Instruction Map
instruction char number
1 8
2 6
3 4
4 2
5 7
6 5
7 3
8 1

change map based on previous character in code! the previous character we just saw was a -. so we look at the - column in the mappings table

this gives us the following change table


CHANGE TABLE
last char: -
FROM (char for inst #) TO (char for inst #)
1 2
2 4
3 6
4 8
5 1
6 3
7 5
8 7

this makes our new instruction map

Instruction Map
instruction char number
1 6
2 2
3 5
4 1
5 8
6 4
7 7
8 3

we want instruction 3 so the char we need is char 5 .


so, drum role please... our code is +.-. (wow)

now go make hello world or something