Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 4, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/07caf9920a6cb34af2db1d09f0dfe1ca to your computer and use it in GitHub Desktop.
Save lbvf50mobile/07caf9920a6cb34af2db1d09f0dfe1ca to your computer and use it in GitHub Desktop.
Just PHP FUN 094.
<?php
# https://www.codewars.com/kata/582e0450fe38013dbc0002d3 Regex Tic Tac Toe Win Checker.
function regexTicTacToeWinChecker($board) {
$line = "((XXX.{6})|(...XXX...)|(.{3}.{3}XXX)|(OOO.{6})|(...OOO...)|(.{3}.{3}OOO))";
$column = "((..X){3}|(.X.){3}|(X..){3})|((..O){3}|(.O.){3}|(O..){3})";
$diagonal = "(((X...X...X)|(..X.X.X..))|((O...O...O)|(..O.O.O..)))";
$regex = '/^'."$line|$column|$diagonal".'$/i';
return (bool) preg_match($regex, $board);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment