Connect 4: Spot the Fake!












14












$begingroup$


The bank has been broken into, and all the local mafia thugs have an unusual alibi: they were at home playing Connect 4! In order to assist with the investigation, you are asked to write a program to validate all the Connect 4 boards that have been seized in order to check that the positions are indeed positions from a valid Connect 4 game, and have not been hastily put together as soon as the police knocked on the door.



For example (with R starting), the following is an impossible Connect 4 position.



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | |
| | |Y| | | | |
|R| |Y| | | | |


Your program or function must take in a Connect 4 board and return either




  • A falsy value, indicating that the position is impossible or

  • A string of numbers from 1 to 7, indicating one possible sequence of moves leading to that position (the columns are numbered 1 to 7 from left to right, and so the sequence 112, for example, indicates a red move in column 1, followed by a yellow move in column 1, followed by a red move in column 2). You may choose a column-numbering other than 1234567 if you like, as long as you specify in your solution. If you want to return the list in some other format; for example as an array [2, 4, 3, 1, 1, 3] then that is fine too, as long as it is easy to see what the moves are.


You can choose to read the board in in any sensible format including using letters other than R and Y for the players, but you must specify which player goes first. You can assume that the board will always be 6x7, with two players.



This is code golf, so shortest answer wins. Standard loopholes apply.



Examples



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 1234567 (one possible answer)
| | | | | | | |
|R|Y|R|Y|R|Y|R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | | --> false
| | |Y| | | | |
|R| |Y| | | | |

| | | | | | | |
| | |Y| | | | |
| | |R| | | | |
| | |Y| | | | | --> 323333 (only possible answer)
| | |R| | | | |
| |Y|R| | | | |

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> false (this is the position arising after
| |Y|Y|Y|Y| | | the moves 11223344, but using those moves
| |R|R|R|R| | | the game would have ended once R made a 4)

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> 2134231211 (among other possibilities)
|R|R|Y| | | | |
|Y|R|R|Y| | | |

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> false (for example, 21342312117 does not
|R|R|Y| | | | | work, because Y has already made a diagonal 4)
|Y|R|R|Y| | |R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 112244553 or similar
|Y|Y| |Y|Y| | |
|R|R|R|R|R| | |









share|improve this question











$endgroup$












  • $begingroup$
    Could you, eg, take the board as arrays of characters representing the rows, or do you have to parse the ascii with the |, etc?
    $endgroup$
    – Jonah
    11 hours ago










  • $begingroup$
    @Jpnah You can read the board in using any sensible format, including as arrays.
    $endgroup$
    – John Gowers
    10 hours ago












  • $begingroup$
    Suggested test case: ......./......./......./......./YYY.YY./RRRRRR. (silly game, but legal).
    $endgroup$
    – Arnauld
    5 hours ago






  • 1




    $begingroup$
    May we assume that the empty board will not be given as input?
    $endgroup$
    – Jonathan Allan
    4 hours ago








  • 1




    $begingroup$
    May we assume no "floating" pieces?
    $endgroup$
    – Jonathan Allan
    4 hours ago
















14












$begingroup$


The bank has been broken into, and all the local mafia thugs have an unusual alibi: they were at home playing Connect 4! In order to assist with the investigation, you are asked to write a program to validate all the Connect 4 boards that have been seized in order to check that the positions are indeed positions from a valid Connect 4 game, and have not been hastily put together as soon as the police knocked on the door.



For example (with R starting), the following is an impossible Connect 4 position.



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | |
| | |Y| | | | |
|R| |Y| | | | |


Your program or function must take in a Connect 4 board and return either




  • A falsy value, indicating that the position is impossible or

  • A string of numbers from 1 to 7, indicating one possible sequence of moves leading to that position (the columns are numbered 1 to 7 from left to right, and so the sequence 112, for example, indicates a red move in column 1, followed by a yellow move in column 1, followed by a red move in column 2). You may choose a column-numbering other than 1234567 if you like, as long as you specify in your solution. If you want to return the list in some other format; for example as an array [2, 4, 3, 1, 1, 3] then that is fine too, as long as it is easy to see what the moves are.


You can choose to read the board in in any sensible format including using letters other than R and Y for the players, but you must specify which player goes first. You can assume that the board will always be 6x7, with two players.



This is code golf, so shortest answer wins. Standard loopholes apply.



Examples



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 1234567 (one possible answer)
| | | | | | | |
|R|Y|R|Y|R|Y|R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | | --> false
| | |Y| | | | |
|R| |Y| | | | |

| | | | | | | |
| | |Y| | | | |
| | |R| | | | |
| | |Y| | | | | --> 323333 (only possible answer)
| | |R| | | | |
| |Y|R| | | | |

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> false (this is the position arising after
| |Y|Y|Y|Y| | | the moves 11223344, but using those moves
| |R|R|R|R| | | the game would have ended once R made a 4)

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> 2134231211 (among other possibilities)
|R|R|Y| | | | |
|Y|R|R|Y| | | |

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> false (for example, 21342312117 does not
|R|R|Y| | | | | work, because Y has already made a diagonal 4)
|Y|R|R|Y| | |R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 112244553 or similar
|Y|Y| |Y|Y| | |
|R|R|R|R|R| | |









share|improve this question











$endgroup$












  • $begingroup$
    Could you, eg, take the board as arrays of characters representing the rows, or do you have to parse the ascii with the |, etc?
    $endgroup$
    – Jonah
    11 hours ago










  • $begingroup$
    @Jpnah You can read the board in using any sensible format, including as arrays.
    $endgroup$
    – John Gowers
    10 hours ago












  • $begingroup$
    Suggested test case: ......./......./......./......./YYY.YY./RRRRRR. (silly game, but legal).
    $endgroup$
    – Arnauld
    5 hours ago






  • 1




    $begingroup$
    May we assume that the empty board will not be given as input?
    $endgroup$
    – Jonathan Allan
    4 hours ago








  • 1




    $begingroup$
    May we assume no "floating" pieces?
    $endgroup$
    – Jonathan Allan
    4 hours ago














14












14








14





$begingroup$


The bank has been broken into, and all the local mafia thugs have an unusual alibi: they were at home playing Connect 4! In order to assist with the investigation, you are asked to write a program to validate all the Connect 4 boards that have been seized in order to check that the positions are indeed positions from a valid Connect 4 game, and have not been hastily put together as soon as the police knocked on the door.



For example (with R starting), the following is an impossible Connect 4 position.



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | |
| | |Y| | | | |
|R| |Y| | | | |


Your program or function must take in a Connect 4 board and return either




  • A falsy value, indicating that the position is impossible or

  • A string of numbers from 1 to 7, indicating one possible sequence of moves leading to that position (the columns are numbered 1 to 7 from left to right, and so the sequence 112, for example, indicates a red move in column 1, followed by a yellow move in column 1, followed by a red move in column 2). You may choose a column-numbering other than 1234567 if you like, as long as you specify in your solution. If you want to return the list in some other format; for example as an array [2, 4, 3, 1, 1, 3] then that is fine too, as long as it is easy to see what the moves are.


You can choose to read the board in in any sensible format including using letters other than R and Y for the players, but you must specify which player goes first. You can assume that the board will always be 6x7, with two players.



This is code golf, so shortest answer wins. Standard loopholes apply.



Examples



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 1234567 (one possible answer)
| | | | | | | |
|R|Y|R|Y|R|Y|R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | | --> false
| | |Y| | | | |
|R| |Y| | | | |

| | | | | | | |
| | |Y| | | | |
| | |R| | | | |
| | |Y| | | | | --> 323333 (only possible answer)
| | |R| | | | |
| |Y|R| | | | |

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> false (this is the position arising after
| |Y|Y|Y|Y| | | the moves 11223344, but using those moves
| |R|R|R|R| | | the game would have ended once R made a 4)

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> 2134231211 (among other possibilities)
|R|R|Y| | | | |
|Y|R|R|Y| | | |

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> false (for example, 21342312117 does not
|R|R|Y| | | | | work, because Y has already made a diagonal 4)
|Y|R|R|Y| | |R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 112244553 or similar
|Y|Y| |Y|Y| | |
|R|R|R|R|R| | |









share|improve this question











$endgroup$




The bank has been broken into, and all the local mafia thugs have an unusual alibi: they were at home playing Connect 4! In order to assist with the investigation, you are asked to write a program to validate all the Connect 4 boards that have been seized in order to check that the positions are indeed positions from a valid Connect 4 game, and have not been hastily put together as soon as the police knocked on the door.



For example (with R starting), the following is an impossible Connect 4 position.



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | |
| | |Y| | | | |
|R| |Y| | | | |


Your program or function must take in a Connect 4 board and return either




  • A falsy value, indicating that the position is impossible or

  • A string of numbers from 1 to 7, indicating one possible sequence of moves leading to that position (the columns are numbered 1 to 7 from left to right, and so the sequence 112, for example, indicates a red move in column 1, followed by a yellow move in column 1, followed by a red move in column 2). You may choose a column-numbering other than 1234567 if you like, as long as you specify in your solution. If you want to return the list in some other format; for example as an array [2, 4, 3, 1, 1, 3] then that is fine too, as long as it is easy to see what the moves are.


You can choose to read the board in in any sensible format including using letters other than R and Y for the players, but you must specify which player goes first. You can assume that the board will always be 6x7, with two players.



This is code golf, so shortest answer wins. Standard loopholes apply.



Examples



| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 1234567 (one possible answer)
| | | | | | | |
|R|Y|R|Y|R|Y|R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | |R| | | | | --> false
| | |Y| | | | |
|R| |Y| | | | |

| | | | | | | |
| | |Y| | | | |
| | |R| | | | |
| | |Y| | | | | --> 323333 (only possible answer)
| | |R| | | | |
| |Y|R| | | | |

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> false (this is the position arising after
| |Y|Y|Y|Y| | | the moves 11223344, but using those moves
| |R|R|R|R| | | the game would have ended once R made a 4)

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> 2134231211 (among other possibilities)
|R|R|Y| | | | |
|Y|R|R|Y| | | |

| | | | | | | |
| | | | | | | |
|Y| | | | | | |
|R|Y| | | | | | --> false (for example, 21342312117 does not
|R|R|Y| | | | | work, because Y has already made a diagonal 4)
|Y|R|R|Y| | |R|

| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | --> 112244553 or similar
|Y|Y| |Y|Y| | |
|R|R|R|R|R| | |






code-golf board-game






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 hours ago







John Gowers

















asked 12 hours ago









John GowersJohn Gowers

19110




19110












  • $begingroup$
    Could you, eg, take the board as arrays of characters representing the rows, or do you have to parse the ascii with the |, etc?
    $endgroup$
    – Jonah
    11 hours ago










  • $begingroup$
    @Jpnah You can read the board in using any sensible format, including as arrays.
    $endgroup$
    – John Gowers
    10 hours ago












  • $begingroup$
    Suggested test case: ......./......./......./......./YYY.YY./RRRRRR. (silly game, but legal).
    $endgroup$
    – Arnauld
    5 hours ago






  • 1




    $begingroup$
    May we assume that the empty board will not be given as input?
    $endgroup$
    – Jonathan Allan
    4 hours ago








  • 1




    $begingroup$
    May we assume no "floating" pieces?
    $endgroup$
    – Jonathan Allan
    4 hours ago


















  • $begingroup$
    Could you, eg, take the board as arrays of characters representing the rows, or do you have to parse the ascii with the |, etc?
    $endgroup$
    – Jonah
    11 hours ago










  • $begingroup$
    @Jpnah You can read the board in using any sensible format, including as arrays.
    $endgroup$
    – John Gowers
    10 hours ago












  • $begingroup$
    Suggested test case: ......./......./......./......./YYY.YY./RRRRRR. (silly game, but legal).
    $endgroup$
    – Arnauld
    5 hours ago






  • 1




    $begingroup$
    May we assume that the empty board will not be given as input?
    $endgroup$
    – Jonathan Allan
    4 hours ago








  • 1




    $begingroup$
    May we assume no "floating" pieces?
    $endgroup$
    – Jonathan Allan
    4 hours ago
















$begingroup$
Could you, eg, take the board as arrays of characters representing the rows, or do you have to parse the ascii with the |, etc?
$endgroup$
– Jonah
11 hours ago




$begingroup$
Could you, eg, take the board as arrays of characters representing the rows, or do you have to parse the ascii with the |, etc?
$endgroup$
– Jonah
11 hours ago












$begingroup$
@Jpnah You can read the board in using any sensible format, including as arrays.
$endgroup$
– John Gowers
10 hours ago






$begingroup$
@Jpnah You can read the board in using any sensible format, including as arrays.
$endgroup$
– John Gowers
10 hours ago














$begingroup$
Suggested test case: ......./......./......./......./YYY.YY./RRRRRR. (silly game, but legal).
$endgroup$
– Arnauld
5 hours ago




$begingroup$
Suggested test case: ......./......./......./......./YYY.YY./RRRRRR. (silly game, but legal).
$endgroup$
– Arnauld
5 hours ago




1




1




$begingroup$
May we assume that the empty board will not be given as input?
$endgroup$
– Jonathan Allan
4 hours ago






$begingroup$
May we assume that the empty board will not be given as input?
$endgroup$
– Jonathan Allan
4 hours ago






1




1




$begingroup$
May we assume no "floating" pieces?
$endgroup$
– Jonathan Allan
4 hours ago




$begingroup$
May we assume no "floating" pieces?
$endgroup$
– Jonathan Allan
4 hours ago










2 Answers
2






active

oldest

votes


















6












$begingroup$

JavaScript (ES6),  202  188 bytes



Takes input as a matrix with $1$ for red, $2$ for yellow and $0$ for empty. Returns a string of 0-indexed moves (or an empty string if there's no solution). Reds start the game.





m=>(p=[...'5555555'],g=(c,s=o='')=>/1|2/.test(m)?[1,13,15,17].some(n=>eval(`/(5|6)(.{${n}}\1){3}/`).test(m))?o:p.map((y,x)=>m[(m[y][x]|=4)^c||p[g(c^3,s+x,p[x]--),x]++,y][x]&=3)&&o:o=s)(5)


Try it online!



How?



The recursive function $g$ attempts to replace $1$'s and $2$'s in the input matrix with $5$'s and $6$'s respectively.



It also makes sure that we don't have four consecutive $5$'s or $6$'s before all $1$'s and $2$'s have disappeared (i.e. if a side wins, it must be the last move).



The row $y$ of the next available slot for each column $x$ is stored in $p[x]$.






share|improve this answer











$endgroup$













  • $begingroup$
    Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
    $endgroup$
    – Jonathan Allan
    4 hours ago



















2












$begingroup$


Jelly, 57 bytes



ŒṪŒ!µ0ịŒṬ¬a³ZU,Ɗ;ŒD$€Ẏṡ€4Ḅo1%15;Ḋ€ṢṚ$Ƒƙ$Ȧȧœị³$2R¤ṁ$ƑµƇṪṪ€


Takes a matrix where 0 is unfilled, 1 played first, and 2 played second. Yields a list of 1-indexed columns, empty if a fake was identified.



Try it online! (too inefficient for more than 7 pieces to run in under a minute)



Note:




  1. Assumes that no "floating" pieces are present (fix this by prepending ZṠṢ€Ƒȧ for +6 bytes)

  2. Assumes that the empty board is a fake






share|improve this answer











$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "200"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178944%2fconnect-4-spot-the-fake%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6












    $begingroup$

    JavaScript (ES6),  202  188 bytes



    Takes input as a matrix with $1$ for red, $2$ for yellow and $0$ for empty. Returns a string of 0-indexed moves (or an empty string if there's no solution). Reds start the game.





    m=>(p=[...'5555555'],g=(c,s=o='')=>/1|2/.test(m)?[1,13,15,17].some(n=>eval(`/(5|6)(.{${n}}\1){3}/`).test(m))?o:p.map((y,x)=>m[(m[y][x]|=4)^c||p[g(c^3,s+x,p[x]--),x]++,y][x]&=3)&&o:o=s)(5)


    Try it online!



    How?



    The recursive function $g$ attempts to replace $1$'s and $2$'s in the input matrix with $5$'s and $6$'s respectively.



    It also makes sure that we don't have four consecutive $5$'s or $6$'s before all $1$'s and $2$'s have disappeared (i.e. if a side wins, it must be the last move).



    The row $y$ of the next available slot for each column $x$ is stored in $p[x]$.






    share|improve this answer











    $endgroup$













    • $begingroup$
      Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
      $endgroup$
      – Jonathan Allan
      4 hours ago
















    6












    $begingroup$

    JavaScript (ES6),  202  188 bytes



    Takes input as a matrix with $1$ for red, $2$ for yellow and $0$ for empty. Returns a string of 0-indexed moves (or an empty string if there's no solution). Reds start the game.





    m=>(p=[...'5555555'],g=(c,s=o='')=>/1|2/.test(m)?[1,13,15,17].some(n=>eval(`/(5|6)(.{${n}}\1){3}/`).test(m))?o:p.map((y,x)=>m[(m[y][x]|=4)^c||p[g(c^3,s+x,p[x]--),x]++,y][x]&=3)&&o:o=s)(5)


    Try it online!



    How?



    The recursive function $g$ attempts to replace $1$'s and $2$'s in the input matrix with $5$'s and $6$'s respectively.



    It also makes sure that we don't have four consecutive $5$'s or $6$'s before all $1$'s and $2$'s have disappeared (i.e. if a side wins, it must be the last move).



    The row $y$ of the next available slot for each column $x$ is stored in $p[x]$.






    share|improve this answer











    $endgroup$













    • $begingroup$
      Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
      $endgroup$
      – Jonathan Allan
      4 hours ago














    6












    6








    6





    $begingroup$

    JavaScript (ES6),  202  188 bytes



    Takes input as a matrix with $1$ for red, $2$ for yellow and $0$ for empty. Returns a string of 0-indexed moves (or an empty string if there's no solution). Reds start the game.





    m=>(p=[...'5555555'],g=(c,s=o='')=>/1|2/.test(m)?[1,13,15,17].some(n=>eval(`/(5|6)(.{${n}}\1){3}/`).test(m))?o:p.map((y,x)=>m[(m[y][x]|=4)^c||p[g(c^3,s+x,p[x]--),x]++,y][x]&=3)&&o:o=s)(5)


    Try it online!



    How?



    The recursive function $g$ attempts to replace $1$'s and $2$'s in the input matrix with $5$'s and $6$'s respectively.



    It also makes sure that we don't have four consecutive $5$'s or $6$'s before all $1$'s and $2$'s have disappeared (i.e. if a side wins, it must be the last move).



    The row $y$ of the next available slot for each column $x$ is stored in $p[x]$.






    share|improve this answer











    $endgroup$



    JavaScript (ES6),  202  188 bytes



    Takes input as a matrix with $1$ for red, $2$ for yellow and $0$ for empty. Returns a string of 0-indexed moves (or an empty string if there's no solution). Reds start the game.





    m=>(p=[...'5555555'],g=(c,s=o='')=>/1|2/.test(m)?[1,13,15,17].some(n=>eval(`/(5|6)(.{${n}}\1){3}/`).test(m))?o:p.map((y,x)=>m[(m[y][x]|=4)^c||p[g(c^3,s+x,p[x]--),x]++,y][x]&=3)&&o:o=s)(5)


    Try it online!



    How?



    The recursive function $g$ attempts to replace $1$'s and $2$'s in the input matrix with $5$'s and $6$'s respectively.



    It also makes sure that we don't have four consecutive $5$'s or $6$'s before all $1$'s and $2$'s have disappeared (i.e. if a side wins, it must be the last move).



    The row $y$ of the next available slot for each column $x$ is stored in $p[x]$.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 5 hours ago

























    answered 7 hours ago









    ArnauldArnauld

    73.6k689309




    73.6k689309












    • $begingroup$
      Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
      $endgroup$
      – Jonathan Allan
      4 hours ago


















    • $begingroup$
      Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
      $endgroup$
      – Jonathan Allan
      4 hours ago
















    $begingroup$
    Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
    $endgroup$
    – Jonathan Allan
    4 hours ago




    $begingroup$
    Note I have asked "May we assume that the empty board will not be given as input?" - if we have to handle this then your code will need a tweak.
    $endgroup$
    – Jonathan Allan
    4 hours ago











    2












    $begingroup$


    Jelly, 57 bytes



    ŒṪŒ!µ0ịŒṬ¬a³ZU,Ɗ;ŒD$€Ẏṡ€4Ḅo1%15;Ḋ€ṢṚ$Ƒƙ$Ȧȧœị³$2R¤ṁ$ƑµƇṪṪ€


    Takes a matrix where 0 is unfilled, 1 played first, and 2 played second. Yields a list of 1-indexed columns, empty if a fake was identified.



    Try it online! (too inefficient for more than 7 pieces to run in under a minute)



    Note:




    1. Assumes that no "floating" pieces are present (fix this by prepending ZṠṢ€Ƒȧ for +6 bytes)

    2. Assumes that the empty board is a fake






    share|improve this answer











    $endgroup$


















      2












      $begingroup$


      Jelly, 57 bytes



      ŒṪŒ!µ0ịŒṬ¬a³ZU,Ɗ;ŒD$€Ẏṡ€4Ḅo1%15;Ḋ€ṢṚ$Ƒƙ$Ȧȧœị³$2R¤ṁ$ƑµƇṪṪ€


      Takes a matrix where 0 is unfilled, 1 played first, and 2 played second. Yields a list of 1-indexed columns, empty if a fake was identified.



      Try it online! (too inefficient for more than 7 pieces to run in under a minute)



      Note:




      1. Assumes that no "floating" pieces are present (fix this by prepending ZṠṢ€Ƒȧ for +6 bytes)

      2. Assumes that the empty board is a fake






      share|improve this answer











      $endgroup$
















        2












        2








        2





        $begingroup$


        Jelly, 57 bytes



        ŒṪŒ!µ0ịŒṬ¬a³ZU,Ɗ;ŒD$€Ẏṡ€4Ḅo1%15;Ḋ€ṢṚ$Ƒƙ$Ȧȧœị³$2R¤ṁ$ƑµƇṪṪ€


        Takes a matrix where 0 is unfilled, 1 played first, and 2 played second. Yields a list of 1-indexed columns, empty if a fake was identified.



        Try it online! (too inefficient for more than 7 pieces to run in under a minute)



        Note:




        1. Assumes that no "floating" pieces are present (fix this by prepending ZṠṢ€Ƒȧ for +6 bytes)

        2. Assumes that the empty board is a fake






        share|improve this answer











        $endgroup$




        Jelly, 57 bytes



        ŒṪŒ!µ0ịŒṬ¬a³ZU,Ɗ;ŒD$€Ẏṡ€4Ḅo1%15;Ḋ€ṢṚ$Ƒƙ$Ȧȧœị³$2R¤ṁ$ƑµƇṪṪ€


        Takes a matrix where 0 is unfilled, 1 played first, and 2 played second. Yields a list of 1-indexed columns, empty if a fake was identified.



        Try it online! (too inefficient for more than 7 pieces to run in under a minute)



        Note:




        1. Assumes that no "floating" pieces are present (fix this by prepending ZṠṢ€Ƒȧ for +6 bytes)

        2. Assumes that the empty board is a fake







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 hours ago

























        answered 4 hours ago









        Jonathan AllanJonathan Allan

        51.3k535166




        51.3k535166






























            draft saved

            draft discarded




















































            If this is an answer to a challenge…




            • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


            • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
              Explanations of your answer make it more interesting to read and are very much encouraged.


            • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



            More generally…




            • …Please make sure to answer the question and provide sufficient detail.


            • …Avoid asking for help, clarification or responding to other answers (use comments instead).





            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178944%2fconnect-4-spot-the-fake%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Le Mesnil-Réaume

            Ida-Boy-Ed-Garten

            web3.py web3.isConnected() returns false always