Code Golf: Connect 4
Posted
by Matthieu M.
on Stack Overflow
See other posts from Stack Overflow
or by Matthieu M.
Published on 2010-04-03T12:47:28Z
Indexed on
2010/04/03
12:53 UTC
Read the original article
Hit count: 496
If you don't know the Connect 4 game, follow the link :)
I used to play it a lot when I was a child. At least until my little sister got bored with me winning...
Anyway I was reading the Code Golf: Tic Tac Toe the other day and I thought that solving the Tic Tac Toe problem was simpler than solving the Connect 4... and wondered how much this would reflect on the number of characters a solution would yield.
I thus propose a similar challenge: Find the winner
The grid is given under the form of a string meant to passed as a parameter to a function.
- The goal of the code golf is to write the body of the function, the parameter will be
b
, of string type - The image in the wikipedia article leads to the following representation:
"....... ..RY... ..YYYR. ..RRYY. ..RYRY. .YRRRYR"
(6 rows of 7 elements) but is obviously incomplete (Yellow has not won yet) - There is a winner in the grid passed, no need to do error checking
- Remember that it might not be exactly 4
- The expected output is the letter representing the winner (either
R
orY
)
I expect perl mongers to produce the most unreadable script (along with Ook and whitespace, of course), but I am most interested in reading innovative solutions. I must admit the magic square solution for Tic Tac Toe was my personal fav and I wonder if there is a way to build a similar one with this.
Well, happy Easter weekend :) Now I just have a few days to come up with a solution of my own!
© Stack Overflow or respective owner