Problem 61144. FEN Chess Notation

Note: This problem is the reverse, or complement, of Problem 61155 - FEN to Chess Board.
Given an 8-by-8 character matrix representing a chess board, convert it to FEN (Forsyth-Edwards Notation) board position format.
The input matrix uses:
  • Dots (".") for empty squares
  • Letters for pieces: "rnbqkp" (black pieces) and "RNBQKP" (white pieces)
FEN notation encodes each row from top to bottom, separated by slashes ("/"). Consecutive empty squares are replaced by their count (1-8).
Example 1
Starting position:
input = [ ...
'rnbqkbnr'
'pppppppp'
'........'
'........'
'........'
'........'
'PPPPPPPP'
'RNBQKBNR']
output =
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR'
Example 2
After white plays e4:
input = [ ...
'rnbqkbnr'
'pppppppp'
'........'
'........'
'....P...'
'........'
'PPPP.PPP'
'RNBQKBNR']
output =
'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR'
Note: Empty squares before the P are "4", the P itself, then "3" empty squares after.

Solution Stats

87.5% Correct | 12.5% Incorrect
Last Solution submitted on Jan 08, 2026

Solution Comments

Show comments

Problem Recent Solvers7

Suggested Problems

More from this Author53

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!