{"id":198,"date":"2018-08-19T19:28:36","date_gmt":"2018-08-19T11:28:36","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=198"},"modified":"2018-11-27T17:29:21","modified_gmt":"2018-11-27T09:29:21","slug":"292-nim-game","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=198","title":{"rendered":"292. Nim Game"},"content":{"rendered":"<p>You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.<\/p>\n<p>Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><strong>Input:<\/strong> <code>4<\/code> <strong>Output:<\/strong> false <strong>Explanation: <\/strong>If there are 4 stones in the heap, then you will never win the game; \u00a0 No matter 1, 2, or 3 stones you remove, the last stone will always be \u00a0 removed by your friend.<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def canWinNim(self, n):\r\n        &quot;&quot;&quot;\r\n        :type n: int\r\n        :rtype: bool\r\n        &quot;&quot;&quot;\r\n        if n % 4 == 0:\r\n            return False\r\n        else:\r\n            return True\r\n        \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You are playing the following Nim Game with your friend<a href=\"https:\/\/www.ccagml.com\/?p=198\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">292. Nim Game<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/198"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":199,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions\/199"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}