5 kyu

Reversi row rudiments

154 of 273Insti

Description:

Introduction:

Reversi is a game usually played by 2 people on a 8x8 board. Here we're only going to consider a single 8x1 row.

Players take turns placing pieces, which are black on one side and white on the other, onto the board with their colour facing up. If one or more of the opponents pieces are sandwiched by the piece just played and another piece of the current player's colour, the opponents pieces are flipped to the current players colour.

Note that the flipping stops when the first piece of the player's colour is reached.

Task:

Your task is to take an array of moves and convert this into a string representing the state of the board after all those moves have been played.

Input:

The input to your function will be an array of moves. Moves are represented by integers from 0 to 7 corresponding to the 8 squares on the board. Black plays first, and black and white alternate turns. Input is guaranteed to be valid. (No duplicates, all moves in range, but array may be empty)

Output:

8 character long string representing the final state of the board. Use '*' for black and 'O' for white and '.' for empty.

Examples:

   moves   |     result
--------------------------
 []       -->  "........"
 [3]      -->  "...*...."
 [3,4]    -->  "...*O..."
 [3,4,5]  -->  "...***.."
Games
Algorithms

Stats:

CreatedJul 18, 2015
PublishedJul 18, 2015
Warriors Trained625
Total Skips88
Total Code Submissions3285
Total Times Completed273
Ruby Completions65
Python Completions154
JavaScript Completions71
CoffeeScript Completions8
Total Stars32
% of votes with a positive feedback rating95% of 86
Total "Very Satisfied" Votes79
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes1
Total Rank Assessments12
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Insti Avatar
  • GiacomoSorbi Avatar
  • smile67 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad