In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is OK). The input board is guaranteed to be a square board. You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or if no one has won. Specifically, the given board в will be a list of n strings, where each string has length n . There are two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied--- or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string Gif the G player has won; or the string otherwise. Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a winner, that player will be the only winner. Here are a few examples (keep in mind, the board size doesn't have to be 4x4): board1= ['RRRG', 'GRRG', '.R..'] board2= ['GRRG', '.GGR', 'GRGR' › 'RGRG'] In these cases, findWinner(board1)=='-' ' and findwinner(board2)=='G' . Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return within 2 seconds.
In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is OK). The input board is guaranteed to be a square board. You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or if no one has won. Specifically, the given board в will be a list of n strings, where each string has length n . There are two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied--- or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string Gif the G player has won; or the string otherwise. Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a winner, that player will be the only winner. Here are a few examples (keep in mind, the board size doesn't have to be 4x4): board1= ['RRRG', 'GRRG', '.R..'] board2= ['GRRG', '.GGR', 'GRGR' › 'RGRG'] In these cases, findWinner(board1)=='-' ' and findwinner(board2)=='G' . Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return within 2 seconds.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list
of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is
OK). The input board is guaranteed to be a square board.
if no
You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or
one has won. Specifically, the given board B will be a list of n strings, where each string has length n. There are
two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied---
or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string G if the G
player has won; or the string otherwise.
Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a
winner, that player will be the only winner.
Here are a few examples (keep in mind, the board size doesn't have to be 4×4 ):
board1 = ['RRRG',
'GRRG'
'.R..']
board2= ['GRRG',
'.GGR'
'GRGR'
'RGRG']
In these cases, findWinner (board1)=='=' and findWinner (board2)=='G' .
Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return
within 2 seconds.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F28e2e603-ecab-45a4-8f55-ede3fe263a81%2F6702f1b2-b05e-41e0-ba40-934dd824d9a8%2F4q9zwx_processed.png&w=3840&q=75)
Transcribed Image Text:In the game of Connect Four, two players take turns playing on an n x n board, which we represent as a 2d list (a list
of strings). To win, a player needs to connect 4 consecutive pieces in a row or column, or diagonally (either direction is
OK). The input board is guaranteed to be a square board.
if no
You will implement a function findWinner (B: List[str]) -> str that takes a board and returns the winner or
one has won. Specifically, the given board B will be a list of n strings, where each string has length n. There are
two players R and G, so each position in the board B[i][j] is either the string R or G if it has been occupied---
or (dot) for an unoccupied spot. You are to return the string R if the R player has won; the string G if the G
player has won; or the string otherwise.
Notice that the size of the board can be obtained by asking for the length of B. We guarantee that if there's a
winner, that player will be the only winner.
Here are a few examples (keep in mind, the board size doesn't have to be 4×4 ):
board1 = ['RRRG',
'GRRG'
'.R..']
board2= ['GRRG',
'.GGR'
'GRGR'
'RGRG']
In these cases, findWinner (board1)=='=' and findWinner (board2)=='G' .
Performance Expectations: The largest input you will be tested is a 100-by-100 board, and your function must return
within 2 seconds.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY