Problem 61144. FEN Chess Notation
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
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
2 Solvers
More from this Author51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!